From 7acbeed030cfc82afa78ff37c71761f57b7233b0 Mon Sep 17 00:00:00 2001 From: Bibek Kumar Patro Date: Thu, 16 May 2024 11:05:58 +0530 Subject: [PATCH] ANDROID: mm/cma: Introduce vendor hooks for best fit CMA allocation Introduce vendor hooks for best fit mechanism of CMA allocation. Bug: 379357530 Change-Id: I8149b0ba1c69d3482e726b6ff5227e8344aed6aa Signed-off-by: Bibek Kumar Patro --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 11 +++++++++++ mm/cma.c | 8 ++++++++ mm/cma.h | 2 ++ 4 files changed, 22 insertions(+) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 09987377ca68..daa8ccd90f53 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -76,6 +76,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_send_sig_info); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_killed_process); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_arch_set_freq_scale); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_bitmap_find_best_next_area); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_transaction_init); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_set_priority); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_binder_restore_priority); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 9200bd1cc9af..6516545096a0 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -35,6 +35,17 @@ 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_bitmap_find_best_next_area, + TP_PROTO(unsigned long *bitmap, + unsigned long bitmap_maxno, + unsigned long start, + unsigned int bitmap_count, + unsigned long mask, + unsigned long offset, + unsigned long *bitmap_no, + bool status), + TP_ARGS(bitmap, bitmap_maxno, start, bitmap_count, mask, + offset, bitmap_no, status), 1); /* DECLARE_RESTRICTED_HOOK(android_rvh_set_skip_swapcache_flags, diff --git a/mm/cma.c b/mm/cma.c index babbc44ab02f..3e0f11da2b8a 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -29,6 +29,7 @@ #include #include #include +#define CREATE_TRACE_POINTS #include #undef CREATE_TRACE_POINTS #include @@ -133,6 +134,8 @@ static void __init cma_activate_area(struct cma *cma) spin_lock_init(&cma->mem_head_lock); #endif + android_init_vendor_data(cma, 1); + return; not_in_zone: @@ -463,6 +466,11 @@ struct page *__cma_alloc(struct cma *cma, unsigned long count, bitmap_no = bitmap_find_next_zero_area_off(cma->bitmap, bitmap_maxno, start, bitmap_count, mask, offset); +#ifdef CONFIG_ANDROID_VENDOR_OEM_DATA + trace_android_rvh_bitmap_find_best_next_area(cma->bitmap, + bitmap_maxno, start, bitmap_count, mask, + offset, &bitmap_no, cma->android_vendor_data1); +#endif if (bitmap_no >= bitmap_maxno) { if ((num_attempts < max_retries) && (ret == -EBUSY)) { spin_unlock_irq(&cma->lock); diff --git a/mm/cma.h b/mm/cma.h index ad61cc6dd439..c5c1f94c4529 100644 --- a/mm/cma.h +++ b/mm/cma.h @@ -4,6 +4,7 @@ #include #include +#include struct cma_kobject { struct kobject kobj; @@ -33,6 +34,7 @@ struct cma { struct cma_kobject *cma_kobj; #endif bool reserve_pages_on_error; + ANDROID_VENDOR_DATA(1); }; extern struct cma cma_areas[MAX_CMA_AREAS];