[Devel] [PATCH RH8 09/10] mm/page_alloc: add latency to the page_alloc tracepoint

Andrey Zhadchenko andrey.zhadchenko at virtuozzo.com
Wed May 26 17:56:17 MSK 2021


From: Andrey Ryabinin <aryabinin at virtuozzo.com>

Add 'lat' field to the mm_page_alloc tracepoint. It shows allocation
latency in microseconds (0.000001 second).

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov at virtuozzo.com>

++++++++++++

mm/page_alloc: fix latency in tracepoint.

Since transition from jiffies to sched_clock(), mm_page_alloc
garbadge since we substract from jiffies nanoseconds.
Fix this.

Fixes: e9e7602565ab ("mm/page_alloc: use sched_clock() instead of jiffies to
measure latency")
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

++++++++++++

mm/page_alloc: fix latency in tracepoint - addon

Compilation warning fixed: use proper type.

Fixes: 7eff199a7a9e ("mm/page_alloc: fix latency in tracepoint.")

Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

++++++++++++

mm/trace: fix always 0 latency in page_alloc tracepoint

Since __entry->time wasn't assigned, mm_page_alloc trace point
shows always 0 lat.

Fixes: fc8961c87c00 ("mm/page_alloc: add latency to the page_alloc tracepoint")
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>

Rebased to vz8 and merged following patches:
 - b3e2b2367630 ("mm/page_alloc: add latency to the page_alloc tracepoint")
 - 5ae153305c03 ("mm/page_alloc: fix latency in tracepoint.")
 - b6be69d05fd4 ("mm/page_alloc: fix latency in tracepoint - addon")
 - 0662cba1feed ("mm/trace: fix always 0 latency in page_alloc tracepoint")
Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>

diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h
index eb57e30..e6c62ea 100644
--- a/include/trace/events/kmem.h
+++ b/include/trace/events/kmem.h
@@ -192,15 +192,16 @@
 TRACE_EVENT(mm_page_alloc,
 
 	TP_PROTO(struct page *page, unsigned int order,
-			gfp_t gfp_flags, int migratetype),
+			gfp_t gfp_flags, int migratetype, u64 time),
 
-	TP_ARGS(page, order, gfp_flags, migratetype),
+	TP_ARGS(page, order, gfp_flags, migratetype, time),
 
 	TP_STRUCT__entry(
 		__field(	unsigned long,	pfn		)
 		__field(	unsigned int,	order		)
 		__field(	gfp_t,		gfp_flags	)
 		__field(	int,		migratetype	)
+		__field(	u64,		time		)
 	),
 
 	TP_fast_assign(
@@ -208,14 +209,16 @@
 		__entry->order		= order;
 		__entry->gfp_flags	= gfp_flags;
 		__entry->migratetype	= migratetype;
+		__entry->time		= time;
 	),
 
-	TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s",
+	TP_printk("page=%p pfn=%lu order=%d migratetype=%d gfp_flags=%s lat=%llu",
 		__entry->pfn != -1UL ? pfn_to_page(__entry->pfn) : NULL,
 		__entry->pfn != -1UL ? __entry->pfn : 0,
 		__entry->order,
 		__entry->migratetype,
-		show_gfp_flags(__entry->gfp_flags))
+		show_gfp_flags(__entry->gfp_flags),
+		__entry->time)
 );
 
 DECLARE_EVENT_CLASS(mm_page,
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index b5afa2a..f66accf 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -4552,14 +4552,13 @@ void update_maxlat(struct kstat_lat_snap_struct *alloc_lat,
 }
 
 static void __alloc_collect_stats(gfp_t gfp_mask, unsigned int order,
-		struct page *page, u64 time)
+		struct page *page, u64 time, u64 current_clock)
 {
 #ifdef CONFIG_VE
 	unsigned long flags;
-	u64 current_clock, delta;
+	u64 delta;
 	int ind, cpu;
 
-	current_clock = sched_clock();
 	delta = current_clock - time;
 	if (!(gfp_mask & __GFP_RECLAIM))
 		ind = KSTAT_ALLOCSTAT_ATOMIC;
@@ -4596,7 +4595,7 @@ struct page *
 	unsigned int alloc_flags = ALLOC_WMARK_LOW;
 	gfp_t alloc_mask; /* The gfp_t that was actually used for allocation */
 	struct alloc_context ac = { };
-	u64 start;
+	u64 start, current_clock;
 
 	gfp_mask &= gfp_allowed_mask;
 	alloc_mask = gfp_mask;
@@ -4639,8 +4638,10 @@ struct page *
 		page = NULL;
 	}
 
-	__alloc_collect_stats(alloc_mask, order, page, start);
-	trace_mm_page_alloc(page, order, alloc_mask, ac.migratetype);
+	current_clock = sched_clock();
+	__alloc_collect_stats(alloc_mask, order, page, start, current_clock);
+	trace_mm_page_alloc(page, order, alloc_mask, ac.migratetype,
+			(current_clock - start));
 
 	return page;
 }
-- 
1.8.3.1



More information about the Devel mailing list