From 99e3951ea46cbc90fa412cd7f12630e4a610fb3f Mon Sep 17 00:00:00 2001 From: Pavankumar Kondeti Date: Mon, 26 Sep 2022 18:36:10 +0530 Subject: [PATCH] ANDROID: vendor_hooks: Allow shared pages reclaim via MADV_PAGEOUT Add a hook in madvise_cold_or_pageout_pte_range() to allow vendor modules to influence the shared pages reclaim. Bug: 242678506 Change-Id: I269a385b59f7291c2e96478674bb3d05f94584cb Signed-off-by: Pavankumar Kondeti --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 3 +++ mm/madvise.c | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 483811d6873b..569a69580999 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -402,6 +402,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_check_hibernation_swap); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_cpu_resume); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_save_hib_resume_bdev); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dma_buf_stats_teardown); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_cold_or_pageout); /* * For type visibility diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index d0dc3d8c61b7..b3abf9dbd24a 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -150,6 +150,9 @@ DECLARE_HOOK(android_vh_rmqueue, DECLARE_HOOK(android_vh_kmalloc_slab, TP_PROTO(unsigned int index, gfp_t flags, struct kmem_cache **s), TP_ARGS(index, flags, s)); +DECLARE_HOOK(android_vh_madvise_cold_or_pageout, + TP_PROTO(struct vm_area_struct *vma, bool *allow_shared), + TP_ARGS(vma, allow_shared)); #endif /* _TRACE_HOOK_MM_H */ /* This part must be outside protection */ diff --git a/mm/madvise.c b/mm/madvise.c index 94ce40a965f6..fba5c83cec9f 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -324,10 +325,12 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, spinlock_t *ptl; struct page *page = NULL; LIST_HEAD(page_list); + bool allow_shared = false; if (fatal_signal_pending(current)) return -EINTR; + trace_android_vh_madvise_cold_or_pageout(vma, &allow_shared); #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (pmd_trans_huge(*pmd)) { pmd_t orig_pmd; @@ -443,7 +446,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, } /* Do not interfere with other mappings of this page */ - if (page_mapcount(page) != 1) + if (!allow_shared && page_mapcount(page) != 1) continue; VM_BUG_ON_PAGE(PageTransCompound(page), page);