[PATCH RFC 0/1] sched: replace the nr_pinned offset access with a per-CPU counter
From: Qiurong Fang
Date: Tue Aug 25 2026 - 00:13:52 EST
From: fangqiurong <fangqiurong@xxxxxxxxxx>
378b7708194f inlined migrate_{en,dis}able() into include/linux/sched.h
and reached rq->nr_pinned from there through a generated offset
constant, since struct rq is incomplete in that header. The offset
route was picked as the least ugly of the four options weighed in the
2025-07 bpf-next discussion that led to the commit (Alexei
Starovoitov: reorder the field, RUNTIME_CONST, asm-offsets, a compiler
extension).
This RFC takes that unconsidered path: nr_pinned becomes a plain
per-CPU variable, written with __this_cpu_inc()/__this_cpu_dec() (both
call sites are already preempt-disabled; same plain RMW codegen as the
open-coded access) and read by per_cpu_ptr() + READ_ONCE() in the
single hotplug reader. The offset generator, its Kbuild rule and the
global generated-header include from sched.h go away.
It is a cleanup, not a bug fix, hence no Fixes: or Cc: stable.
Link: https://lore.kernel.org/bpf/CAADnVQ+5sEDKHdsJY5ZsfGDO_1SEhhQWHrt2SMBG5SYyQ+jt7w@xxxxxxxxxxxxxx/
Link: https://lore.kernel.org/lkml/175878730376.709179.17451225747099918958.tip-bot2@tip-bot2/
fangqiurong (1):
sched: Replace nr_pinned offset hack with a dedicated per-CPU counter
Kbuild | 13 +------------
include/linux/sched.h | 30 +++--------------------------
kernel/sched/core.c | 3 ++-
kernel/sched/rq-offsets.c | 12 ------------
kernel/sched/sched.h | 1 -
5 files changed, 6 insertions(+), 53 deletions(-)
delete mode 100644 kernel/sched/rq-offsets.c
--
2.43.0