From: Peng Huang <penghuang@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun@kernel.org>, Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Cc: Waiman Long <longman@redhat.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
John Stultz <jstultz@google.com>,
Suren Baghdasaryan <surenb@google.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Peng Huang <penghuang@google.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
linux-rt-devel@lists.linux.dev
Subject: [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters
Date: Mon, 30 Nov 2026 22:27:27 -0800 [thread overview]
Message-ID: <20261201062738.1047159-1-penghuang@google.com> (raw)
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
next reply other threads:[~2026-12-01 6:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 6:27 Peng Huang [this message]
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 8:40 ` Christoph Hellwig
2026-12-01 14:43 ` Steven Rostedt
2026-12-01 17:41 ` Peng Huang
2026-12-02 6:20 ` Christoph Hellwig
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-02 6:28 ` sashiko-bot
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
2026-12-02 6:28 ` sashiko-bot
2026-12-01 20:43 ` [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters Kayra Cizmeci
2026-12-01 21:10 ` Peng Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201062738.1047159-1-penghuang@google.com \
--to=penghuang@google.com \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=bsegall@google.com \
--cc=clrkwllms@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=jstultz@google.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=surenb@google.com \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.