From 0ca85e35bf5b4a7ff08f00a060c83e4a82380b64 Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Tue, 24 May 2022 11:12:33 -0700 Subject: [PATCH] ANDROID: add vendor_hook to control CMA allocation ratio CMA first allocation policy for movable makes CMA(Upstream doesn't) area always full. It's good for memory efficiency since it could use up CMA available memory most of time. However, it could cause cma_alloc slow since it causes a lot page migration all the time. Let's add vendor hook for someone who want to restore CMA allocation policy to upstream so they will see less page migration in cma_alloc. If the vendor_hook returns false, the rmqueue_bulk return 0 without filling pcp->lists so get_populated_pcp_list will return NULL. Once get_populated_pcp_list returns NULL, __rmqueue_pcplist will retry the page allocation with original migratetype(currently, original migratetype couldn't be MIGRATE_CMA) so the retrial will find available pages from !MIGRATE_CMA free list. Bug: 231978523 Signed-off-by: Minchan Kim Change-Id: Ia031d9bc6f34085b892a8d9923bf5b9b1794f94a --- drivers/android/vendor_hooks.c | 1 + include/trace/hooks/mm.h | 3 +++ mm/page_alloc.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/android/vendor_hooks.c b/drivers/android/vendor_hooks.c index 804d5a1460ac..afee68c46b82 100644 --- a/drivers/android/vendor_hooks.c +++ b/drivers/android/vendor_hooks.c @@ -277,6 +277,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_get_from_fragment_pool); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_exclude_reserved_zone); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_include_reserved_zone); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_pages_slowpath); +EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_cma_alloc_adjust); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_show_mem); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_print_slabinfo_header); EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_do_shrink_slab); diff --git a/include/trace/hooks/mm.h b/include/trace/hooks/mm.h index 9b583a337101..94983d8d73f8 100644 --- a/include/trace/hooks/mm.h +++ b/include/trace/hooks/mm.h @@ -70,6 +70,9 @@ DECLARE_HOOK(android_vh_show_mem, DECLARE_HOOK(android_vh_alloc_pages_slowpath, TP_PROTO(gfp_t gfp_mask, unsigned int order, unsigned long delta), TP_ARGS(gfp_mask, order, delta)); +DECLARE_HOOK(android_vh_cma_alloc_adjust, + TP_PROTO(struct zone *zone, bool *is_cma_alloc), + TP_ARGS(zone, is_cma_alloc)); DECLARE_HOOK(android_vh_print_slabinfo_header, TP_PROTO(struct seq_file *m), TP_ARGS(m)); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 757cb85124b0..969348ee43b0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3057,12 +3057,16 @@ static int rmqueue_bulk(struct zone *zone, unsigned int order, spin_lock(&zone->lock); for (i = 0; i < count; ++i) { - struct page *page; + struct page *page = NULL; - if (is_migrate_cma(migratetype)) - page = __rmqueue_cma(zone, order, migratetype, + if (is_migrate_cma(migratetype)) { + bool is_cma_alloc = true; + + trace_android_vh_cma_alloc_adjust(zone, &is_cma_alloc); + if (is_cma_alloc) + page = __rmqueue_cma(zone, order, migratetype, alloc_flags); - else + } else page = __rmqueue(zone, order, migratetype, alloc_flags); if (unlikely(page == NULL))