From 667f0d71dc08e25bf013cafa617adf6789fe5b93 Mon Sep 17 00:00:00 2001 From: Bing Han Date: Fri, 10 Jun 2022 19:00:02 +0800 Subject: [PATCH] ANDROID: vendor_hooks: Add hooks to extend the struct swap_info_struct Two vendor hooks are added to extend the struct swap_info_struct: android_vh_alloc_si, extend the allocation of struct swap_info_struct, adding data to record the information of specified reclaimed location; android_vh_init_swap_info_struct, adding initializing the extension of struct swap_info_struct; Bug: 234214858 Signed-off-by: Bing Han Change-Id: I0e1d8e38ba7dfd52b609b1c14eb78f8b0ef0f9e6 --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/mm.h | 6 ++++++ mm/swapfile.c | 8 ++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f897daea3aea..6409da002b43 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -422,3 +422,5 @@ 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); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_unuse_swap_page); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_init_swap_info_struct); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_si); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 6f385db5813b..d05e3bef5e2b 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -188,6 +188,12 @@ DECLARE_HOOK(android_vh_account_swap_pages, DECLARE_HOOK(android_vh_unuse_swap_page, TP_PROTO(struct swap_info_struct *si, struct page *page), TP_ARGS(si, page)); +DECLARE_HOOK(android_vh_init_swap_info_struct, + TP_PROTO(struct swap_info_struct *p, struct plist_head *swap_avail_heads), + TP_ARGS(p, swap_avail_heads)); +DECLARE_HOOK(android_vh_alloc_si, + TP_PROTO(struct swap_info_struct **p, bool *skip), + TP_ARGS(p, skip)); /* macro versions of hooks are no longer required */ #endif /* _TRACE_HOOK_MM_H */ diff --git a/mm/swapfile.c b/mm/swapfile.c index 7d7e9096fec8..4a41956f1ad1 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -2898,12 +2898,15 @@ late_initcall(max_swapfiles_check); static struct swap_info_struct *alloc_swap_info(void) { - struct swap_info_struct *p; + struct swap_info_struct *p = NULL; struct swap_info_struct *defer = NULL; unsigned int type; int i; + bool skip = false; - p = kvzalloc(struct_size(p, avail_lists, nr_node_ids), GFP_KERNEL); + trace_android_vh_alloc_si(&p, &skip); + if (!skip) + p = kvzalloc(struct_size(p, avail_lists, nr_node_ids), GFP_KERNEL); if (!p) return ERR_PTR(-ENOMEM); @@ -3386,6 +3389,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags) (swap_flags & SWAP_FLAG_PRIO_MASK) >> SWAP_FLAG_PRIO_SHIFT; enable_swap_info(p, prio, swap_map, cluster_info, frontswap_map); + trace_android_vh_init_swap_info_struct(p, swap_avail_heads); pr_info("Adding %uk swap on %s. Priority:%d extents:%d across:%lluk %s%s%s%s%s\n", p->pages<<(PAGE_SHIFT-10), name->name, p->prio, nr_extents, (unsigned long long)span<<(PAGE_SHIFT-10),