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 <quic_charante@quicinc.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
This commit is contained in:
Charan Teja Kalla
2025-02-19 17:54:25 +05:30
committed by Suren Baghdasaryan
parent fac8fe3f78
commit add2b5a560
3 changed files with 20 additions and 1 deletions
+2
View File
@@ -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);
+8 -1
View File
@@ -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,
+10
View File
@@ -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)) {