From 91d24272180b478d60ea2ca35664a6e86bb67774 Mon Sep 17 00:00:00 2001 From: zihan ju Date: Tue, 31 Oct 2023 16:13:55 +0800 Subject: [PATCH] ANDROID: Add Interrupt Hook for madvise Compression We introduce an interrupt hook in Android to manage memory compression using madvise, improving user experience. Currently, when a user returns to the home screen, memory compression is triggered using madvise. The vma and PAGEOUT flag are sent to process_madvise, initiating page reclaim. However, if an app is re-opened soon after starting compression, the reclaim process can cause read delays, leading to potential lag. To resolve this, we propose to skip pte range traversal. By comparing the vma's task uid with the current app's uid, we can identify and interrupt the madvise operation for that vma. Implementing this requires a vendor hook for should_end_madvise. This allows us to skip traversal, enhancing user experience. Bug: 307846869 Change-Id: If2bdbc200b7305e92f836353b7356aa115e00705 Signed-off-by: zihan ju --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 3 +++ mm/madvise.c | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 7b945c3cce28..3ca92b6b1172 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -474,6 +474,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_del_from_avail_list); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh___cgroup_throttle_swaprate); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_cold_or_pageout); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_page_isolated_for_reclaim); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_should_end_madvise); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_inactive_is_low); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_snapshot_refaults); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_account_swap_pages); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 4628e4aa1cc6..2b2459b1b878 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -302,6 +302,9 @@ DECLARE_HOOK(android_vh_madvise_cold_or_pageout, DECLARE_HOOK(android_vh_page_isolated_for_reclaim, TP_PROTO(struct mm_struct *mm, struct page *page), TP_ARGS(mm, page)); +DECLARE_HOOK(android_vh_should_end_madvise, + TP_PROTO(struct mm_struct *mm, bool *skip, bool *pageout), + TP_ARGS(mm, skip, pageout)); DECLARE_HOOK(android_vh_account_swap_pages, TP_PROTO(struct swap_info_struct *si, bool *skip), TP_ARGS(si, skip)); diff --git a/mm/madvise.c b/mm/madvise.c index d16fa1d8f60f..7071c1116f32 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -323,6 +323,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, LIST_HEAD(page_list); bool allow_shared = false; bool abort_madvise = false; + bool skip = false; trace_android_vh_madvise_cold_or_pageout_abort(vma, &abort_madvise); if (fatal_signal_pending(current) || abort_madvise) @@ -419,6 +420,10 @@ regular_page: if (!page) continue; + trace_android_vh_should_end_madvise(mm, &skip, &pageout); + if (skip) + break; + /* * Creating a THP page is expensive so split it only if we * are sure it's worth. Split it if we are only owner.