mm/vmscan: move vmscan tracepoints to a local header
Subsystems (7)
v2 cover mm/vmscan: move vmscan tracepoints to a local header
From: Ridong Chen <[email protected]>
This series started as an effort to add two tracepoints for MGLRU. In the discussion, Steven suggested moving include/trace/events/vmscan.h to mm/trace_vmscan.h [1], as several other subsystems already do. Once the header lives under mm/, struct scan_control can be moved there too, letting the trace events access its fields directly instead of having each callsite copy the scalars out by hand.
The series builds in small steps:
1) drop the now-unused vmscan trace include from memcontrol.c;
2) move include/trace/events/vmscan.h to mm/trace_vmscan.h, using a
relative TRACE_INCLUDE_PATH so no Makefile change is needed;
3) move struct scan_control into a dedicated mm/vmscan.h, which trace_vmscan.h pulls in, guarded against the multi-read that define_trace.h performs;
4-7) pass scan_control to the vmscan tracepoints and pick the fields
out in TP_fast_assign, one group at a time: the reclaim-begin events, the LRU isolate/shrink events, mm_vmscan_reclaim_pages and mm_vmscan_balance_pgdat_end.
Besides the cleanup, this moves the code that computes the tracepoint parameters into TP_fast_assign(), which is in a separate text section. It removes code from the work flow, improving instruction cache.
There is no functional change and no ABI change: TP_STRUCT__entry and TP_printk are untouched, so the exported event format is identical. This was confirmed by diffing the tracefs format files before and after, and by capturing the direct/memcg/node reclaim-begin events under load in a QEMU guest (order, gfp_flags and memcg_id all match).
Where a value passed to a tracepoint is a local of the caller rather than a scan_control field (highest_zoneidx for balance_pgdat_end, nr_reclaimed for reclaim_pages), it stays a separate argument.
[1]: https://lore.kernel.org/linux-mm/20260916095122.50cbb620@robin/
---
Changes since v1:
- Convert the remaining vmscan tracepoints too, not just reclaim-begin
(4 -> 7 patches).
- Put struct scan_control in its own mm/vmscan.h instead of directly in trace_vmscan.h suggested by Baoquan.
Ridong Chen (7):
mm/memcontrol: drop unused vmscan tracepoint include mm/vmscan: move vmscan tracepoints to a local header mm/vmscan: move struct scan_control to a dedicated header mm/vmscan: pass scan_control to the reclaim-begin tracepoints mm/vmscan: pass scan_control to the LRU isolate/shrink tracepoints mm/vmscan: pass scan_control to mm_vmscan_reclaim_pages mm/vmscan: pass scan_control to mm_vmscan_balance_pgdat_end
MAINTAINERS | 4 + mm/memcontrol.c | 2 - mm/shrinker.c | 2 +- .../events/vmscan.h => mm/trace_vmscan.h | 80 ++++++----- mm/vmscan.c | 136 ++---------------- mm/vmscan.h | 118 +++++++++++++++ 6 files changed, 178 insertions(+), 164 deletions(-) rename include/trace/events/vmscan.h => mm/trace_vmscan.h (90%) create mode 100644 mm/vmscan.h
Signature · 1 line
2.34.1
RFC PATCH v2 1/7 mm/memcontrol: drop unused vmscan tracepoint include
From: Ridong Chen <[email protected]>
memcontrol.c includes <trace/events/vmscan.h> but does not use any of the tracepoints or macros it defines: all tracepoints invoked here come from memcg.h and writeback.h. Removing the include still compiles cleanly.
--- mm/memcontrol.c | 2 -- 1 file changed, 2 deletions(-)
mm/memcontrol.c +0 -2
@@ -77,8 +77,6 @@#include <trace/events/memcg.h> #undef CREATE_TRACE_POINTS -#include <trace/events/vmscan.h> -struct cgroup_subsys memory_cgrp_subsys__read_mostly ;EXPORT_SYMBOL (memory_cgrp_subsys);
Signature · 1 line
2.34.1
Re: [PATCH RFC v2 1/7] mm/memcontrol: drop unused vmscan tracepoint include
Quoted 12 lines · Ridong Chen
From: Ridong Chen <[email protected]>
memcontrol.cincludes <trace/events/vmscan.h> but does not use any of the tracepoints or macros it defines: all tracepoints invoked here come frommemcg.handwriteback.h. Removing the include still compiles cleanly.Assisted-by Claude:claude-opus-4-8
Since commit 816d9992d9ed, the label we recommend is Assisted-by: LLM.
Quoted 10 lines
Signed-off-by Ridong Chen <[email protected]>---
mm/memcontrol.c| 2 --1 file changed, 2 deletions(-)mm/memcontrol.c +0
-0
mm/memcontrol.c line 81
Quoted 7 lines
mm/memcontrol.c +0
-2@@ -77,8 +77,6 @@#include <trace/events/memcg.h> #undef CREATE_TRACE_POINTS -#include <trace/events/vmscan.h> -struct cgroup_subsys memory_cgrp_subsys__read_mostly ;EXPORT_SYMBOL (memory_cgrp_subsys);
Thanks.
Re: [PATCH RFC v2 1/7] mm/memcontrol: drop unused vmscan tracepoint include
Quoted 6 lines · Muchun Song
Quoted 6 lines · Ridong Chen
From: Ridong Chen <[email protected]>
Quoted 9 lines
Quoted 6 lines
memcontrol.cincludes <trace/events/vmscan.h> but does not use any of the tracepoints or macros it defines: all tracepoints invoked here come frommemcg.handwriteback.h. Removing the include still compiles cleanly.Assisted-by Claude:claude-opus-4-8Since commit
816d9992d9ed, the label we recommend is Assisted-by: LLM.
Thank you for the reminder; I will update it in the next version.
Quoted 21 lines
Quoted 10 lines
Signed-off-by Ridong Chen <[email protected]>---
mm/memcontrol.c| 2 --1 file changed, 2 deletions(-)mm/memcontrol.c +0
-0mm/memcontrol.c line 81
Quoted 7 lines
mm/memcontrol.c +0
-2@@ -77,8 +77,6 @@#include <trace/events/memcg.h> #undef CREATE_TRACE_POINTS -#include <trace/events/vmscan.h> -struct cgroup_subsys memory_cgrp_subsys__read_mostly ;EXPORT_SYMBOL (memory_cgrp_subsys);Acked-by Muchun Song <[email protected]>Thanks.
Signature · 2 lines
Best regards Ridong
RFC PATCH v2 2/7 mm/vmscan: move vmscan tracepoints to a local header
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
Move include/trace/events/vmscan.h to mm/trace_vmscan.h so that the tracepoints can be extended to reference vmscan-internal structures such as struct scan_control, which is not visible outside mm/. This mirrors what several other subsystems already do with their trace headers (e.g. fs/ext2, kernel/trace/trace_benchmark).
No functional change.
--- MAINTAINERS | 2 ++ mm/shrinker.c | 2 +- include/trace/events/vmscan.h => mm/trace_vmscan.h | 4 ++++ mm/vmscan.c | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) rename include/trace/events/vmscan.h => mm/trace_vmscan.h (99%)
MAINTAINERS +2 -0
@@ -17229,6 +17229,7 @@ F: Documentation/admin-guide/mm/multigen_lru.rst F: Documentation/mm/multigen_lru.rst F: include/linux/mm_inline.h F: include/linux/mmzone.h +F: mm/trace_vmscan.h F: mm/vmscan.c F: mm/workingset.c
@@ -17376,6 +17377,7 @@ R: Shakeel Butt <[email protected]> R: Lorenzo Stoakes <[email protected]> L: [email protected] S: Maintained +F: mm/trace_vmscan.h F: mm/vmscan.c F: mm/workingset.c
mm/shrinker.c +1 -1
@@ -3,7 +3,7 @@#include <linux/rwsem.h> #include <linux/shrinker.h> #include <linux/rculist.h> -#include <trace/events/vmscan.h> +#include "trace_vmscan.h" #include "internal.h"
mm/trace_vmscan.h renamed from include/trace/events/vmscan.h +4 -0
@@ -648,4 +648,8 @@ TRACE_EVENT(mm_vmscan_kswapd_clear_hopeless,#endif /* _TRACE_VMSCAN_H */ /* This part must be outside protection */ +#undef TRACE_INCLUDE_FILE +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH ../../mm +#define TRACE_INCLUDE_FILE trace_vmscan#include <trace/define_trace.h>
mm/vmscan.c +1 -1
@@ -71,7 +71,7 @@#include "swap.h" #define CREATE_TRACE_POINTS -#include <trace/events/vmscan.h> +#include "trace_vmscan.h" struct scan_control {/* How many pages shrink_list() should reclaim */
Signature · 1 line
2.34.1
RFC PATCH v2 3/7 mm/vmscan: move struct scan_control to a dedicated header
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
The definition of struct scan_control has lived inline at the top of mm/vmscan.c. Move it out to a new mm/vmscan.h so the reclaim-internal state can be referenced from other reclaim translation units without duplicating the definition.
The header uses an ordinary include guard and pulls in only what the struct needs (nodemask_t, gfp_t and struct reclaim_state).
mm/trace_vmscan.h includes the new header directly so that any translation unit pulling in the trace events (mm/vmscan.c, mm/shrinker.c) sees the full definition of struct scan_control regardless of include order.
No functional change.
--- MAINTAINERS | 2 + mm/trace_vmscan.h | 2 + mm/vmscan.c | 108 ------------------------------------------ mm/vmscan.h | 118 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 108 deletions(-) create mode 100644 mm/vmscan.h
MAINTAINERS +2 -0
@@ -17231,6 +17231,7 @@ F: include/linux/mm_inline.h F: include/linux/mmzone.h F: mm/trace_vmscan.h F: mm/vmscan.c +F: mm/vmscan.h F: mm/workingset.c MEMORY MANAGEMENT - MIGRATION
@@ -17379,6 +17380,7 @@ L: [email protected] S: Maintained F: mm/trace_vmscan.h F: mm/vmscan.c +F: mm/vmscan.h F: mm/workingset.c MEMORY MANAGEMENT - RMAP (REVERSE MAPPING)
mm/trace_vmscan.h +2 -0
@@ -11,6 +11,8 @@#include <linux/memcontrol.h> #include <trace/events/mmflags.h> +#include "vmscan.h" +#define RECLAIM_WB_ANON 0x0001u#define RECLAIM_WB_FILE 0x0002u#define RECLAIM_WB_MIXED 0x0010u
mm/vmscan.c +0 -108
114 lines not on this page · raw message
mm/vmscan.h new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.34.1
RFC PATCH v2 4/7 mm/vmscan: pass scan_control to the reclaim-begin tracepoints
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
The reclaim-begin tracepoints describe the entry conditions of a reclaim invocation, which struct scan_control already carries. Now that the struct is visible from the trace header, pass sc directly and pick the fields out in TP_fast_assign instead of spelling out gfp_mask and order at every callsite. The exported event format is unchanged.
No functional change.
--- mm/trace_vmscan.h | 24 ++++++++++++------------ mm/vmscan.c | 7 +++---- 2 files changed, 15 insertions(+), 16 deletions(-)
mm/trace_vmscan.h +12 -12
@@ -178,9 +178,9 @@ TRACE_EVENT(mm_vmscan_wakeup_kswapd, DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_begin_template, - TP_PROTO(gfp_t gfp_flags, int order, struct mem_cgroup *memcg), + TP_PROTO(struct scan_control *sc, struct mem_cgroup *memcg), - TP_ARGS(gfp_flags, order, memcg), + TP_ARGS(sc, memcg), TP_STRUCT__entry( __field( unsigned long, gfp_flags )
@@ -189,8 +189,8 @@ DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_begin_template, ),TP_fast_assign ( - __entry->gfp_flags = (__force unsigned long)gfp_flags; - __entry->order = order; + __entry->gfp_flags = (__force unsigned long)sc->gfp_mask; + __entry->order = sc->order; __entry->memcg_id =mem_cgroup_id (memcg); ),
@@ -204,17 +204,17 @@ DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_begin_template,DEFINE_EVENT (mm_vmscan_direct_reclaim_begin_template, mm_vmscan_direct_reclaim_begin, - TP_PROTO(gfp_t gfp_flags, int order, struct mem_cgroup *memcg), + TP_PROTO(struct scan_control *sc, struct mem_cgroup *memcg), -TP_ARGS (gfp_flags, order, memcg) +TP_ARGS (sc, memcg) );#ifdef CONFIG_MEMCG DEFINE_EVENT (mm_vmscan_direct_reclaim_begin_template, mm_vmscan_memcg_reclaim_begin, - TP_PROTO(gfp_t gfp_flags, int order, struct mem_cgroup *memcg), + TP_PROTO(struct scan_control *sc, struct mem_cgroup *memcg), -TP_ARGS (gfp_flags, order, memcg) +TP_ARGS (sc, memcg) );#endif /* CONFIG_MEMCG */
@@ -551,9 +551,9 @@ TRACE_EVENT(mm_vmscan_lru_shrink_active, TRACE_EVENT(mm_vmscan_node_reclaim_begin, - TP_PROTO(int nid, int order, gfp_t gfp_flags), + TP_PROTO(int nid, struct scan_control *sc), - TP_ARGS(nid, order, gfp_flags), + TP_ARGS(nid, sc), TP_STRUCT__entry( __field(int, nid)
@@ -563,8 +563,8 @@ TRACE_EVENT(mm_vmscan_node_reclaim_begin,TP_fast_assign ( __entry->nid = nid; - __entry->order = order; - __entry->gfp_flags = (__force unsigned long )gfp_flags; + __entry->order = sc->order; + __entry->gfp_flags = (__force unsigned long )sc->gfp_mask; ), TP_printk("nid=%d order=%d gfp_flags=%s",
mm/vmscan.c +3 -4
@@ -6885,7 +6885,7 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,return 1 ;set_task_reclaim_state (current, &sc.reclaim_state); -trace_mm_vmscan_direct_reclaim_begin (sc.gfp_mask, order,NULL ); +trace_mm_vmscan_direct_reclaim_begin (&sc,NULL ); nr_reclaimed =do_try_to_free_pages (zonelist, &sc);
@@ -6926,7 +6926,7 @@ unsigned long try_to_free_mem_cgroup_pages(struct mem_cgroup *memcg,struct zonelist *zonelist =node_zonelist (numa_node_id (), sc.gfp_mask);set_task_reclaim_state (current, &sc.reclaim_state); -trace_mm_vmscan_memcg_reclaim_begin (sc.gfp_mask,0 , memcg); +trace_mm_vmscan_memcg_reclaim_begin (&sc, memcg); noreclaim_flag =memalloc_noreclaim_save (); nr_reclaimed =do_try_to_free_pages (zonelist, &sc);
@@ -7882,8 +7882,7 @@ static unsigned long __node_reclaim(struct pglist_data *pgdat,unsigned int noreclaim_flag;unsigned long pflags; -trace_mm_vmscan_node_reclaim_begin (pgdat->node_id, sc->order, - sc->gfp_mask); +trace_mm_vmscan_node_reclaim_begin (pgdat->node_id, sc);cond_resched ();psi_memstall_enter (&pflags);
Signature · 1 line
2.34.1
RFC PATCH v2 5/7 mm/vmscan: pass scan_control to the LRU isolate/shrink tracepoints
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
mm_vmscan_lru_isolate, mm_vmscan_lru_shrink_inactive and mm_vmscan_lru_shrink_active spell out reclaim state (reclaim_idx, order, priority) as individual arguments, all of which the caller already holds in struct scan_control. Now that the struct is visible from the trace header, pass sc directly and pick the fields out in TP_fast_assign.
The exported event format is unchanged.
No functional change.
--- mm/trace_vmscan.h | 31 +++++++++++++++---------------- mm/vmscan.c | 14 +++++++------- 2 files changed, 22 insertions(+), 23 deletions(-)
mm/trace_vmscan.h +15 -16
@@ -350,15 +350,14 @@ TRACE_EVENT(mm_shrink_slab_end, ); TRACE_EVENT(mm_vmscan_lru_isolate, - TP_PROTO(int highest_zoneidx, - int order, - unsigned long nr_requested, - unsigned long nr_scanned, - unsigned long nr_skipped, - unsigned long nr_taken, - int lru), + TP_PROTO(struct scan_control *sc, + unsigned long nr_requested, + unsigned long nr_scanned, + unsigned long nr_skipped, + unsigned long nr_taken, + int lru), - TP_ARGS(highest_zoneidx, order, nr_requested, nr_scanned, nr_skipped, nr_taken, lru), + TP_ARGS(sc, nr_requested, nr_scanned, nr_skipped, nr_taken, lru), TP_STRUCT__entry( __field(int, highest_zoneidx)
@@ -371,8 +370,8 @@ TRACE_EVENT(mm_vmscan_lru_isolate, ), TP_fast_assign( - __entry->highest_zoneidx = highest_zoneidx; - __entry->order = order; + __entry->highest_zoneidx = sc->reclaim_idx; + __entry->order = sc->order; __entry->nr_requested = nr_requested; __entry->nr_scanned = nr_scanned; __entry->nr_skipped = nr_skipped;
@@ -466,9 +465,9 @@ TRACE_EVENT(mm_vmscan_lru_shrink_inactive, TP_PROTO(int nid, unsigned long nr_scanned, unsigned long nr_reclaimed, - struct reclaim_stat *stat, int priority, int file), + struct reclaim_stat *stat, struct scan_control *sc, int file), -TP_ARGS (nid, nr_scanned, nr_reclaimed, stat, priority, file), +TP_ARGS (nid, nr_scanned, nr_reclaimed, stat, sc, file),TP_STRUCT__entry ( __field(int, nid)
@@ -498,7 +497,7 @@ TRACE_EVENT(mm_vmscan_lru_shrink_inactive, __entry->nr_activate1 = stat->nr_activate[1 ]; __entry->nr_ref_keep = stat->nr_ref_keep; __entry->nr_unmap_fail = stat->nr_unmap_fail; - __entry->priority = priority; + __entry->priority = sc->priority; __entry->reclaim_flags =trace_reclaim_flags (file); ),
@@ -517,9 +516,9 @@ TRACE_EVENT(mm_vmscan_lru_shrink_active, TP_PROTO(int nid, unsigned long nr_taken, unsigned long nr_active, unsigned long nr_deactivated, - unsigned long nr_referenced, int priority, int file), + unsigned long nr_referenced, struct scan_control *sc, int file), -TP_ARGS (nid, nr_taken, nr_active, nr_deactivated, nr_referenced, priority, file), +TP_ARGS (nid, nr_taken, nr_active, nr_deactivated, nr_referenced, sc, file),TP_STRUCT__entry ( __field(int, nid)
@@ -537,7 +536,7 @@ TRACE_EVENT(mm_vmscan_lru_shrink_active, __entry->nr_active = nr_active; __entry->nr_deactivated = nr_deactivated; __entry->nr_referenced = nr_referenced; - __entry->priority = priority; + __entry->priority = sc->priority; __entry->reclaim_flags =trace_reclaim_flags (file); ),
mm/vmscan.c +7 -7
@@ -1764,7 +1764,7 @@ static unsigned long isolate_lru_folios(unsigned long nr_to_scan, } } *nr_scanned = total_scan; -trace_mm_vmscan_lru_isolate (sc->reclaim_idx, sc->order, nr_to_scan, +trace_mm_vmscan_lru_isolate (sc, nr_to_scan, total_scan, skipped, nr_taken, lru);update_lru_sizes (lruvec, lru, nr_zone_taken);return nr_taken;
@@ -2053,7 +2053,7 @@ static unsigned long shrink_inactive_list(unsigned long nr_to_scan,handle_reclaim_writeback (nr_taken, pgdat, sc, &stat);trace_mm_vmscan_lru_shrink_inactive (pgdat->node_id, - nr_scanned, nr_reclaimed, &stat, sc->priority, file); + nr_scanned, nr_reclaimed, &stat, sc, file);return nr_reclaimed; }
@@ -2160,7 +2160,7 @@ static void shrink_active_list(unsigned long nr_to_scan,mod_lruvec_state (lruvec,PGROTATE_ANON + file, nr_rotated);trace_mm_vmscan_lru_shrink_active (pgdat->node_id, nr_taken, nr_activate, - nr_deactivate, nr_rotated, sc->priority, file); + nr_deactivate, nr_rotated, sc, file); } static unsigned int reclaim_folio_list(struct list_head *folio_list,
@@ -4850,9 +4850,9 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,mod_lruvec_state (lruvec, item, isolated);mod_lruvec_state (lruvec,PGREFILL , sorted);mod_lruvec_state (lruvec,PGSCAN_ANON + type, isolated); -trace_mm_vmscan_lru_isolate (sc->reclaim_idx, sc->order, nr_to_scan, - scanned, skipped, isolated, - type ?LRU_INACTIVE_FILE :LRU_INACTIVE_ANON ); +trace_mm_vmscan_lru_isolate (sc, nr_to_scan, + scanned, skipped, isolated, + type ?LRU_INACTIVE_FILE :LRU_INACTIVE_ANON ); *isolatedp = isolated;return scanned;
@@ -4991,7 +4991,7 @@ static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec,if (isolated)handle_reclaim_writeback (isolated, pgdat, sc, &stat);trace_mm_vmscan_lru_shrink_inactive (pgdat->node_id, - type_scanned, reclaimed, &stat, sc->priority, + type_scanned, reclaimed, &stat, sc, type ?LRU_INACTIVE_FILE :LRU_INACTIVE_ANON );list_for_each_entry_safe_reverse (folio, next, &list, lru) {
Signature · 1 line
2.34.1
RFC PATCH v2 6/7 mm/vmscan: pass scan_control to mm_vmscan_reclaim_pages
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
reclaim_folio_list() passes sc.nr_scanned to mm_vmscan_reclaim_pages as a bare argument. Pass the enclosing struct scan_control instead and read nr_scanned out in TP_fast_assign, consistent with the other reclaim tracepoints. nr_reclaimed stays a separate argument as it is the return value of shrink_folio_list() rather than a scan_control field.
The exported event format is unchanged.
No functional change.
--- mm/trace_vmscan.h | 10 +++++----- mm/vmscan.c | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-)
mm/trace_vmscan.h +5 -5
@@ -418,11 +418,11 @@ TRACE_EVENT(mm_vmscan_write_folio, TRACE_EVENT(mm_vmscan_reclaim_pages, - TP_PROTO(int nid, - unsigned long nr_scanned, unsigned long nr_reclaimed, - struct reclaim_stat *stat), + TP_PROTO(int nid, struct scan_control *sc, + unsigned long nr_reclaimed, + struct reclaim_stat *stat), - TP_ARGS(nid, nr_scanned, nr_reclaimed, stat), + TP_ARGS(nid, sc, nr_reclaimed, stat), TP_STRUCT__entry( __field(int, nid)
@@ -440,7 +440,7 @@ TRACE_EVENT(mm_vmscan_reclaim_pages,TP_fast_assign ( __entry->nid = nid; - __entry->nr_scanned = nr_scanned; + __entry->nr_scanned = sc->nr_scanned; __entry->nr_reclaimed = nr_reclaimed; __entry->nr_dirty = stat->nr_dirty; __entry->nr_writeback = stat->nr_writeback;
mm/vmscan.c +1 -1
@@ -2183,7 +2183,7 @@ static unsigned int reclaim_folio_list(struct list_head *folio_list,list_del (&folio->lru);folio_putback_lru (folio); } -trace_mm_vmscan_reclaim_pages (pgdat->node_id, sc.nr_scanned, nr_reclaimed, &stat); +trace_mm_vmscan_reclaim_pages (pgdat->node_id, &sc, nr_reclaimed, &stat);return nr_reclaimed; }
Signature · 1 line
2.34.1
RFC PATCH v2 7/7 mm/vmscan: pass scan_control to mm_vmscan_balance_pgdat_end
In reply to Ridong ChenFrom: Ridong Chen <[email protected]>
balance_pgdat() passes sc.order and sc.nr_reclaimed to mm_vmscan_balance_pgdat_end as bare arguments. Pass the enclosing struct scan_control instead and read the fields out in TP_fast_assign, mirroring mm_vmscan_balance_pgdat_begin. highest_zoneidx stays a separate argument as it is a local of balance_pgdat() rather than a scan_control field.
The exported event format is unchanged.
No functional change.
--- mm/trace_vmscan.h | 9 ++++----- mm/vmscan.c | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-)
mm/trace_vmscan.h +4 -5
@@ -124,10 +124,9 @@ TRACE_EVENT(mm_vmscan_balance_pgdat_begin, TRACE_EVENT(mm_vmscan_balance_pgdat_end, - TP_PROTO(int nid, int order, int highest_zoneidx, - unsigned long nr_reclaimed), + TP_PROTO(int nid, struct scan_control *sc, int highest_zoneidx), - TP_ARGS(nid, order, highest_zoneidx, nr_reclaimed), + TP_ARGS(nid, sc, highest_zoneidx), TP_STRUCT__entry( __field(int, nid)
@@ -138,9 +137,9 @@ TRACE_EVENT(mm_vmscan_balance_pgdat_end,TP_fast_assign ( __entry->nid = nid; - __entry->order = order; + __entry->order = sc->order; __entry->highest_zoneidx = highest_zoneidx; - __entry->nr_reclaimed = nr_reclaimed; + __entry->nr_reclaimed = sc->nr_reclaimed; ), TP_printk("nid=%d order=%d highest_zoneidx=%-8s nr_reclaimed=%lu",
mm/vmscan.c +1 -2
@@ -7403,8 +7403,7 @@ static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)psi_memstall_leave (&pflags);set_task_reclaim_state (current,NULL ); -trace_mm_vmscan_balance_pgdat_end (pgdat->node_id, sc.order, - highest_zoneidx, sc.nr_reclaimed); +trace_mm_vmscan_balance_pgdat_end (pgdat->node_id, &sc, highest_zoneidx);/* * Return the order kswapd stopped reclaiming at as
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH RFC v2 7/7] mm/vmscan: pass scan_control to mm_vmscan_balance_pgdat_end
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] mm: BPF raw tracepoint ABI breakage and commit message mismatch in mm_vmscan_balance_pgdat_end --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: BPF raw tracepoint ABI breakage and commit message mismatch in mm_vmscan_balance_pgdat_end --
commit eb8bc6091aab714af4b68f316fecfc08d43c39dc
Author: Ridong Chen <[email protected]>
mm/vmscan: pass scan_control to mm_vmscan_balance_pgdat_end
This commit updates the mm_vmscan_balance_pgdat_end tracepoint to receive a struct scan_control pointer rather than passing individual struct fields. It updates the TP_PROTO and TP_ARGS while leaving the exported event format unchanged.
Quoted 4 lines
balance_pgdat()passes sc.order and sc.nr_reclaimed tomm_vmscan_balance_pgdat_endas bare arguments. Pass the enclosing structscan_controlinstead and read the fields out inTP_fast_assign, mirroringmm_vmscan_balance_pgdat_begin.highest_zoneidxstays a
[Severity: Medium]
The commit message states this change is "mirroring mm_vmscan_balance_pgdat_begin." Is this description accurate?
Looking at mm_vmscan_balance_pgdat_begin in mm/trace_vmscan.h, it still takes individual arguments and was not updated to take struct scan_control *sc:
TRACE_EVENT(mm_vmscan_balance_pgdat_begin,
TP_PROTO(int nid, int order, int highest_zoneidx),
Could the commit message be more precise about the rationale?
Quoted 4 lines
mm/trace_vmscan.h +0
-0
[ ... ]
mm/trace_vmscan.h TRACE_EVENT(mm_vmscan_balance_pgdat_begin, · line 129
Quoted 10 lines
mm/trace_vmscan.h +2
-3@@ -124,10 +124,9 @@ TRACE_EVENT(mm_vmscan_balance_pgdat_begin, TRACE_EVENT(mm_vmscan_balance_pgdat_end, - TP_PROTO(int nid, int order, int highest_zoneidx, - unsigned long nr_reclaimed), + TP_PROTO(int nid, struct scan_control *sc, int highest_zoneidx), - TP_ARGS(nid, order, highest_zoneidx, nr_reclaimed), + TP_ARGS(nid, sc, highest_zoneidx),
[Severity: Medium]
The commit message mentions there is "No functional change", but could this modification break existing BPF programs hooked to this tracepoint?
While standard trace events parse the formatted output, BPF raw tracepoints consume the TP_PROTO arguments directly via ctx->args. Changing the number and type of arguments alters the BPF raw tracepoint ABI for this event.
Does this inadvertently break user space tools that attach to this raw tracepoint and expect the 4 original arguments?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH RFC v2 7/7] mm/vmscan: pass scan_control to mm_vmscan_balance_pgdat_end
Quoted 23 lines · On 9/28/2026 7:58 PM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm: BPF raw tracepoint ABI breakage and commit message mismatch inmm_vmscan_balance_pgdat_end--commit
eb8bc6091aab714af4b68f316fecfc08d43c39dc
Author: Ridong Chen <[email protected]>mm/vmscan: pass
scan_controltomm_vmscan_balance_pgdat_endThis commit updates the
mm_vmscan_balance_pgdat_endtracepoint to receive a structscan_controlpointer rather than passing individual struct fields. It updates theTP_PROTOandTP_ARGSwhile leaving the exported event format unchanged.Quoted 4 lines
balance_pgdat()passes sc.order and sc.nr_reclaimed tomm_vmscan_balance_pgdat_endas bare arguments. Pass the enclosing structscan_controlinstead and read the fields out inTP_fast_assign, mirroringmm_vmscan_balance_pgdat_begin.highest_zoneidxstays a[Severity: Medium]
The commit message states this change is "mirroringmm_vmscan_balance_pgdat_begin." Is this description accurate?
Quoted 8 lines
Looking at
mm_vmscan_balance_pgdat_begininmm/trace_vmscan.h, it still takes individual arguments and was not updated to take structscan_control*sc:TRACE_EVENT(mm_vmscan_balance_pgdat_begin,
TP_PROTO(int nid, int order, int highest_zoneidx),Could the commit message be more precise about the rationale?
You're right, that wording is misleading and I'll fix it in next version.
I just mixed it up with other xxx_begin tracepoints.
Quoted 20 lines
Quoted 4 lines
mm/trace_vmscan.h +0
-0[ ... ]
mm/trace_vmscan.h TRACE_EVENT(mm_vmscan_balance_pgdat_begin, · line 129
Quoted 10 lines
mm/trace_vmscan.h +2
-3@@ -124,10 +124,9 @@ TRACE_EVENT(mm_vmscan_balance_pgdat_begin, TRACE_EVENT(mm_vmscan_balance_pgdat_end, - TP_PROTO(int nid, int order, int highest_zoneidx, - unsigned long nr_reclaimed), + TP_PROTO(int nid, struct scan_control *sc, int highest_zoneidx), - TP_ARGS(nid, order, highest_zoneidx, nr_reclaimed), + TP_ARGS(nid, sc, highest_zoneidx),[Severity: Medium]
The commit message mentions there is "No functional change", but could this modification break existing BPF programs hooked to this tracepoint?
Quoted 7 lines
While standard trace events parse the formatted output, BPF raw tracepoints consume the
TP_PROTOarguments directly viactx->args. Changing the number and type of arguments alters the BPF raw tracepoint ABI for this event.Does this inadvertently break user space tools that attach to this raw tracepoint and expect the 4 original arguments?
Thanks, "No functional change" is inaccurate here.
Kernel behaviour and the tracefs format are unchanged (TP_STRUCT__entry / TP_printk are untouched), so perf / trace-cmd / libbpf CO-RE consumers are unaffected. But for BPF raw tracepoints the arg layout does change: a program reading the old args[3] (nr_reclaimed) now has to read it out of sc. I shouldn't have hidden that under "no functional change".
Raw tracepoints aren't a stable ABI though (Documentation/bpf/bpf_design_QA.rst), so the change itself is fine — I'll just fix the commit message in next version.
Signature · 2 lines
Best regards Ridong