Re: [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters

From: Kayra Cizmeci

Date: Tue Dec 01 2026 - 15:43:26 EST


Hi Peng,

On Mon, Nov 30, 2026 at 10:27:27PM -0800, Peng Huang wrote:
> Hi,
>
> High-priority threads (e.g. UI/render) can stall for tens to hundreds
> of milliseconds on shared rw_semaphores like mmap_lock or i_rwsem when
> preempted low-priority or SCHED_IDLE readers block a writer. Outside
> PREEMPT_RT, rwsems have no PI, Proxy Execution covers only mutexes,
> and read-owners are anonymous. This hits both servers (/proc/pid/
> cmdline, background MADV_COLD) and phones (nice -10 UI vs. background
> MADV_PAGEOUT on small cores, where we found it).
>
> This RFC raises the fair load weight of contended rwsem holders:
> - Patches 1-2: per-task tracking of up to 4 held rwsems (no atomics);
> btrfs untracks i_rwsem before cross-task io_uring completion.
> - Patch 3: pack top waiter priority into sem->count bits 3..8 (no
> struct rw_semaphore growth).
> - Patches 4-5: apply boost in set_load_weight() (p->prio and PI
> untouched); re-check queued holders on enqueue, preemption, and
> tick; drop on unlock.
> - Patch 6: KUnit suite (16 cases, 20 tests).
>
> Opt-in via CONFIG_RWSEM_SCHED_BOOST; disable at boot with
> rwsem_sched_boost=0.
>
> Questions for this RFC
> ----------------------
> - Is per-task tracking + weight boost acceptable for readers, or
> should this wait for Proxy Execution to cover rwsems?
> - Track readers and writers, or readers only (leaving writers to PE)?
> - Raw pointer slots (+56 B/task, explicit untrack) or a hash table?
> - Reweight via set_load_weight() (stays in cgroup share, moves PELT)
> or a floor on flattened EEVDF weight (crosses cgroups, skips PELT)?
>
> Known limits
> ------------
> - Weight is not PI; only runnable holders benefit (not I/O-blocked).
> Queued holders wait up to one tick; at most 4 rwsems/task tracked.
> - Waiter priority is sampled on queue (so rwsem-to-rwsem propagates
> when a boosted holder queues, but not across mutexes or futexes);
> concurrent readers share the boost.
> - Under FAIR_GROUP_SCHED, boost stays within the holder's cgroup
> share; a boosted SCHED_IDLE holder still yields to non-idle wakeups.
> - Under Proxy Execution, a fair task running for a non-fair donor is
> linked only on its next enqueue or preemption.
>
> Results (mean high-priority waiter latency)
> -------------------------------------------
> - KUnit (UML, nice +19 reader + 4 nice 0 hogs, nice -10 writer):
> 1813 -> 50 ms (-97.2%, median of 3; control 1.77-1.81 s).
> - QEMU x86_64 -smp 4 (TCG), mmap_lock, same setup (10 runs):
> 445.8 -> 8.7 ms within one image (-98.1%, max 14.9 ms, 0/200 > 16 ms;
> BASE 394.4 ms, TCG shifts up to 20% across images).
> - ARM64 phone (older 6.18 backport), mmap_lock, nice -10 vs. 7 hogs:
> 46.95 -> 8.89 ms (-81.1%) unpinned, 229.5 -> 19.4 ms (-91.5%) mid.
>
> Costs and non-results
> ---------------------
> - UML uncontended fastpath (boost=0 -> 1, median of 3): read 16.9 ->
> 20.2, write 17.1 -> 19.8, nested read 16.9 -> 21.8 ns/op; boosted
> holder cycling an unrelated rwsem: 28.5 ns/op.
> - Tick scan: walks up to 16 queued holders per tick under rq->lock
> (round-robin, up to 4 sem->count reads each); not measured alone.
> - Waiter prio rescan: O(1) when waiters share priority; losing a sole
> top waiter rescans remaining waiters under wait_lock (O(waiters)).
> - QEMU (boost=0 -> 1, 10 runs): madvise +2.4%, mprotect +1.4% (+0.4%
> median); equal-priority contention -4.3% mean, -5.6% median
> (196-240 ms on vs. 195-268 ms off).
> - ARM64 (same backport): madvise -2.2%, mprotect +0.2%; boot-time
> hackbench +6.6% and pipe +0.2% (settled -8.7% and -0.7%);
> equal-priority contention -10.6% mid-pinned, -2.8% mean / +12.1%
> median unpinned.

...

> - Browser warm launch from zRAM (same backport, 22 vs. 23 runs):
> +2.4% (p=0.45); holders spent 91-96% of inversion in D state (I/O).
> - Reader count loses 1 bit (22 bits on 32-bit, > PID_MAX_LIMIT).
> Memory: +56 B/task_struct, +16 B/rq.

Well if that is the case I can't see increasing the weight would help
atleast on this browser thing.

Even Proxy Exec. wouldn't help that much. You can't make a sleeping
task run earlier while it is sleeping.


But aside from that if we really want this, I think it would be better
to try to make this compatible with Proxy Exec. rather than
trying to implement a new mechanism, no :-)?


Thanks!

Kayra