Re: [PATCH v2] locking/rwsem: don't let readers retain the lock past a queued writer
From: Lorenzo Stoakes (ARM)
Date: Thu Dec 03 2026 - 14:23:01 EST
On Tue, Dec 01, 2026 at 11:27:59AM -0500, Waiman Long wrote:
> On 11/26/26 5:14 PM, Lorenzo Stoakes (ARM) wrote:
> > This still permits reader stealing if a writer last held the lock, as
> > failing to do so can starve readers in favour of writers. This maintains
> > fairness.
> Yes, I like this idea of maintaining some fairness.
Thanks :)
Yeah the numbers showed that this was a good idea.
> > Writer latency (microbenchmark, bare metal, p99)
> > ------------------------------------------------
> > readers base patched
> > 2 3813 us 17 us
> > 4 3868 us 29 us
> > 16 5369 us 4008 us (within expected stddev)
> > 62 4612 us 3835 us (ditto)
> > 2, one CCD 3865 us 17 us
> > 7, one CCD 3951 us 35 us
> >
> > Writer throughput +35-54% at 2 and 4 readers and in both one-CCD cases.
> > Reader steals in this test: 4.8M -> 8.
> Just to confirm if the reader steals had dropped from 4.8M to just 8. That
> is really low. What is the test duration?
Yeah this is accurate :)
Each test run is 7 runs of 5 seconds each, with:
* one writer calling mprotect() on a single page ever 1ms
* vs. [1,2,4,16,62,2^,7^] readers looping madvise(MADV_POPULATE_READ) over 64 pages.
^ = pinned to one CCD
So basically contrived to be the case this change is addressing.
So either the writer holds the lock or is at the head of the queue of a
reader-owned rwsem, thus won't steal.
Stats were:
base patched
rlock_steal 4809477 8
sleep_writer 4408523 22979
wake_writer 4823875 46499
wlock 17385 22926
rlock 229735 249025
So this is basically 'does this change do what we need' and yes :)
And as per the bench results there's no impact elsewhere.
> Other than a question about the drop in reader stealing count, the patch
> looks reasonable to me and the benchmark results look good too.
>
> Reviewed-by: Waiman Long <longman@xxxxxxxxxx>
Great thanks! :)
--
Cheers, Lorenzo