linux/Documentation
Chen Yu ad6b26b6a0 sched/numa: add statistics of numa balance task
On systems with NUMA balancing enabled, it has been found that tracking
task activities resulting from NUMA balancing is beneficial.  NUMA
balancing employs two mechanisms for task migration: one is to migrate
a task to an idle CPU within its preferred node, and the other is to
swap tasks located on different nodes when they are on each other's
preferred nodes.

The kernel already provides NUMA page migration statistics in
/sys/fs/cgroup/mytest/memory.stat and /proc/{PID}/sched.  However, it
lacks statistics regarding task migration and swapping.  Therefore,
relevant counts for task migration and swapping should be added.

The following two new fields:

numa_task_migrated
numa_task_swapped

will be shown in /sys/fs/cgroup/{GROUP}/memory.stat, /proc/{PID}/sched
and /proc/vmstat.

Introducing both per-task and per-memory cgroup (memcg) NUMA balancing
statistics facilitates a rapid evaluation of the performance and
resource utilization of the target workload.  For instance, users can
first identify the container with high NUMA balancing activity and then
further pinpoint a specific task within that group, and subsequently
adjust the memory policy for that task.  In short, although it is
possible to iterate through /proc/$pid/sched to locate the problematic
task, the introduction of aggregated NUMA balancing activity for tasks
within each memcg can assist users in identifying the task more
efficiently through a divide-and-conquer approach.

As Libo Chen pointed out, the memcg event relies on the text names in
vmstat_text, and /proc/vmstat generates corresponding items based on
vmstat_text.  Thus, the relevant task migration and swapping events
introduced in vmstat_text also need to be populated by
count_vm_numa_event(), otherwise these values are zero in /proc/vmstat.

In theory, task migration and swap events are part of the scheduler's
activities.  The reason for exposing them through the
memory.stat/vmstat interface is that we already have NUMA balancing
statistics in memory.stat/vmstat, and these events are closely related
to each other.  Following Shakeel's suggestion, we describe the
end-to-end flow/story of all these events occurring on a timeline for
future reference:

The goal of NUMA balancing is to co-locate a task and its memory pages
on the same NUMA node.  There are two strategies: migrate the pages to
the task's node, or migrate the task to the node where its pages
reside.

Suppose a task p1 is running on Node 0, but its pages are located on
Node 1.  NUMA page fault statistics for p1 reveal its "page footprint"
across nodes.  If NUMA balancing detects that most of p1's pages are on
Node 1:

1.Page Migration Attempt:
The Numa balance first tries to migrate p1's pages to Node 0.
The numa_page_migrate counter increments.

2.Task Migration Strategies:
After the page migration finishes, Numa balance checks every
1 second to see if p1 can be migrated to Node 1.

Case 2.1: Idle CPU Available

  If Node 1 has an idle CPU, p1 is directly scheduled there.  This
  event is logged as numa_task_migrated.

Case 2.2: No Idle CPU (Task Swap)

  If all CPUs on Node1 are busy, direct migration could cause CPU
  contention or load imbalance.  Instead: The Numa balance selects a
  candidate task p2 on Node 1 that prefers Node 0 (e.g., due to its own
  page footprint).  p1 and p2 are swapped.  This cross-node swap is
  recorded as numa_task_swapped.

