Skip to contentSkip to conversation

mm/mempolicy: track user-defined mempolicy allocations

PATCH Superseded JP Kobryn (Meta) 1 participant 1 message Mar 17

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mm/mempolicy: track user-defined mempolicy allocations

When investigating pressure on a NUMA node, there is no straightforward way to determine which user-defined policies are driving allocations to it.

Add NUMA mempolicy allocation counters as new node stat items. These counters track allocations to nodes and also whether the allocations were intentional or fallbacks.

The new stats follow the existing numa hit/miss/foreign style and have the following meanings:

hit
- for nodemask-based policies, allocation succeeded within nodemask
- for other policies, allocation succeeded on intended node
- counted on the node of the allocation
miss
- allocation intended for other node, but happened on this one
- counted on other node
foreign
- allocation intended on this node, but happened on other node
- counted on this node

The existing numa_* counters cannot be adjusted to fill this role because they are incremented in zone_statistics(), which also covers non-policy allocations such as alloc_pages_node(). The mempolicy context is not applicable at that level since in-kernel callers may make their own node decisions independent of any task policy.

Allocations where task mempolicy is NULL are excluded since they do not reflect a user designation and are already accounted for in the existing numa_* stats.

Counters are exposed per-node in nodeN/vmstat and globally in /proc/vmstat. They provide the information needed in step 3 of the investigation workflow below:

1) Pressure/OOMs reported while system-wide memory is free.
2) Check /proc/zoneinfo or per-node stats in .../nodeN/vmstat to narrow down node(s) under pressure.
3) Check numa_mpol_{hit,miss,foreign} counters (added by this patch) on node(s) to see what policy is driving allocations there (and whether they are intentional vs fallback).
- If active: a user-defined policy is driving allocations to the node. Proceed to step 4.
- If inactive: pressure is from allocations without a user-defined policy. Stop and investigate task placement or node capacity instead.
4) Use /proc/*/numa_maps to identify tasks using the policy.

---
v3:
- Moved stats off of memcg
- Switched from per-policy to aggregated counters (18 -> 3)
- Filter allocations with no user-specified policy

v2: https://lore.kernel.org/linux-mm/[email protected]/
- Replaced single per-policy total counter (PGALLOC_MPOL_*) with hit/miss/foreign triplet per policy
- Changed from global node stats to per-memcg per-node tracking

v1: https://lore.kernel.org/linux-mm/[email protected]/

 include/linux/mmzone.h |  5 ++++
 mm/mempolicy.c         | 53 +++++++++++++++++++++++++++++++++++++++---
 mm/vmstat.c            |  5 ++++
 3 files changed, 60 insertions(+), 3 deletions(-)
include/linux/mmzone.h +5 -0
index 7bd0134c241c..a9407a3b4c8a 100644
@@ -323,6 +323,11 @@ enum node_stat_item {
 	PGSCAN_ANON,
 	PGSCAN_FILE,
 	PGREFILL,
+#ifdef CONFIG_NUMA
+	NUMA_MPOL_HIT,
+	NUMA_MPOL_MISS,
+	NUMA_MPOL_FOREIGN,
+#endif
 #ifdef CONFIG_HUGETLB_PAGE
 	NR_HUGETLB,
 #endif
mm/mempolicy.c +50 -3

77 lines not on this page · raw message

mm/vmstat.c +5 -0
index b33097ab9bc8..4a8384441870 100644
@@ -1291,6 +1291,11 @@ const char * const vmstat_text[] = {
 	[I(PGSCAN_ANON)]			= "pgscan_anon",
 	[I(PGSCAN_FILE)]			= "pgscan_file",
 	[I(PGREFILL)]				= "pgrefill",
+#ifdef CONFIG_NUMA
+	[I(NUMA_MPOL_HIT)]			= "numa_mpol_hit",
+	[I(NUMA_MPOL_MISS)]			= "numa_mpol_miss",
+	[I(NUMA_MPOL_FOREIGN)]			= "numa_mpol_foreign",
+#endif
 #ifdef CONFIG_HUGETLB_PAGE
 	[I(NR_HUGETLB)]				= "nr_hugetlb",
 #endif
Signature · 1 line
2.52.0