sched/numa: Don't act on stale NUMA placement state
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 1 replyIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | sched/numa: Ignore stale task placement statekernel/ | +27 | 0 replies | |
| 2/3 | sched/numa: Don't migrate memory on stale placement statekernel/ | +16 | 0 replies | |
| 3/3 | sched/numa: Only pick a fair task as a swap partnerkernel/ | +7 | 1 reply |
Reviews trailers per patch
1 of 3 patches has a Reviewed-by or Acked-by.
| Patch | Balbir Singh |
|---|---|
| 1/3 | |
| 2/3 | |
| 3/3 | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/3] sched/numa: Don't act on stale NUMA placement state
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 allIn 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/[email protected]
[2] v2: https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]
[4] https://lore.kernel.org/r/[email protected]
[5] https://lore.kernel.org/r/[email protected]
[6] https://lore.kernel.org/r/[email protected]
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(-)