Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters
@ 2026-12-01  6:27 Peng Huang
  2026-12-01  6:27 ` [RFC PATCH v2 1/6] locking/rwsem: Track held rwsems per task Peng Huang
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Peng Huang @ 2026-12-01  6:27 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng, Juri Lelli,
	Vincent Guittot
  Cc: Waiman Long, Dietmar Eggemann, Steven Rostedt, Ben Segall,
	Mel Gorman, Valentin Schneider, K Prateek Nayak, John Stultz,
	Suren Baghdasaryan, linux-kernel, linux-mm, Peng Huang,
	Sebastian Andrzej Siewior, Clark Williams, linux-rt-devel

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.

Changes in v2
-------------
- Boost fair load weight only (leave p->prio, static_prio, PI alone).
- Pack waiter prio into sem->count (32 B rwsem); lockless drop check.
- Move all hooks into fair.c; drop idle-balance pull; handle Proxy
  Execution donors and delayed dequeue.
- Split into 6 patches, opt-in Kconfig, fixed 4 slots, 16 KUnit cases.

Based on tip/sched/core (74ce3843347b).
v1: https://lore.kernel.org/all/20261119224954.196990-1-penghuang@google.com/

Tool disclosure (Documentation/process/generated-content.rst): an
LLM-based coding assistant (Gemini, via Google-internal tooling) helped
draft parts of the code, changelogs, KUnit tests, and this letter, and
ran review, refactoring, and test passes.  I reviewed and edited all of
it and take full responsibility for the series.

Peng Huang (6):
  locking/rwsem: Track held rwsems per task
  btrfs: untrack i_rwsem before io_uring encoded read completion
  locking/rwsem: Publish the top waiter priority
  sched: Apply rwsem holder boost to the fair load weight
  sched/fair: Boost rwsem holders with contended high-priority waiters
  locking/rwsem: Add KUnit tests for scheduler priority boost

 .../admin-guide/kernel-parameters.txt         |    5 +
 fs/btrfs/ioctl.c                              |    7 +
 include/linux/rwsem.h                         |   46 +
 include/linux/sched.h                         |   34 +
 init/init_task.c                              |    6 +
 kernel/Kconfig.locks                          |   15 +
 kernel/locking/Makefile                       |    1 +
 kernel/locking/rwsem.c                        |  387 ++++-
 kernel/locking/rwsem_sched_boost_test.c       | 1468 +++++++++++++++++
 kernel/sched/core.c                           |   92 +-
 kernel/sched/fair.c                           |  326 ++++
 kernel/sched/sched.h                          |   59 +
 lib/Kconfig.debug                             |   17 +
 13 files changed, 2442 insertions(+), 21 deletions(-)
 create mode 100644 kernel/locking/rwsem_sched_boost_test.c


base-commit: 74ce3843347b0fe192e9bf29f46e1a266515defa
-- 
2.56.1.839.g22a8290db9-goog



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-01  6:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01  6:27 [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 1/6] locking/rwsem: Track held rwsems per task Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 2/6] btrfs: untrack i_rwsem before io_uring encoded read completion Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 3/6] locking/rwsem: Publish the top waiter priority Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 4/6] sched: Apply rwsem holder boost to the fair load weight Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 5/6] sched/fair: Boost rwsem holders with contended high-priority waiters Peng Huang
2026-12-01  6:27 ` [RFC PATCH v2 6/6] locking/rwsem: Add KUnit tests for scheduler priority boost Peng Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox