Skip to contentSkip to conversation

mm: page_alloc: add nid to mm_page_alloc tracepoint

PATCH In review Ye Bin 3 participants 3 messages Nov 13 – Nov 14

Subsystems (2)
lore
Share & tools
lore

Ye Bin

author
#0 lore raw

PATCH 1/1 mm: page_alloc: add nid to mm_page_alloc tracepoint

From: Ye Bin <[email protected]>

Add the NUMA node id to the mm_page_alloc trace event so that page allocations can be attributed to a specific node directly from the trace, without having to look up the pfn separately.

The nid is derived from the allocated page, or set to -1 when no page is available (e.g. failed allocations).

---
 include/trace/events/kmem.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/kmem.h +4 -1
index cd7920c81f85..8bf4e992d8bb 100644
@@ -189,6 +189,7 @@ TRACE_EVENT(mm_page_alloc,
 		__field(	unsigned int,	order		)
 		__field(	unsigned long,	gfp_flags	)
 		__field(	int,		migratetype	)
+		__field(	int,		nid		)
 	),
 
 	TP_fast_assign(
@@ -196,13 +197,15 @@ TRACE_EVENT(mm_page_alloc,
 		__entry->order		= order;
 		__entry->gfp_flags	= (__force unsigned long)gfp_flags;
 		__entry->migratetype	= migratetype;
+		__entry->nid		= page ? page_to_nid(page) : -1;
 	),
 
-	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s",
+	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d nid=%d gfp_flags=%s",
 		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
 		__entry->pfn != -1UL ? __entry->pfn : 0,
 		__entry->order,
 		__entry->migratetype,
+		__entry->nid,
 		show_gfp_flags(__entry->gfp_flags))
 );
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Ye Bin

From: Ye Bin <[email protected]>

Add the NUMA node id to the mm_page_alloc trace event so that page allocations can be attributed to a specific node directly from the trace, without having to look up the pfn separately.

But is it the right tradeoff? Trace data should be as minimal as possible for cpu and memory purposes. Anything extra that can be achieved by postprocessing is better done that way. Matching pfn to node using /proc/zoneinfo is simple.

Quoted 37 lines

The nid is derived from the allocated page, or set to -1 when no page is available (e.g. failed allocations).

---
 include/trace/events/kmem.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/kmem.h +4 -1
index cd7920c81f85..8bf4e992d8bb 100644
@@ -189,6 +189,7 @@ TRACE_EVENT(mm_page_alloc,
 		__field(	unsigned int,	order		)
 		__field(	unsigned long,	gfp_flags	)
 		__field(	int,		migratetype	)
+		__field(	int,		nid		)
 	),
 
 	TP_fast_assign(
@@ -196,13 +197,15 @@ TRACE_EVENT(mm_page_alloc,
 		__entry->order		= order;
 		__entry->gfp_flags	= (__force unsigned long)gfp_flags;
 		__entry->migratetype	= migratetype;
+		__entry->nid		= page ? page_to_nid(page) : -1;
 	),
 
-	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s",
+	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d nid=%d gfp_flags=%s",
 		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
 		__entry->pfn != -1UL ? __entry->pfn : 0,
 		__entry->order,
 		__entry->migratetype,
+		__entry->nid,
 		show_gfp_flags(__entry->gfp_flags))
 );
 
#2 lore raw
Quoted 12 lines · Vlastimil Babka (SUSE)
Quoted 5 lines · Ye Bin

From: Ye Bin <[email protected]>

Add the NUMA node id to the mm_page_alloc trace event so that page allocations can be attributed to a specific node directly from the trace, without having to look up the pfn separately.

But is it the right tradeoff? Trace data should be as minimal as possible for cpu and memory purposes. Anything extra that can be achieved by postprocessing is better done that way. Matching pfn to node using /proc/zoneinfo is simple.

Hi,

I agree with the general principle that trace data should be kept minimal and that anything computable in post-processing is better done there. But I think the "matching pfn to node via /proc/zoneinfo is simple" part underestimates the actual work involved, and for this particular event the tradeoff is not as clear as it looks.Although AI can be used to analyze data now, not all data in every scenario can be exported for post-processing analysis. Online debugging requires speed.
Trace is a debugging facility to begin with. Enabling it already has a performance cost by design; that's accepted when you turn it on. Adding one int to an event that already carries pfn, order, migratetype and gfp_flags is a marginal increase relative to that, while the benefit — direct, unambiguous node attribution — is immediate.
So while the extra field does cost some ring buffer space and a small amount of work in TP_fast_assign(), I think adding nid here is the more practical tradeoff.

Quoted 41 lines
Quoted 27 lines

The nid is derived from the allocated page, or set to -1 when no page is available (e.g. failed allocations).

---
  include/trace/events/kmem.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/kmem.h +2 -0
index cd7920c81f85..8bf4e992d8bb 100644
@@ -189,6 +189,7 @@ TRACE_EVENT(mm_page_alloc,
  		__field(	unsigned int,	order		)
  		__field(	unsigned long,	gfp_flags	)
  		__field(	int,		migratetype	)
+		__field(	int,		nid		)
  	),
 
  	TP_fast_assign(
@@ -196,13 +197,15 @@ TRACE_EVENT(mm_page_alloc,
  		__entry->order		= order;
  		__entry->gfp_flags	= (__force unsigned long)gfp_flags;
  		__entry->migratetype	= migratetype;
+		__entry->nid		= page ? page_to_nid(page) : -1;
  	),
 

include/trace/events/kmem.h TRACE_EVENT(mm_page_alloc, · line 211

Quoted 10 lines
include/trace/events/kmem.h +2 -1
-	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d gfp_flags=%s",
+	TP_printk("page=%p pfn=0x%lx order=%d migratetype=%d nid=%d gfp_flags=%s",
  		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
  		__entry->pfn != -1UL ? __entry->pfn : 0,
  		__entry->order,
  		__entry->migratetype,
+		__entry->nid,
  		show_gfp_flags(__entry->gfp_flags))
  );
 

.