From 6e881bf0341859e40dc04203f3597769e1de53ac Mon Sep 17 00:00:00 2001 From: Haonan Wang Date: Tue, 26 Sep 2023 19:40:57 +0800 Subject: [PATCH] ANDROID: vendor_hooks: mm: add hook to count the number pages allocated for each slab We want to add an interface that can detect the number of pages allocated by the slab, and if exceeds a threshold, trigger a panic or other actions. Bug: 302090264 Change-Id: I8fcae6a97046806376b95b66085dd5b852c2d1e8 Signed-off-by: Haonan Wang --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 3 +++ mm/slub.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f34fa39c84e6..71a349221f3f 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -362,3 +362,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_early_resume_begin); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_filemap_get_folio); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmc_blk_mq_rw_recovery); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_sd_update_bus_speed_mode); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_folio_alloced); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 00f50548a20f..6b9353695660 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -196,6 +196,9 @@ DECLARE_HOOK(android_vh_mm_alloc_pages_may_oom_exit, DECLARE_HOOK(android_vh_adjust_kvmalloc_flags, TP_PROTO(unsigned int order, gfp_t *alloc_flags), TP_ARGS(order, alloc_flags)); +DECLARE_HOOK(android_vh_slab_folio_alloced, + TP_PROTO(unsigned int order, gfp_t flags), + TP_ARGS(order, flags)); #endif /* _TRACE_HOOK_MM_H */ /* This part must be outside protection */ diff --git a/mm/slub.c b/mm/slub.c index 3c9d4e333963..32c73002a5c5 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -43,6 +43,7 @@ #include #include +#include #include "internal.h" @@ -1823,6 +1824,8 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node, if (page_is_pfmemalloc(folio_page(folio, 0))) slab_set_pfmemalloc(slab); + trace_android_vh_slab_folio_alloced(order, flags); + return slab; }