[Devel] [PATCH RHEL8 COMMIT] mm/page_alloc: add latency to the page_alloc tracepoint

Konstantin Khorenko khorenko at virtuozzo.com
Tue Jun 1 20:35:09 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.34
------>
commit bc4ec61884b02012926c8104d76882d93045e3d9
Author: Andrey Ryabinin <aryabinin at virtuozzo.com>
Date:   Tue Jun 1 20:35:08 2021 +0300

    mm/page_alloc: add latency to the page_alloc tracepoint
    
    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.
    
    mFixes: 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.
    
    mFixes: 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.
    
    mFixes: 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 vz7 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>
---
 include/trace/events/kmem.h | 11 +++++++----
 mm/page_alloc.c             | 13 +++++++------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/trace/events/kmem.h b/include/trace/events/kmem.h
index eb57e3037deb..e6c62ea527fb 100644
--- a/include/trace/events/kmem.h
+++ b/include/trace/events/kmem.h
@@ -192,15 +192,16 @@ TRACE_EVENT(mm_page_free_batched,
 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 @@ TRACE_EVENT(mm_page_alloc,
 		__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 548c4d087664..ce2f69c5b54b 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)) {
 		if (in_task())
@@ -4600,7 +4599,7 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
 	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;
@@ -4643,8 +4642,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, int preferred_nid,
 		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;
 }


More information about the Devel mailing list