From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.70 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796106460; b=0KBgKeaf5C3gIoXs9l0/1Ut9to4oSsVaTNwO/upOJTPwvtxGnN7sSjp51Lev3lNTxjvz c8wsfJFf+RsrCZ98WROlxpln2tFLWbh7SXhWmgulKFqEBucAWvsm9dsG7f2IPylTqO4KI 2V6Nn9bOXwaPJ1t8MclSzfVfx9AxHtkXP7peflC1ID/S+wQQpdtw7fxUKfTfg7DO+uGqk Fqjx+VKbPnv88iDsRNjJtozCOqEHluQN6p/2mYmUrJSF8fQzOR6YjzlwY4L+vAo852Qfc kt8ODX/MbWAOiRbb55rEcQb8IIlZqgqQ1xaf9Juiy591a1/3ITzWD1ECrwBGsCzxNhw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796106460; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=gaAdMvsQJ+ltnMOeIcImOwzh1HYapS4i4XHJCw+1vQI=; b=TppASYIVhZenXsfXoo4mwMk4/v6RSNHdJEVbuYFsQzwp/CAH7dlHw1wIooKVj6aZbph7 mUt6Y27qpfXaMp1sfl5JUvdUZjzo1iEk1/zJibkt2e9MlQUwyN5E4p3e+o+g/O+zK9Xjh UX7+YQVJRSzi+uI2pfc7lzGaJwJs9v+aLW42eV5/Sj+DTK53dJ2izX50EEgR3uH2YgUNJ g/4GeNznFVMm8mJuiiAbexORd5hLRahO23TgZsW/iFOcOlZ+1lxsJstBmnVmljFegJFN6 7Qg1N6J7cQ1siaMQGdmB4LqaQamorgSvD0YeJ+cBMsgwRciOWmIhakVKDC7HQ+Wfp0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--penghuang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=b7WIT1nX; arc=none smtp.remote-ip=74.125.82.70 Received: from mail-dl1-f70.google.com (mail-dl1-f70.google.com [74.125.82.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E428606A31A for ; Tue, 1 Dec 2026 06:27:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4E428606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--penghuang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=b7WIT1nX Received: by mail-dl1-f70.google.com with SMTP id a92af1059eb24-1b59dfe467eso2098386c88.1 for ; Mon, 30 Nov 2026 22:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796106459; x=1796711259; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=gaAdMvsQJ+ltnMOeIcImOwzh1HYapS4i4XHJCw+1vQI=; b=b7WIT1nXggmI1FxuE5pEoqrJ/T3CcfrCI04IXj9cFP5t2x2LDwR5QP+ql25glHF7ad Bi8VgmrSaf1k6sqoV3BA2o7zkvfH2AUZ6imb9LpJYuc3EKZINjylTCfdNYaNxhVYqzvm D7IFvHljHySv0NxL4Nq5s65gbYoa2MvbMygEfYpEqHiaIrD50XlwWC+Eyd1K65TrzCxL IEjAfs6abde3OPbnI5e3OfThsvlGUU673BxR+HxtZ6AGQ981PT4Wn/DLQwy/mdSmd8LR eB0ASUIF/SjqElGQ8BZxKf9poVUPO7HghHkXqGtULRDP7tshriARN4sWke2DqGp69R5u j4mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796106459; x=1796711259; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=gaAdMvsQJ+ltnMOeIcImOwzh1HYapS4i4XHJCw+1vQI=; b=0eIag5zdCsff87vQx6J7B/usY19U5zhYHI/Uv19J8ddpKCal5wPk2DlUTChxjGJD4O Etq78OsMyEakhpRi0Gu2UJfOhmmSGuhZuszJd8JxCMHxVw1Np8J8GVqQAwtfI/X4w+eE NkeO8nIA4cqjSH2J9uGdJNoWzeOsL6Ib8a3eIKARP27h1o+3zC59k3CuqV9odWdHgfqz QU4TBH9xq+va79UKHL/jieEmVZFNt0pqGy515591syRw68/wo5NphZa2PgxexyPpjDC+ pFLD6wWI++Xtv7b4rnen+fMTHANbA+u9CkL6dGx9FDNed9Jd2/hhc5WiveTR8F1OHoHD EUSA== X-Forwarded-Encrypted: i=1; AL+hErG3sCIb1AKYtqlFwZfdunvT6AkoNBx5GN7qhwDr1xJH0zI4e3ZKr3uzXDC+qGcp9wRsRBadNFHArs4jmn4=@vger.kernel.org X-Gm-Message-State: APuU4Z965dVpq7d6HU3h0v0OyyHqNpPFe+y80Eh1LZ1o9Z+h+NEFMk3u XdaLobIcp1TO9TcDfKirtAhNLKBHWS4wQsGK2d0mbc4Ip0aHUkO3OqSEi9RdGUeJiAIDQKrh+pp YqDVcFDaAKzTYSB6rAw== X-Received: from dlbpv3.prod.google.com ([2002:a05:7023:903:b0:199:f7f6:16f2]) (user=penghuang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:701b:2810:b0:192:74cf:1db2 with SMTP id a92af1059eb24-1b5568650b5mr30814912c88.11.1796106458991; Mon, 30 Nov 2026 22:27:38 -0800 (PST) Date: Mon, 30 Nov 2026 22:27:27 -0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261201062738.1047159-1-penghuang@google.com> Subject: [RFC PATCH v2 0/6] rwsem: priority boost for holders blocking high-priority waiters From: Peng Huang 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@vger.kernel.org, linux-mm@kvack.org, Peng Huang , Sebastian Andrzej Siewior , Clark Williams , linux-rt-devel@lists.linux.dev Content-Type: text/plain; charset="UTF-8" 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