mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v8] dm zoned: keep polling for idle reclaim after a reclaim pass
@ 2026-11-28 18:25 Kyrylo Biryuk
  0 siblings, 0 replies; only message in thread
From: Kyrylo Biryuk @ 2026-11-28 18:25 UTC (permalink / raw)
  To: dm-devel
  Cc: mpatocka, snitzer, agk, bmarzins, dlemoal, hare, hare, linux-kernel

dmz_reclaim_work() re-arms its DMZ_IDLE_PERIOD poll only when
dmz_should_reclaim() returns false at the start of a pass, or when a
pass fails with -ENOSPC or -EBUSY. After a pass it calls
dmz_schedule_reclaim(), which queues the work only if reclaim is needed
right now. When a pass ends while the target is still busy and has
enough free zones, nothing is queued at all. Once the target goes idle,
nothing re-evaluates dmz_should_reclaim() until another zone allocation,
a "reclaim" message or a resume schedules the work, so the random or
cache zones that filled up under load remain occupied.

Seen on md RAID5 members on 27 TB host-managed drives: after heavy
writes the random zones remained occupied for hours on idle targets;
the workaround was a timer sending "dmsetup message <dev> 0 reclaim".

When reclaim is not needed right now, make dmz_schedule_reclaim() queue
the idle poll, so the work stays queued after every pass. It uses
queue_delayed_work(), which leaves already pending work alone, so the
other callers (zone allocation and the "reclaim" message) neither
postpone a pending poll nor delay a pending immediate reclaim.

