From 3b58573735e1d2f2c3eff856ed4c596f4d52a61d 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 Bug: 336900791 Change-Id: I363853a050a87201f6f368ccc580485dddd6c6b6 Signed-off-by: Dezhi Huang Signed-off-by: huzhanyuan (cherry picked from commit 49fa9c5a7e11922caa132a0d014b46b7a72f10d3) --- 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 fcd653650197..8551fb9adc69 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -224,6 +224,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_special_task); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_buffer_release); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_mglru_should_abort_scan); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_shrink_slab); +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_check_folio_look_around_ref); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_look_around); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_look_around_migrate_folio); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 81b5daac494c..8cb47aa66b0a 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -199,6 +199,13 @@ 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_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)); DECLARE_HOOK(android_vh_alloc_pages_slowpath_start, TP_PROTO(u64 *stime), TP_ARGS(stime)); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index f84618ee5d05..26eb7f20f798 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -66,6 +66,9 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(mm_page_alloc); EXPORT_TRACEPOINT_SYMBOL_GPL(mm_page_free); +#undef CREATE_TRACE_POINTS +#include + /* Free Page Internal flags: for internal, non-pcp variants of free_pages(). */ typedef int __bitwise fpi_t; @@ -3682,6 +3685,7 @@ retry: check_alloc_wmark: 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 b9ea64794345..73f8d34455c8 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1470,6 +1470,7 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, __folio_mod_stat(folio, nr, nr_pmdmapped); mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON, 1); + trace_android_vh_page_add_new_anon_rmap(&folio->page, vma, address); } static __always_inline void __folio_add_file_rmap(struct folio *folio,