Re: [PATCH] md/raid5: fix write stalls when a write is queued during a drain

From: yu kuai

Date: Fri Nov 20 2026 - 23:01:02 EST


在 2026/11/15 6:46, Miroslav Cimerman 写道:

> With continuous O_DIRECT writes to a RAID-5/6 array that uses
> read-modify-writes, a few 4k writes can take seconds to complete, up
> to the length of the run.
>
> The pre-read permission (STRIPE_PREREAD_ACTIVE) belongs to a stripe.
> A REQ_SYNC write queued while an earlier write on the same stripe is
> being drained finds the bit set and gets no count of its own in
> preread_active_stripes. handle_stripe() clears the bit when the drain
> result is handled, so the queued write gets STRIPE_DELAYED, and the
> stripe goes to delayed_list together with the completion of the
> drained write. raid5_activate_delayed() only moves it on once
> preread_active_stripes is below IO_THRESHOLD, which with other
> REQ_SYNC writes in flight may happen until the load stops.
>
> Check for writes queued on the stripe, under stripe_lock, after
> clearing the bit, and keep the bit and its count if there are any.
> A write queued later tests the bit after the clear and either takes
> the permission itself or finds it kept. Do this for any queued write:
> a queued buffered write would otherwise hold back the completion of
> the drained write the same way.
>
> md-7.4, RAM disks, 4k random writes, io_uring, QD64, 20 s, slowest
> write without -> with this patch, md defaults (1 job) and
> group_thread_cnt=8 (16 jobs):
>
> RAID-6 4+2 (rmw_level=2) 18.0 s -> 2.0 ms 19.3 s -> 5.8 ms
> RAID-6 8+2 13.4 s -> 2.2 ms 13.0 s -> 7.0 ms
> RAID-5 5+1 16.9 s -> 1.8 ms 18.3 s -> 4.9 ms
> RAID-5 9+1 17.4 s -> 2.2 ms 12.0 s -> 5.8 ms
>
> IOPS are unchanged with md defaults and within a few percent with 8
> workers. Buffered writes are not affected.
>
> Fixes: e9c7469bb4f5 ("md: implment REQ_FLUSH/FUA support")
> Cc:stable@xxxxxxxxxxxxxxx
> Signed-off-by: Miroslav Cimerman<mc@xxxxxxxxxxx>
> ---
> drivers/md/raid5.c | 41 +++++++++++++++++++++++++++++++++++++++--
> drivers/md/raid5.h | 4 +++-
> 2 files changed, 42 insertions(+), 3 deletions(-)
Applied

--
Thanks,
Kuai