Re: [PATCH] md/raid5: grow stripe hash table with the size of stripe cache

From: yu kuai

Date: Sat Nov 28 2026 - 20:25:43 EST


在 2026/11/16 21:39, Miroslav Cimerman 写道:

> The stripe hash table has a fixed size of one page, 512 buckets with
> 4 KiB pages. With stripe_cache_size at its current maximum (32768), a
> bucket contains 64 stripes on average. Every stripe lookup walks one
> chain with interrupts off and the hash lock held, and with random I/O
> most lookups miss and walk the whole chain. This costs CPU time on
> every request and makes the hash locks more contended.
>
> Grow the table when stripe_cache_size is written, to about
> STRIPES_PER_HASH_BUCKET (two) stripes per bucket, rounded up to a
> power of two. The new table is allocated before any hash lock is taken,
> and the stripes are moved to it with all hash locks held. The table
> size stays a power of two and a multiple of NR_STRIPE_HASH_LOCKS, so
> every stripe keeps its hash lock. If the allocation fails, the old
> table stays. Moving about 24k stripes (only stripes that have been
> used are in the table) took about 2 ms with interrupts off on the
> Xeon machine below. This happens only when stripe_cache_size is set.
>
> The table starts at one page as before. It needs at most 8 bytes per
> stripe: 128 KiB at stripe_cache_size=32768, where the stripe pages
> alone take 768 MiB on RAID-6 4+2. The table is not shrunk when
> stripe_cache_size is lowered.
>
> 2x Xeon E5-2699 v3 (one NUMA node used), RAM disks, chunk 512K,
> stripe_cache_size=32768, group_thread_cnt=8, io_uring, without -> with
> this patch:
>
> RAID-6 4+2 4k random write, 16 jobs QD64 320k -> 355k IOPS (+11%)
> RAID-6 6+2 4k random write, 16 jobs QD64 345k -> 381k IOPS (+10%)
> RAID-5 5+1 4k random write, 16 jobs QD64 437k -> 514k IOPS (+18%)
> RAID-6 4+2 1M seq write, 4 jobs QD16 4410 -> 4971 MiB/s (+13%)
> RAID-6 4+2 4k random read, degraded 543k -> 705k IOPS (+30%)
>
> HPE DL345 Gen11, AMD EPYC 9455, 6x PCIe 5.0 NVMe (KIOXIA CM7-V 3.2 TB),
> the same md settings and chunk size:
>
> RAID-6 4+2 4k random write, 16 jobs QD64 501k -> 536k IOPS (+7%)
> RAID-6 4+2 2M seq write, 1 job QD64 10342 -> 13523 MiB/s (+31%)
>
> The CPU time per I/O drops by 21-34% on the Xeon, and by 12% (random)
> and 49% (sequential) on the EPYC. In the 4k random write tests,
> find_get_stripe() drops from 9.2% to 0.6% of all cycles on the Xeon,
> and from 3.4% to 0.2% on the EPYC. With md's default stripe_cache_size
> nothing changes.
>
> Signed-off-by: Miroslav Cimerman<mc@xxxxxxxxxxx>
> ---
> drivers/md/raid5.c | 60 +++++++++++++++++++++++++++++++++++++++++++---
> drivers/md/raid5.h | 14 ++++++++---
> 2 files changed, 68 insertions(+), 6 deletions(-)
Applied

--
Thanks,
Kuai