From add2b5a560c69b21c09e79e7d808ad0215c61797 Mon Sep 17 00:00:00 2001 From: Charan Teja Kalla Date: Wed, 19 Feb 2025 17:54:25 +0530 Subject: [PATCH] ANDROID: mm: shmem: add vendor hooks in shmem folio allocation path Add vendor hooks in shmem folio allocation paths to tune the higher order folios. With vendor hook possibly overriding shmem_allowable_huge_orders() result, `order` inside shmem_get_folio_gfp() becomes variable when when CONFIG_TRANSPARENT_HUGEPAGE=n and the block that calls vma_thp_gfp_mask() is not compiled out anymore, leading to the following linker error: ld.lld: error: undefined symbol: vma_thp_gfp_mask >>> referenced by shmem.c Fix this by making the block dependent on CONFIG_TRANSPARENT_HUGEPAGE. Bug: 397599006 Change-Id: Ia0e126c674a9f08cb10fe5ee06f5efac7b5cbe7f Signed-off-by: Charan Teja Kalla Signed-off-by: Suren Baghdasaryan --- drivers/android/vendor_hooks.c | 2 ++ include/trace/hooks/mm.h | 9 ++++++++- mm/shmem.c | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 946590742647..f80f2486ed75 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -286,6 +286,8 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_tune_swappiness); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_logbuf_pr_cont); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_calc_alloc_flags); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_regmap_update); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_shmem_suitable_orders); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_shmem_allowable_huge_orders); EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_shmem_get_folio); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_slab_folio_alloced); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_kmalloc_large_alloced); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 3f882265c50f..89f0843a5fcd 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -20,7 +20,14 @@ DECLARE_RESTRICTED_HOOK(android_rvh_try_alloc_pages_gfp, TP_PROTO(struct page **page, unsigned int order, gfp_t gfp, enum zone_type highest_zoneidx), TP_ARGS(page, order, gfp, highest_zoneidx), 1); - +DECLARE_RESTRICTED_HOOK(android_rvh_shmem_suitable_orders, + TP_PROTO(struct inode *inode, pgoff_t index, + unsigned long orders, unsigned long *suitable_orders), + TP_ARGS(inode, index, orders, suitable_orders), 4); +DECLARE_RESTRICTED_HOOK(android_rvh_shmem_allowable_huge_orders, + TP_PROTO(struct inode *inode, pgoff_t index, + struct vm_area_struct *vma, unsigned long *orders), + TP_ARGS(inode, index, vma, orders), 4); /* DECLARE_RESTRICTED_HOOK(android_rvh_set_skip_swapcache_flags, diff --git a/mm/shmem.c b/mm/shmem.c index 375f4d89d836..be8dd416ce44 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1804,6 +1804,8 @@ static struct folio *shmem_alloc_and_add_folio(struct vm_fault *vmf, suitable_orders = shmem_suitable_orders(inode, vmf, mapping, index, orders); + trace_android_rvh_shmem_suitable_orders(inode, index, + orders, &suitable_orders); order = highest_order(suitable_orders); while (suitable_orders) { pages = 1UL << order; @@ -2322,6 +2324,13 @@ repeat: /* Find hugepage orders that are allowed for anonymous shmem and tmpfs. */ orders = shmem_allowable_huge_orders(inode, vma, index, write_end, false); + trace_android_rvh_shmem_allowable_huge_orders(inode, index, vma, &orders); + /* + * With the above hook `order` is not always 0 anymore and the following + * if block does not get compiled out. With CONFIG_TRANSPARENT_HUGEPAGE=n + * vma_thp_gfp_mask() becomes undefined and linker fails. + */ +#ifdef CONFIG_TRANSPARENT_HUGEPAGE if (orders > 0) { gfp_t huge_gfp; @@ -2338,6 +2347,7 @@ repeat: if (PTR_ERR(folio) == -EEXIST) goto repeat; } +#endif folio = shmem_alloc_and_add_folio(vmf, gfp, inode, index, fault_mm, 0); if (IS_ERR(folio)) {