From 3a2ed8898c25f8b7d46760d5d212d780f0dbd6cf Mon Sep 17 00:00:00 2001 From: Sooyong Suk Date: Wed, 24 May 2023 09:34:19 +0900 Subject: [PATCH] ANDROID: task_mmu: add vendor hook for swap entry Add vendor hook in smaps_pte_entry for swap entry - android_vh_smaps_pte_entry - android_vh_show_smap This vendor hook is to show more information for swap entries of a process based on the characteristics, such as written-back, same-filled or huge (uncompressed). This also merges changes in https://android-review.googlesource.com/c/kernel/common/+/3164628 to count and show swap_shared with single vendor hook. Bug: 284059805 Change-Id: Ie4a48ae42212c056992d34a10b026b60439d0012 Signed-off-by: Sooyong Suk --- drivers/android/vendor_hooks.c | 2 ++ fs/proc/task_mmu.c | 10 ++++++++++ include/trace/hooks/mm.h | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index f3c4a0767d4e..610d996cd217 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -273,3 +273,5 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_modify_scan_control); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_should_continue_reclaim); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_async_psi_bypass); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cma_alloc_retry); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_smaps_pte_entry); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_smap); diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 536b7dc45381..fe9daefda4f5 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -658,6 +659,10 @@ struct mem_size_stats { unsigned long shmem_thp; unsigned long file_thp; unsigned long swap; + unsigned long swap_shared; + unsigned long writeback; + unsigned long same; + unsigned long huge; unsigned long shared_hugetlb; unsigned long private_hugetlb; unsigned long ksm; @@ -820,6 +825,9 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr, } else { mss->swap_pss += (u64)PAGE_SIZE << PSS_SHIFT; } + trace_android_vh_smaps_pte_entry(swpent, mapcount, + &mss->swap_shared, &mss->writeback, + &mss->same, &mss->huge); } else if (is_pfn_swap_entry(swpent)) { if (is_device_private_entry(swpent)) present = true; @@ -1133,6 +1141,8 @@ static void __show_smap(struct seq_file *m, const struct mem_size_stats *mss, SEQ_PUT_DEC(" kB\nLocked: ", mss->pss_locked >> PSS_SHIFT); seq_puts(m, " kB\n"); + trace_android_vh_show_smap(m, mss->swap_shared, mss->writeback, + mss->same, mss->huge); } static int show_smap(struct seq_file *m, void *v) diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 21ce0fa90fe0..15a11e9f75f9 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -130,6 +130,16 @@ DECLARE_RESTRICTED_HOOK(android_rvh_vfree_bypass, DECLARE_HOOK(android_vh_cma_alloc_retry, TP_PROTO(char *name, int *retry), TP_ARGS(name, retry)); +DECLARE_HOOK(android_vh_smaps_pte_entry, + TP_PROTO(swp_entry_t entry, int mapcount, + unsigned long *swap_shared, unsigned long *writeback, + unsigned long *same, unsigned long *huge), + TP_ARGS(entry, mapcount, swap_shared, writeback, same, huge)); +DECLARE_HOOK(android_vh_show_smap, + TP_PROTO(struct seq_file *m, + unsigned long swap_shared, unsigned long writeback, + unsigned long same, unsigned long huge), + TP_ARGS(m, swap_shared, writeback, same, huge)); #endif /* _TRACE_HOOK_MM_H */ /* This part must be outside protection */