This change requires commit 9bb1d14877f4 ("dm zoned: back off when
reclaim cannot make progress"): without it, keeping the poll armed
would restart the idle -EBUSY loop described there in every idle
period.

Tested on 7.4-rc3, on a scsi_debug host-managed drive: after a reclaim
pass that ended while the target was busy with 33% of its random zones
free, the unpatched kernel ran no reclaim pass in the following 600
seconds; with this patch, idle reclaim resumed and all random zones
were free about 10 seconds after writes stopped.
With three such drives as md RAID5 members, the first two write/idle
cycles reached all random zones free 23 and 13 seconds after the start
of each write, without a "reclaim" message; without this patch the
first cycle did not drain. The planned ten-cycle run stopped after
cycle 2 because trim did not restore sequential capacity.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Kyrylo Biryuk <illofspeed@gmail.com>
---
For 7.5. This was patch 3 of v4/v5 of "dm zoned: fix idle reclaim busy
loops"; it was split out after Mikulas asked to separate bugfixes from
enhancements. The two fixes went in as v7 and are in 7.4-rc3: commit
9bb1d14877f4 ("dm zoned: back off when reclaim cannot make progress"),
which this patch requires, and commit dab527d83462 ("dm zoned: do not
reclaim a random zone into another random zone").

v8: split out of the series, rebased on v7.4-rc3 and retested there
(the test paragraphs above have the new numbers); no code change.

Damien's Reviewed-by is from v4 3/3 (2026-10-13); the code of this
patch is unchanged since then. The back-off fix underneath it changed since
v4: it now also backs off when there is no zone to reclaim (-EBUSY), so
with both applied an idle target with nothing to reclaim runs one
no-op pass per DMZ_IDLE_PERIOD. The Fixes tag of the earlier versions is
dropped: this is an enhancement for 7.5, not a stable fix.

Hannes, on 2026-10-21 you replied to v3 3/3 and suggested simply
rescheduling with no delay at the end of dmz_reclaim_work(), because
its start evaluates dmz_should_reclaim() and re-arms the poll anyway.
That code was already gone by then: v4 (2026-10-13) had moved the idle
poll into dmz_schedule_reclaim(), as Damien asked on the same patch,
and he reviewed that form. It avoids one extra run of
the work after a pass that leaves reclaim not needed; if you prefer the
unconditional reschedule, please say so and I will change it.

Also tested on three 27 TB host-managed SATA drives (single-device
dm-zoned targets, 998 random zones of 256 MiB each, as md RAID5
members under dm-crypt and XFS), with this patch built out of tree for
7.2.10 on top of the two fixes and compared with the fixes alone; one
run each, kprobes attached throughout, the drives behind a SATA port
multiplier on a Marvell 88SE9235, with two other drives on the same
controller being zero-filled at about 218 MB/s:
- after a reclaim pass that ended while the target was busy with 31%
  of the random zones free, then 600 s without test I/O: with the
  fixes alone no pass ran and the zones stayed in use; with this patch
  all random zones were free again within about 260 s;
- ten cycles of new data written into 32 fresh chunks followed by idle
  (on the emulated drives this test stopped after two cycles because
  trim did not restore sequential capacity): every cycle drained
  without intervention, in 2-4 minutes each; with the fixes alone (and
  with the stock module) random zones were still in use after the
  first cycle's 600 s;
- idle for 300 s with all random zones free: 29-30 passes per worker;
- 300 s of single-threaded random 4 KiB O_DIRECT overwrites with
  dm-zoned's free random zone percentage at or below 30 (at most 309
  of 998 free) in 66-73% of the samples, but at most 299 free in only
  2-10% of them (fixes alone: 22-31%): 2,925 writes, 99th percentile
  0.38 s (fixes alone: 2,395 writes, 0.48 s);
- a target suspend with the array running, removal of one member's
  dm-zoned target after the array was stopped, and a "reclaim"
  message, each during a full-zone copy (one occurrence each): suspend
  and removal waited for the copy to end (10-17 s), the copy under the
  message completed without error, no hang or kernel warning;
- sha256 of all written data, read back at the end of the run: no
  mismatch; md parity checks of every stripe of the suspend/removal
  test and of a random sample (about 4%) of the other written stripes:
  no mismatch.

Not tested (this list covers the two fixes and this patch together):
the back-off under write load (every reclaim pass of the overwrite
test copied a zone); single-device -ENOSPC back-off
without cache zones; recovery after freeing a sequential zone;
the effect of the cache-to-random fallback (6 copies ran while the
two-device target was filled, but its own test could not establish its
starting state).

Reboot and power-off, on 7.4-rc3 with this patch loaded (three
scsi_debug host-managed drives as dm-zoned targets under md RAID5 and
XFS): one reboot after the targets had been idle with all random zones
free for at least 25 s, one reboot and one power-off right after a
write that left 1-2 of 6 random zones free on each target. All three
completed (1.6 s, 1.8 s and 4.9 s from the command to "Restarting
system" or "Power down"): the array was stopped, systemd-shutdown
detached all DM devices, and the console showed no warning or hang.
Whether a zone copy was in flight at that moment was not established.

The Assisted-by tag is gone, following commit 1e035297ffda ("docs:
remove Assisted-by references").
I used LLM coding assistants for root-cause analysis, drafts of the code
and changelog, the test harnesses and reviews. I reviewed the code and
changed it where needed, and I am responsible for this patch.

 drivers/md/dm-zoned-reclaim.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/md/dm-zoned-reclaim.c b/drivers/md/dm-zoned-reclaim.c
index 152cb878811..3a4e3a6e4ff 100644
--- a/drivers/md/dm-zoned-reclaim.c
+++ b/drivers/md/dm-zoned-reclaim.c
@@ -643,7 +643,8 @@ void dmz_reclaim_bio_acc(struct dmz_reclaim *zrc)
 }
 
 /*
- * Start reclaim if necessary.
+ * Start reclaim if necessary. Otherwise make sure that an idle poll stays
+ * queued, without delaying work that is already pending.
  */
 void dmz_schedule_reclaim(struct dmz_reclaim *zrc)
 {
@@ -651,4 +652,6 @@ void dmz_schedule_reclaim(struct dmz_reclaim *zrc)
 
 	if (dmz_should_reclaim(zrc, p_unmap))
 		mod_delayed_work(zrc->wq, &zrc->work, 0);
+	else
+		queue_delayed_work(zrc->wq, &zrc->work, DMZ_IDLE_PERIOD);
 }

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-28 18:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28 18:25 [PATCH v8] dm zoned: keep polling for idle reclaim after a reclaim pass Kyrylo Biryuk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®