Re: [PATCH] percpu_ref: make percpu_ref_switch_lock per percpu_ref
From: Egor Shalashnov
Date: Wed Nov 25 2026 - 16:46:39 EST
On 25/11/2026 22:35, Andrew Morton wrote:
> Well, an unpublished module isn't very useful for us.
>
> And an intense microbenchmark isn't as interesting as a real-world
> workload. So can you please provide more details about what "our
> workload" is doing and some measurements on how much this patch
> improves that workload?
The workload is a full-volume discard on an out-of-tree storage
block device backed by NVMe drives. The test machine has 128 logical CPUs.
The device maintains a percpu_ref for each independently managed
logical region of a thin volume. Normal I/O holds a reference while accessing
that region. To process a discard, we kill the affected references and
wait for outstanding I/O to drain before removing the mappings.
After the metadata updates complete, we reinitialize the references
so the regions can accept I/O again.
A large discard repeats this lifecycle for many regions, with
different regions processed concurrently on multiple CPUs. Although
the regions are independent, their kill and reinit operations
contend on the global percpu_ref_switch_lock.
We measured the elapsed time of blkdiscard over the entire volume,
refilling the volume before each run.
Volume Global lock Per-reference lock Speedup
1 TB 3.424 s 1.218 s 2.81x
8 TB 27.943 s 6.133 s 4.56x
16 TB 56.021 s 8.591 s 6.52x
> Alternatively, this looks like somewhere where a hashed spinlock will
> work well. A static array of 32(?) cacheline_aligned spinlocks, hash
> the percpu_ref* onto one of those. That'll get 90% of the benefit
> without growing percpu_ref.
This might be a better approach. I'll compare it with the global-lock
and per-reference-lock variants and report the results.