* [PATCH v8] dm zoned: keep polling for idle reclaim after a reclaim pass
@ 2026-11-28 18:25 Kyrylo Biryuk
2026-12-02 20:25 ` Kyrylo Biryuk
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread* Re: [PATCH v8] dm zoned: keep polling for idle reclaim after a reclaim pass
2026-11-28 18:25 [PATCH v8] dm zoned: keep polling for idle reclaim after a reclaim pass Kyrylo Biryuk
@ 2026-12-02 20:25 ` Kyrylo Biryuk
0 siblings, 0 replies; 2+ messages in thread
From: Kyrylo Biryuk @ 2026-12-02 20:25 UTC (permalink / raw)
To: dm-devel
Cc: mpatocka, snitzer, agk, bmarzins, dlemoal, hare, hare, linux-kernel
Please hold the "[PATCH v8] dm zoned: keep polling for idle reclaim after a
reclaim pass" patch. I found a write amplification problem that it allows,
and I am working on a new version.
With the idle poll always armed, the idle rule of dmz_should_reclaim()
(mainline: the target has been idle for DMZ_IDLE_PERIOD, 10 seconds, and
has random zones) keeps starting reclaim passes. By my reading of the
code, a chunk with a buffer zone is then merged about 10 seconds after
the last I/O to the target, which copies the chunk's valid data (up to
256 MiB); I did not trace individual merges. A workload that writes
small amounts periodically therefore keeps causing chunk-sized rewrites
while it is otherwise idle. My v8 tests wrote bursts and then checked
that the zones drained while idle; they did not include periodic small
writes.
I saw it with a Synology DSM guest (a NAS operating system) running a
5-disk RAID6 that had three single-device dm-zoned targets as members,
each on an emulated host-managed disk (zloop, 62 random zones of
256 MiB). The module was built from the v7.0 dm-zoned sources and run on
a 7.0.14-30-pve kernel. It carried four local patches (the two v7 fixes, a
version of the idle polling patch from the earlier series that re-arms
the poll at the end of every pass, and a check that idle reclaim needs a
random or cache zone holding data) and the v8 hunk. I did not run v8
alone on this workload.
During an 8-minute window (493 s) with the guest idle and all random
zones already free:
- each target received about 0.23 MiB from the guest;
- each backing disk was written 6,131 to 6,643 MiB (about 12.4 to 13.5
MiB/s), or about 26,000 to 28,000 times the data written to the
target. That write volume equals about 24 to 26 full-zone copies in 8
minutes.
The stock module of the same kernel on the same disks, idle for 472 s:
- each target received 2.6 to 3.2 MiB;
- each backing disk was written 2.8 to 3.3 MiB (write amplification
1.02 to 1.04).
During three guest reboots the write amplification on the backing disks,
from the reboot command until the web UI was up, was 22.7 to 47.1 times
with the polling module (22.7 to 31.1 times for the second and third
reboots alone; the first started 91 s after a write burst with 7 to 8
random zones still in use). The time from the reboot command to the web
UI was 342 to 414 s with the polling module. One reboot with the stock
module gave 1.01 to 1.02 and 301 s. The stock module did not drain the
random zones at idle (43 of 62 stayed free); the polling module did (62
of 62), at that price. In a later run, the first boot after the stock
module was loaded, with 38 of 62 random zones free, gave 10.2 to 17.1.
I have tested one candidate change since then: at idle, merge a chunk
only if it has been quiet for 600 s and fewer than 60 % of the random
zones are free. In a steady idle hour on the same setup it did no merges
(write amplification 1.00). But the guest's own boot writes lowered the
free random zones from 38 of 62 (61 %) to 35 to 37 of 62 (56 to 60 %),
below that threshold, and the following reboot windows still merged
chunks (7 of 9 target windows, the first one included; write
amplification up to about 7 on a target, 256 MiB per merge). This
candidate therefore does not solve the reboot case. I am not proposing a
fix yet. I will follow up when a version has been tested against guest
reboots as well as periodic small writes.
I used LLM coding assistants for the test harnesses, the analysis of the
results and the draft of this message. I reviewed the results and I am
responsible for this message.
Thanks,
Kyrylo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 20:25 UTC | newest]
Thread overview: 2+ messages (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
2026-12-02 20:25 ` 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®