Re: [PATCH] md: wait for a single grace period when stopping an array

From: yu kuai

Date: Sat Nov 28 2026 - 22:48:49 EST


在 2026/11/22 7:59, Qiliang Yuan 写道:

> When an array is stopped, export_array() takes the members off
> mddev->disks one by one with md_kick_rdev_from_array(), which unlinks a
> member with list_del_rcu() and calls synchronize_rcu() before handing it
> to mddev_unlock() for kobject_del().
>
> Each member thus waits for a full grace period of its own, so stopping
> an array takes one grace period per member, about 6 ms each in a guest,
> with reconfig_mutex held.
>
> Release the serialization resources of all members first, while
> mddev_destroy_serial_pool() still sees the members that need the pool,
> then unlink all members at once with list_splice_init_rcu() and a single
> synchronize_rcu(). Clear rdev->mddev and the sysfs references only after
> the grace period, so a reader walking mddev->disks never finds a member
> that has already been detached.
>
> Stopping an array made of null_blk devices in a guest with 32 vCPUs,
> base and patched kernels alternating over 2 rounds of 3 runs, median of
> the 6 runs and range in parentheses:
>
> level, disks before (ms) after (ms) change
> raid0, 16 132.4 (126.3-147.5) 37.7 (34.5-41.4) -72%
> raid1, 8 88.5 (86.3-103.1) 43.7 (40.7-45.4) -51%
> raid5, 8 98.8 (97.6-107.3) 57.7 (55.0-59.1) -42%
> raid10, 8 87.4 (85.0-89.8) 41.7 (37.8-43.9) -52%
>
> Signed-off-by: Qiliang Yuan<qiliang.yuan@xxxxxxxxx>
> ---
> drivers/md/md.c | 39 +++++++++++++++++++++++++++++----------
> 1 file changed, 29 insertions(+), 10 deletions(-)
Applied

--
Thanks,
Kuai