From 8f858585f05162431a7e5f26f1bf4ef25048fb27 Mon Sep 17 00:00:00 2001 From: Sooyong Suk Date: Wed, 10 Jul 2024 14:31:36 +0900 Subject: [PATCH] ANDROID: mm: add vendor hook for __alloc_pages_slowpath() Add vendor hooks in __alloc_pages_slowpath() to print debug logs on allocation delay. trace_android_vh_alloc_pages_slowpath() already exists but new vendor hooks are needed for more information. This also merges change in https://android-review.googlesource.com/c/kernel/common/+/2897503. Bug: 351175506 Change-Id: If04c64dc436b0874a06f1a0a96cde918e96c1bb2 Signed-off-by: Sooyong Suk --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/mm.h | 9 +++++++++ mm/page_alloc.c | 11 ++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 33a6dd5dc0d4..343136dc2e65 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -305,3 +305,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_smaps_pte_entry); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_smap); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rebalance_anon_lru_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_trigger_vendor_lmk_kill); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_slowpath_start); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_slowpath_end); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index f8e97c6836da..901246d875da 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -188,6 +188,15 @@ DECLARE_HOOK(android_vh_show_smap, unsigned long swap_shared, unsigned long writeback, unsigned long same, unsigned long huge), TP_ARGS(m, swap_shared, writeback, same, huge)); +DECLARE_HOOK(android_vh_alloc_pages_slowpath_start, + TP_PROTO(u64 *stime), + TP_ARGS(stime)); +DECLARE_HOOK(android_vh_alloc_pages_slowpath_end, + TP_PROTO(gfp_t *gfp_mask, unsigned int order, unsigned long alloc_start, + u64 stime, unsigned long did_some_progress, + unsigned long pages_reclaimed, int retry_loop_count), + TP_ARGS(gfp_mask, order, alloc_start, stime, did_some_progress, + pages_reclaimed, retry_loop_count)); #endif /* _TRACE_HOOK_MM_H */ /* This part must be outside protection */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index fc3c38b72fde..5bbc9f5c13ca 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4359,7 +4359,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER; struct page *page = NULL; unsigned int alloc_flags; - unsigned long did_some_progress; + unsigned long did_some_progress = 0; enum compact_priority compact_priority; enum compact_result compact_result; int compaction_retries; @@ -4367,6 +4367,10 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, unsigned int cpuset_mems_cookie; unsigned int zonelist_iter_cookie; int reserve_flags; + unsigned long alloc_start = jiffies; + unsigned long pages_reclaimed = 0; + int retry_loop_count = 0; + u64 stime = 0; if (unlikely(nofail)) { /* @@ -4386,6 +4390,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, */ WARN_ON_ONCE(current->flags & PF_MEMALLOC); } + trace_android_vh_alloc_pages_slowpath_start(&stime); restart: compaction_retries = 0; @@ -4492,6 +4497,7 @@ restart: } retry: + retry_loop_count++; /* Ensure kswapd doesn't accidentally go to sleep as long as we loop */ if (alloc_flags & ALLOC_KSWAPD) wake_all_kswapds(order, gfp_mask, ac); @@ -4528,6 +4534,7 @@ retry: /* Try direct reclaim and then allocating */ page = __alloc_pages_direct_reclaim(gfp_mask, order, alloc_flags, ac, &did_some_progress); + pages_reclaimed += did_some_progress; if (page) goto got_pg; @@ -4631,6 +4638,8 @@ fail: warn_alloc(gfp_mask, ac->nodemask, "page allocation failure: order:%u", order); got_pg: + trace_android_vh_alloc_pages_slowpath_end(&gfp_mask, order, alloc_start, + stime, did_some_progress, pages_reclaimed, retry_loop_count); return page; }