Re: [PATCH] percpu_ref: make percpu_ref_switch_lock per percpu_ref
From: Egor Shalashnov
Date: Sun Nov 29 2026 - 09:07:51 EST
On 26/11/2026 00:46, Egor Shalashnov wrote:
> This might be a better approach. I'll compare it with the global-lock
> and per-reference-lock variants and report the results.
I compared the global switch lock, per-reference locks, and hashed
lock arrays with 16, 32, 64 and 128 cacheline-separated locks.
The machine has 128 logical CPUs and runs Fedora kernel
7.3.3-200.fc44.x86_64. Volumes were prefilled before each run.
To increase lock contention, fio 3.40 used io_uring with 128 jobs,
one pinned to each logical CPU. Each job discarded a separate,
non-overlapping range; together they covered the entire volume.
The maximum discard request size was 4095 MiB.
Full-volume fio discard completion times, in seconds:
Volume Global Per-ref Hash16 Hash32 Hash64 Hash128
1 TB 3.393 0.675 0.838 0.759 0.722 0.719
2 TB 5.039 1.315 1.470 1.423 1.399 1.399
4 TB 8.705 1.406 1.555 1.471 1.471 1.485
8 TB 16.955 2.667 2.991 2.835 2.834 2.832
16 TB 34.056 5.263 6.122 5.015 4.997 5.172
32 TB 67.177 9.755 12.680 10.145 9.467 9.646
64 TB 134.081 21.421 24.058 19.539 20.311 19.009
128 TB 263.881 40.170 48.588 38.663 40.135 39.236
256 TB 543.297 80.053 91.324 78.679 83.590 77.425
I also tested full-volume discard using a single blkdiscard process.
Volume Global Per-ref Hash16 Hash32 Hash64 Hash128
1 TB 2.722 1.018 1.268 1.167 1.117 1.017
2 TB 7.085 1.871 2.573 2.373 2.121 1.821
4 TB 14.354 3.025 4.932 4.179 3.878 3.427
8 TB 28.391 6.186 9.544 8.342 7.441 6.687
16 TB 56.520 11.655 19.124 16.265 14.561 13.311
32 TB 92.209 20.629 27.544 22.931 21.123 26.303
64 TB 162.383 39.483 54.974 48.209 43.342 40.180
128 TB 321.230 90.283 115.726 102.877 87.113 94.157
256 TB 556.408 181.729 231.681 210.062 177.198 165.985
The 64-lock implementation gives results close to the per-reference
implementation. I have prepared that version for the next revision.