Link: https://lkml.kernel.org/r/d00edb12ba0f0de3c5222f61487e65f2ac58f5b1.1748493462.git.yu.c.chen@intel.com
Link: https://lkml.kernel.org/r/7ef90a88602ed536be46eba7152ed0d33bad5790.1748002400.git.yu.c.chen@intel.com
Signed-off-by: Chen Yu <yu.c.chen@intel.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
Cc: Aubrey Li <aubrey.li@intel.com>
Cc: Ayush Jain <Ayush.jain3@amd.com>
Cc: "Chen, Tim C" <tim.c.chen@intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Libo Chen <libo.chen@oracle.com>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-05-31 22:46:15 -07:00
..
ABI mm/mempolicy: Weighted Interleave Auto-tuning 2025-05-21 09:55:15 -07:00
PCI
RCU - The 6 patch series "Enable strict percpu address space checks" from 2025-04-01 09:29:18 -07:00
accel
accounting
admin-guide sched/numa: add statistics of numa balance task 2025-05-31 22:46:15 -07:00
arch OpenRISC updates for 6.15 2025-04-26 09:01:13 -07:00
block Documentation: ublk: remove dead footnote 2025-03-31 07:06:22 -06:00
bpf bpf: Add namespace to BPF internal symbols 2025-04-25 09:21:23 -07:00
cdrom
core-api Documentation: KHO: add memblock bindings 2025-05-12 23:50:43 -07:00
cpu-freq
crypto crypto: remove obsolete 'comp' compression API 2025-03-21 17:39:06 +08:00
dev-tools Kbuild updates for v6.15 2025-04-05 15:46:50 -07:00
devicetree Input updates for v6.15-rc5 2025-05-11 10:29:29 -07:00
doc-guide
driver-api cxl for v6.15 2025-04-02 20:04:43 -07:00
edac
fault-injection
fb
features mseal sysmap: add arch-support txt 2025-04-01 15:17:17 -07:00
filesystems A few more miscellaneous ext4 bug fixes and cleanups including some 2025-04-13 07:15:50 -07:00
firmware-guide
firmware_class
fpga
gpu
hid
hwmon hwmon: add driver for HTU31 2025-03-18 08:03:40 -07:00
i2c
iio Char/Misc/IIO driver updates for 6.15-rc1 2025-04-01 11:26:08 -07:00
images
infiniband
input
isdn
kbuild kbuild: make all file references relative to source root 2025-03-22 23:50:58 +09:00
kernel-hacking
leds
litmus-tests
livepatch
locking hwspinlock: Remove unused hwspin_lock_get_id() 2025-03-21 17:12:04 -05:00
maintainer
mhi
misc-devices
mm Docs/damon: update titles and brief introductions to explain DAMOS 2025-05-22 14:55:38 -07:00
netlabel
netlink netlink: specs: ethtool: Remove UAPI duplication of phy-upstream enum 2025-04-28 15:49:47 -07:00
networking Update Christoph's Email address and make it consistent 2025-05-12 23:50:31 -07:00
nvdimm
nvme
pcmcia
peci
power Documentation: PM: runtime: Fix a reference to pm_runtime_autosuspend() 2025-04-15 19:23:58 +02:00
process Devicetree for v6.15: 2025-03-29 11:23:16 -07:00
rust ARM and clkdev updates for 6.15-rc1 2025-04-03 12:21:44 -07:00
scheduler Scheduler updates for v6.15: 2025-03-24 21:28:12 -07:00
scsi
security Hi, 2025-03-28 12:42:53 -07:00
sound sound updates for 6.15-rc1 2025-03-26 09:41:55 -07:00
sphinx
sphinx-static
spi
staging
sunrpc/xdr
target
tee
timers
tools Documentation/rv: Add sched pages to the indices 2025-03-27 12:02:38 -04:00
trace tracing/timers: Rename the hrtimer_init event to hrtimer_setup 2025-04-05 10:30:17 +02:00
translations OpenRISC updates for 6.15 2025-04-26 09:01:13 -07:00
usb USB/Thunderbolt update for 6.15-rc1 2025-04-02 18:23:31 -07:00
userspace-api mseal: fix typo and style in documentation 2025-04-11 17:32:35 -07:00
virt Documentation: kvm: remove KVM_CAP_MIPS_TE 2025-04-04 06:32:17 -04:00
w1
watchdog
wmi platform/x86: msi-wmi-platform: Workaround a ACPI firmware bug 2025-04-16 11:15:22 +03:00
.gitignore
Changes
CodingStyle
Kconfig
Makefile
SubmittingPatches
atomic_bitops.txt
atomic_t.txt
conf.py
docutils.conf
index.rst
memory-barriers.txt
subsystem-apis.rst Documentation/EDAC: Fix warning document isn't included in any toctree 2025-04-01 22:26:47 +02:00