mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] sched/numa: Don't act on stale NUMA placement state
@ 2026-11-24  6:59 Andrea Righi
  2026-11-24  6:59 ` [PATCH 1/3] sched/numa: Ignore stale task " Andrea Righi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrea Righi @ 2026-11-24  6:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
	Tejun Heo, Vladimir Vdovin, Gregory Price, David Dai,
	Balbir Singh, Lee Trager, linux-mm, sched-ext, linux-kernel

While working on NUMA balancing support for sched_ext [1][2], the review
pointed out that some of the NUMA balancing state a BPF scheduler would
read, p->numa_preferred_nid in particular, can be stale: NUMA balancing
stops updating it when it is disabled at runtime, but never resets it,
and parts of the fair class keep acting on it. The agreement was to
clean this up first, and then build the sched_ext support on top [3][4].

This series is that cleanup. It has no dependency on sched_ext and fixes
the fair class on its own; the sched_ext series will follow on top of
it.

NUMA balancing maintains the task placement state (the NUMA fault
statistics, the preferred node and what is derived from them) from the
hinting faults. With numa_balancing=1 and 3 (NUMA_BALANCING_NORMAL set)
all the scanned memory feeds it, while with numa_balancing=2 (memory
tiering only) top-tier memory is not scanned and only the folios
promoted from the slower tiers do.

Switching numa_balancing at runtime doesn't reset any of it, and:

 - with NUMA balancing disabled the state is not updated anymore, but
   find_idlest_group() and the fbq classification in the load balancer
   keep using the preferred nodes, as they don't check whether NUMA
   balancing is enabled;

 - PTEs armed for hinting faults before switching from 1 or 3 to 0 or 2
   can fault much later, and still update the placement state, migrate
   the task and migrate the folio between top-tier nodes based on that
   state, as if NUMA_BALANCING_NORMAL was still set.

Patch 1 gates find_idlest_group() and the fbq classification on the
sched_numa_balancing static key, like the other users of the placement
state, and makes task_numa_fault() drop the leftover top-tier faults
when NUMA_BALANCING_NORMAL is cleared, keeping the faults of the
promoted folios.

Patch 2 does the same for the memory side: should_numa_migrate_memory()
keeps promoting folios from the slower tiers, which only depends on the
memory tiering mode, but no longer migrates the other folios without
NUMA_BALANCING_NORMAL. It also stops a task_numa_work() queued before
NUMA balancing was disabled from arming new hinting faults.

Patch 3 fixes the choice of the swap partner when NUMA balancing
migrates a fair task: the task running on the destination CPU can be RT,
deadline or sched_ext, which fair should not move around and whose load
average isn't updated. Only pick a fair task as the partner. Vladimir
hit this with sched_ext in partial mode [5], and Peter suggested
checking for the fair class rather than special-casing sched_ext [6].

To see the effect of leftover hinting faults, I ran a single-threaded
task on node 1 with 1GB of memory first touched on node 0, on a 2-node
VM, and switched numa_balancing from 1 to 0 or 2 while its memory was
still migrating. Pages migrated in the 8 seconds after the switch:

                    1 -> 0     1 -> 2
  tip/sched/core    184158     114703
  this series            0          0

I also tested on a 3-node vng instance where node 2 is a slower,
CPU-less memory tier: its memory is marked as soft reserved at boot and
then onlined through dax/kmem, which puts it in a lower tier:

  vng --cpus 4 -m 6G \
      --numa 2G,cpus=0-1 --numa 2G,cpus=2-3 --numa 2G \
      --append 'memmap=2G%0x140000000-1+0xefffffff'
  # daxctl reconfigure-device --mode=system-ram all

In both tests the workload runs on node 1:

 - numa_balancing=2 only, memory on node 2, promotion rate limited so
   that the promotions span several scan passes: the promoted folios
   still feed the placement state as before (preferred node 1, same
   number of recorded faults as tip/sched/core);

 - numa_balancing 3 -> 2 with half the memory on node 0 and half on
   node 2, switching while the node 0 memory is still migrating: in the
   10 seconds after the switch, tip/sched/core keeps migrating ~40000
   pages from node 0, with this series node 0 keeps the same page count,
   and in both cases the node 2 memory keeps being promoted.

With numa_balancing=1 the memory migrates as before.

[1] v1: https://lore.kernel.org/r/20261004072901.3579967-1-arighi@nvidia.com
[2] v2: https://lore.kernel.org/r/20261027041536.3317971-1-arighi@nvidia.com
[3] https://lore.kernel.org/r/20261027105056.GE2668564@noisy.programming.kicks-ass.net
[4] https://lore.kernel.org/r/20261027115410.GK2668564@noisy.programming.kicks-ass.net
[5] https://lore.kernel.org/r/20261002124559.10367-1-deliran@verdict.gg
[6] https://lore.kernel.org/r/20261027104317.GC2668564@noisy.programming.kicks-ass.net

Git tree:
git://git.kernel.org/pub/scm/linux/kernel/git/arighi/linux.git sched-numa-fix-stale-state

Andrea Righi (3):
  sched/numa: Ignore stale task placement state
  sched/numa: Don't migrate memory on stale placement state
  sched/numa: Only pick a fair task as a swap partner

 kernel/sched/fair.c | 57 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 50 insertions(+), 7 deletions(-)

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

end of thread, other threads:[~2026-11-24  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24  6:59 [PATCH 0/3] sched/numa: Don't act on stale NUMA placement state Andrea Righi
2026-11-24  6:59 ` [PATCH 1/3] sched/numa: Ignore stale task " Andrea Righi
2026-11-24  6:59 ` [PATCH 2/3] sched/numa: Don't migrate memory on stale " Andrea Righi
2026-11-24  6:59 ` [PATCH 3/3] sched/numa: Only pick a fair task as a swap partner Andrea Righi

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

all inboxes | Powered by JetHome®