The patch titled Subject: mm: memcg: introduce new event to trace shrink_memcg has been added to the -mm mm-unstable branch. Its filename is mm-memcg-introduce-new-event-to-trace-shrink_memcg.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memcg-introduce-new-event-to-trace-shrink_memcg.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Dmitry Rokosov <ddrokosov@xxxxxxxxxxxxxxxxx> Subject: mm: memcg: introduce new event to trace shrink_memcg Date: Thu, 23 Nov 2023 22:39:37 +0300 The shrink_memcg flow plays a crucial role in memcg reclamation. Currently, it is not possible to trace this point from non-direct reclaim paths. However, direct reclaim has its own tracepoint, so there is no issue there. In certain cases, when debugging memcg pressure, developers may need to identify all potential requests for memcg reclamation including kswapd(). The patchset introduces the tracepoints mm_vmscan_memcg_shrink_{begin|end}() to address this problem. Example of output in the kswapd context (non-direct reclaim): kswapd0-39 [001] ..... 240.356378: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.356396: mm_vmscan_memcg_shrink_end: nr_reclaimed=0 memcg=16 kswapd0-39 [001] ..... 240.356420: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.356454: mm_vmscan_memcg_shrink_end: nr_reclaimed=1 memcg=16 kswapd0-39 [001] ..... 240.356479: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.356506: mm_vmscan_memcg_shrink_end: nr_reclaimed=4 memcg=16 kswapd0-39 [001] ..... 240.356525: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.356593: mm_vmscan_memcg_shrink_end: nr_reclaimed=11 memcg=16 kswapd0-39 [001] ..... 240.356614: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.356738: mm_vmscan_memcg_shrink_end: nr_reclaimed=25 memcg=16 kswapd0-39 [001] ..... 240.356790: mm_vmscan_memcg_shrink_begin: order=0 gfp_flags=GFP_KERNEL memcg=16 kswapd0-39 [001] ..... 240.357125: mm_vmscan_memcg_shrink_end: nr_reclaimed=53 memcg=16 Link: https://lkml.kernel.org/r/20231123193937.11628-3-ddrokosov@xxxxxxxxxxxxxxxxx Signed-off-by: Dmitry Rokosov <ddrokosov@xxxxxxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Masami Hiramatsu (Google) <mhiramat@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxx> Cc: Muchun Song <muchun.song@xxxxxxxxx> Cc: Roman Gushchin <roman.gushchin@xxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Cc: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/trace/events/vmscan.h | 22 ++++++++++++++++++++++ mm/vmscan.c | 7 +++++++ 2 files changed, 29 insertions(+) --- a/include/trace/events/vmscan.h~mm-memcg-introduce-new-event-to-trace-shrink_memcg +++ a/include/trace/events/vmscan.h @@ -180,6 +180,17 @@ DEFINE_EVENT(mm_vmscan_memcg_reclaim_beg TP_ARGS(order, gfp_flags, memcg) ); +DEFINE_EVENT(mm_vmscan_memcg_reclaim_begin_template, mm_vmscan_memcg_shrink_begin, + + TP_PROTO(int order, gfp_t gfp_flags, const struct mem_cgroup *memcg), + + TP_ARGS(order, gfp_flags, memcg) +); + +#else + +#define trace_mm_vmscan_memcg_shrink_begin(...) + #endif /* CONFIG_MEMCG */ DECLARE_EVENT_CLASS(mm_vmscan_direct_reclaim_end_template, @@ -243,6 +254,17 @@ DEFINE_EVENT(mm_vmscan_memcg_reclaim_end TP_ARGS(nr_reclaimed, memcg) ); +DEFINE_EVENT(mm_vmscan_memcg_reclaim_end_template, mm_vmscan_memcg_shrink_end, + + TP_PROTO(unsigned long nr_reclaimed, const struct mem_cgroup *memcg), + + TP_ARGS(nr_reclaimed, memcg) +); + +#else + +#define trace_mm_vmscan_memcg_shrink_end(...) + #endif /* CONFIG_MEMCG */ TRACE_EVENT(mm_shrink_slab_start, --- a/mm/vmscan.c~mm-memcg-introduce-new-event-to-trace-shrink_memcg +++ a/mm/vmscan.c @@ -5788,6 +5788,10 @@ static void shrink_node_memcgs(pg_data_t */ cond_resched(); + trace_mm_vmscan_memcg_shrink_begin(sc->order, + sc->gfp_mask, + memcg); + mem_cgroup_calculate_protection(target_memcg, memcg); if (mem_cgroup_below_min(target_memcg, memcg)) { @@ -5818,6 +5822,9 @@ static void shrink_node_memcgs(pg_data_t shrink_slab(sc->gfp_mask, pgdat->node_id, memcg, sc->priority); + trace_mm_vmscan_memcg_shrink_end(sc->nr_reclaimed - reclaimed, + memcg); + /* Record the group's reclaim efficiency */ if (!sc->proactive) vmpressure(sc->gfp_mask, memcg, false, _ Patches currently in -mm which might be from ddrokosov@xxxxxxxxxxxxxxxxx are mm-memcg-print-out-cgroup-ino-in-the-memcg-tracepoints.patch mm-memcg-introduce-new-event-to-trace-shrink_memcg.patch