From 784f566942e0fb43b349c53762162e9ef5651a97 Mon Sep 17 00:00:00 2001 From: Dezhi Huang Date: Fri, 19 May 2023 09:58:01 +0800 Subject: [PATCH] ANDROID: mm: create vendor hooks for page alloc Add vendor hook inside of get_page_from_freelist() to check and modify the watermark in some special situations. Additional page flag bit will be set for future identification. Separately, a vendor hook inside of page_add_new_anon_rmap() is added to set the referenced bit in some situations, e.g. if the special bit in the page flag mentioned before is set, we will give this page one more chance before it gets reclaimed. Bug: 279793368 Change-Id: I363853a050a87201f6f368ccc580485dddd6c6b6 Signed-off-by: Dezhi Huang --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/mm.h | 7 +++++++ mm/page_alloc.c | 4 ++++ mm/rmap.c | 1 + 4 files changed, 14 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 35c6846bf96b..686e77d67f3c 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -239,6 +239,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_reply); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_trans); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mmap_region); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_try_to_unmap_one); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_get_page_wmark); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_page_add_new_anon_rmap); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_event); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_psi_group); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cpufreq_acct_update_power); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 27b9a53e0667..df186e55a5b9 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -30,6 +30,13 @@ DECLARE_HOOK(android_vh_try_to_unmap_one, TP_PROTO(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, void *arg, bool ret), TP_ARGS(folio, vma, addr, arg, ret)); +DECLARE_HOOK(android_vh_get_page_wmark, + TP_PROTO(unsigned int alloc_flags, unsigned long *page_wmark), + TP_ARGS(alloc_flags, page_wmark)); +DECLARE_HOOK(android_vh_page_add_new_anon_rmap, + TP_PROTO(struct page *page, struct vm_area_struct *vma, + unsigned long address), + TP_ARGS(page, vma, address)); #endif /* _TRACE_HOOK_MM_H */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f0cfac80ca10..7675d1c2d813 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -84,6 +84,9 @@ #include "page_reporting.h" #include "swap.h" +#undef CREATE_TRACE_POINTS +#include + /* Free Page Internal flags: for internal, non-pcp variants of free_pages(). */ typedef int __bitwise fpi_t; @@ -4319,6 +4322,7 @@ retry: } mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK); + trace_android_vh_get_page_wmark(alloc_flags, &mark); if (!zone_watermark_fast(zone, order, mark, ac->highest_zoneidx, alloc_flags, gfp_mask)) { diff --git a/mm/rmap.c b/mm/rmap.c index 2adcc921d96d..a437a1d515b0 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1270,6 +1270,7 @@ void page_add_new_anon_rmap(struct page *page, } __mod_lruvec_page_state(page, NR_ANON_MAPPED, nr); __page_set_anon_rmap(page, vma, address, 1); + trace_android_vh_page_add_new_anon_rmap(page, vma, address); } /**