3
0
Fork 0
forked from mirrors/linux
kernel/mm
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
..
damon mm/damon/Kconfig: enable CONFIG_DAMON by default 2025-05-31 22:46:12 -07:00
kasan hardening fixes for v6.15-rc3 2025-04-18 13:20:20 -07:00
kfence kfence: skip __GFP_THISNODE allocations on NUMA systems 2025-02-01 03:53:26 -08:00
kmsan kmsan: rework kmsan_in_runtime() handling in kmsan_report() 2025-05-21 09:55:16 -07:00
backing-dev.c treewide: Switch/rename to timer_delete[_sync]() 2025-04-05 10:30:12 +02:00
balloon_compaction.c balloon_compaction: update the NR_BALLOON_PAGES state 2025-03-21 22:03:13 -07:00
bootmem_info.c mm/sparse: allow for alternate vmemmap section init at boot 2025-03-16 22:06:27 -07:00
cma.c mm: cma: set early_pfn and bitmap as a union in cma_memrange 2025-05-22 14:55:36 -07:00
cma.h mm: cma: set early_pfn and bitmap as a union in cma_memrange 2025-05-22 14:55:36 -07:00
cma_debug.c mm, cma: support multiple contiguous ranges, if requested 2025-03-16 22:06:25 -07:00
cma_sysfs.c mm/cma: export total and free number of pages for CMA areas 2025-03-16 22:06:24 -07:00
compaction.c mm: page_alloc: tighten up find_suitable_fallback() 2025-05-11 17:48:18 -07:00
debug.c mm/debug: fix parameter passed to page_mapcount_is_type() 2025-05-11 17:48:17 -07:00
debug_page_alloc.c mm/debug_page_alloc: improve error message for invalid guardpage minorder 2025-05-12 23:50:38 -07:00
debug_page_ref.c
debug_vm_pgtable.c mm: remove mk_huge_pte() 2025-05-11 17:48:04 -07:00
dmapool.c
dmapool_test.c
early_ioremap.c
execmem.c execmem: enforce allocation size aligment to PAGE_SIZE 2025-05-12 23:50:33 -07:00
fadvise.c
fail_page_alloc.c
failslab.c
filemap.c mm: rename page->index to page->__folio_index 2025-05-31 22:46:06 -07:00
folio-compat.c mm: Remove grab_cache_page_write_begin() 2025-03-04 17:02:25 +00:00
gup.c mm/gup: update comment explaining why gup_fast() disables IRQs 2025-05-31 22:46:14 -07:00
gup_test.c
gup_test.h
highmem.c
hmm.c mm: allow compound zone device pages 2025-03-17 22:06:39 -07:00
huge_memory.c mm: convert track_pfn_insert() to pfnmap_setup_cachemode*() 2025-05-22 14:55:36 -07:00
hugetlb.c hugetlb: show nr_huge_pages in report_hugepages() 2025-05-31 22:46:11 -07:00
hugetlb_cgroup.c page_counter: track failcnt only for legacy cgroups 2025-03-17 00:05:35 -07:00
hugetlb_cma.c mm/hugetlb: use separate nodemask for bootmem allocations 2025-05-12 23:50:35 -07:00
hugetlb_cma.h mm/hugetlb: move hugetlb CMA code in to its own file 2025-03-16 22:06:31 -07:00
hugetlb_vmemmap.c mm, hugetlb: increment the number of pages to be reset on HVO 2025-04-17 20:10:08 -07:00
hugetlb_vmemmap.h mm/hugetlb: do pre-HVO for bootmem allocated pages 2025-03-16 22:06:29 -07:00
hwpoison-inject.c
init-mm.c mm: replace vm_lock and detached flag with a reference count 2025-03-16 22:06:20 -07:00
internal.h mm: move dup_mmap() to mm 2025-05-12 23:50:48 -07:00
interval_tree.c
io-mapping.c mm/io-mapping: track_pfn() -> "pfnmap tracking" 2025-05-22 14:55:37 -07:00
ioremap.c mm/ioremap: pass pgprot_t to ioremap_prot() instead of unsigned long 2025-03-16 22:06:23 -07:00
Kconfig mm: add CONFIG_PAGE_BLOCK_ORDER to select page block order 2025-05-31 22:46:13 -07:00
Kconfig.debug mm: rename GENERIC_PTDUMP and PTDUMP_CORE 2025-03-17 00:05:32 -07:00
khugepaged.c mm/khugepaged: fix race with folio split/free using temporary reference 2025-05-31 22:46:13 -07:00
kmemleak.c mm: kmemleak: mark variables as __read_mostly 2025-05-12 23:50:47 -07:00
ksm.c mm/ksm: handle device-exclusive entries correctly in write_protect_page() 2025-03-16 22:05:58 -07:00
list_lru.c mm/list_lru: make the case where mlru is NULL as unlikely 2025-03-17 00:05:32 -07:00
maccess.c
madvise.c mm/madvise: batch tlb flushes for MADV_DONTNEED[_LOCKED] 2025-05-11 17:48:27 -07:00
Makefile mm: perform VMA allocation, freeing, duplication in mm 2025-05-12 23:50:48 -07:00
mapping_dirty_helpers.c
memblock.c memblock: add KHO support for reserve_mem 2025-05-12 23:50:42 -07:00
memcontrol-v1.c memcg: make count_memcg_events re-entrant safe against irqs 2025-05-22 14:55:38 -07:00
memcontrol-v1.h memcg: move do_memsw_account() to CONFIG_MEMCG_V1 2025-03-21 22:03:11 -07:00
memcontrol.c sched/numa: add statistics of numa balance task 2025-05-31 22:46:15 -07:00
memfd.c mm: move folio_index to mm/swap.h and remove no longer needed helper 2025-05-12 23:50:50 -07:00
memory-failure.c mm: memory-failure: enhance comments for return value of memory_failure() 2025-03-17 22:07:05 -07:00
memory-tiers.c
memory.c mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables() 2025-05-31 22:46:12 -07:00
memory_hotplug.c mm: use for_each_valid_pfn() in memory_hotplug 2025-05-12 23:50:44 -07:00
mempolicy.c mm/mempolicy: Weighted Interleave Auto-tuning 2025-05-21 09:55:15 -07:00
mempool.c
memremap.c mm: introduce pfnmap_track() and pfnmap_untrack() and use them for memremap 2025-05-22 14:55:37 -07:00
memtest.c
migrate.c mm: move folio_index to mm/swap.h and remove no longer needed helper 2025-05-12 23:50:50 -07:00
migrate_device.c - The 6 patch series "Enable strict percpu address space checks" from 2025-04-01 09:29:18 -07:00
mincore.c mm: mincore: use pte_batch_hint() to batch process large folios 2025-05-22 14:55:36 -07:00
mlock.c mm: allow compound zone device pages 2025-03-17 22:06:39 -07:00
mm_init.c mm: add CONFIG_PAGE_BLOCK_ORDER to select page block order 2025-05-31 22:46:13 -07:00
mm_slot.h
mmap.c mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack() 2025-05-22 14:55:37 -07:00
mmap_lock.c mm: move mmap/vma locking logic into specific files 2025-05-11 17:48:33 -07:00
mmu_gather.c mmu_gather: move tlb flush for VM_PFNMAP/VM_MIXEDMAP vmas into free_pgtables() 2025-05-31 22:46:12 -07:00
mmu_notifier.c Update Christoph's Email address and make it consistent 2025-05-12 23:50:31 -07:00
mmzone.c
mprotect.c mm/huge_memory: remove useless folio pointers passing 2025-05-12 23:50:34 -07:00
mremap.c mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack() 2025-05-22 14:55:37 -07:00
mseal.c
msync.c
nommu.c mm: perform VMA allocation, freeing, duplication in mm 2025-05-12 23:50:48 -07:00
numa.c mm/numa: remove unnecessary local variable in alloc_node_data() 2025-05-12 23:50:38 -07:00
numa_emulation.c
numa_memblks.c mm: numa_memblks: introduce numa_add_reserved_memblk 2025-05-22 14:55:36 -07:00
oom_kill.c mm/oom_kill: fix trivial typo in comment 2025-03-16 22:05:55 -07:00
page-writeback.c mm: rename page->index to page->__folio_index 2025-05-31 22:46:06 -07:00
page_alloc.c mm: pcp: increase pcp->free_count threshold to trigger free_high 2025-05-27 19:38:27 -07:00
page_counter.c page_counter: track failcnt only for legacy cgroups 2025-03-17 00:05:35 -07:00
page_ext.c mm: page_ext: add an iteration API for page extensions 2025-03-17 22:06:57 -07:00
page_frag_cache.c
page_idle.c mm/page_idle: handle device-exclusive entries correctly in page_idle_clear_pte_refs_one() 2025-03-16 22:05:59 -07:00
page_io.c page_io: zswap: do not crash the kernel on decompression failure 2025-03-17 22:06:50 -07:00
page_isolation.c mm: page_isolation: avoid calling folio_hstate() without hugetlb_lock 2025-04-01 15:14:43 -07:00
page_owner.c mm: rename try_alloc_pages() to alloc_pages_nolock() 2025-05-22 14:55:37 -07:00
page_poison.c
page_reporting.c
page_reporting.h
page_table_check.c mm: page_table_check: use new iteration API 2025-03-17 22:06:57 -07:00
page_vma_mapped.c mm: make page_mapped_in_vma() hugetlb walk aware 2025-03-16 22:06:42 -07:00
pagewalk.c
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c - The 6 patch series "Enable strict percpu address space checks" from 2025-04-01 09:29:18 -07:00
pgalloc-track.h
pgtable-generic.c
process_vm_access.c
pt_reclaim.c
ptdump.c mm/ptdump: split effective_prot() into level specific callbacks 2025-05-11 17:48:19 -07:00
readahead.c Revert "fanotify: disable readahead if we have pre-content watches" 2025-03-13 16:31:12 +01:00
rmap.c mm/rmap: fix typo in comment in page_address_in_vma 2025-05-12 23:50:37 -07:00
rodata_test.c
secretmem.c mm: secretmem: convert to .mmap_prepare() hook 2025-05-13 16:28:07 -07:00
shmem.c mm/shmem: remove unneeded xa_is_value() check in shmem_unuse_swap_entries() 2025-05-31 22:46:11 -07:00
shmem_quota.c
show_mem.c mm: add nr_free_highatomic in show_free_areas 2025-05-11 17:48:32 -07:00
shrinker.c
shrinker_debug.c mm/shrinker: fix name consistency issue in shrinker_debugfs_rename() 2025-03-17 00:05:40 -07:00
shuffle.c
shuffle.h
slab.h Merge branch 'slab/for-6.15/kfree_rcu_tiny' into slab/for-next 2025-03-20 10:33:38 +01:00
slab_common.c Update Christoph's Email address and make it consistent 2025-05-12 23:50:31 -07:00
slub.c mm, slab: clean up slab->obj_exts always 2025-04-24 19:19:40 +02:00
sparse-vmemmap.c mm/hugetlb: do pre-HVO for bootmem allocated pages 2025-03-16 22:06:29 -07:00
sparse.c drivers/base/memory: improve add_boot_memory_block() 2025-03-17 22:07:01 -07:00
swap.c memcg: make count_memcg_events re-entrant safe against irqs 2025-05-22 14:55:38 -07:00
swap.h mm: move folio_index to mm/swap.h and remove no longer needed helper 2025-05-12 23:50:50 -07:00
swap_cgroup.c mm: swap_cgroup: remove double initialization of locals 2025-03-17 22:06:58 -07:00
swap_state.c mm: convert free_page_and_swap_cache() to free_folio_and_swap_cache() 2025-05-11 17:48:32 -07:00
swapfile.c mm, swap: remove no longer used swap mapping helper 2025-05-12 23:50:51 -07:00
truncate.c mm: rename page->index to page->__folio_index 2025-05-31 22:46:06 -07:00
usercopy.c mm: security: Check early if HARDENED_USERCOPY is enabled 2025-02-28 11:51:31 -08:00
userfaultfd.c mm: add folio_mk_pte() 2025-05-11 17:48:03 -07:00
util.c Summary 2025-03-26 21:02:05 -07:00
vma.c mm/vma: remove mmap() retry merge 2025-05-13 16:28:07 -07:00
vma.h mm: perform VMA allocation, freeing, duplication in mm 2025-05-12 23:50:48 -07:00
vma_exec.c mm: abstract initial stack setup to mm subsystem 2025-05-12 23:50:48 -07:00
vma_init.c mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack() 2025-05-22 14:55:37 -07:00
vma_internal.h
vmalloc.c mm/vmalloc: fix data race in show_numa_info() 2025-05-22 14:55:36 -07:00
vmpressure.c
vmscan.c memcg: make count_memcg_events re-entrant safe against irqs 2025-05-22 14:55:38 -07:00
vmstat.c sched/numa: add statistics of numa balance task 2025-05-31 22:46:15 -07:00
workingset.c mm: workingset: simplify lockdep check in update_node 2025-05-12 23:50:44 -07:00
zpdesc.h mm: rename page->index to page->__folio_index 2025-05-31 22:46:06 -07:00
zpool.c zsmalloc: prefer the the original page's node for compressed data 2025-05-11 17:48:06 -07:00
zsmalloc.c zsmalloc: cleanup headers includes 2025-05-11 17:48:16 -07:00
zswap.c zsmalloc: prefer the the original page's node for compressed data 2025-05-11 17:48:06 -07:00