ANDROID: Add vendor hook for cma adjusting

CMA was originally designed to be fallback of GFP_MOVABLE when it is
worked as second client(alloc_pages). However, it is working more like
reserved memory for anon&swap pages that hard binded with _GFP_CMA now,
which has bellowing negative impactions:

1. Permanantyly use MIGRATE_CMA first under any scenario which could introduce
   large numbers of migration when cma_alloc() happens.
2. normal GFP_MOVABLE has no opportunity to fallback to CMA which could lead to
   abnormal reclaiming as bellowing scenario etc.
alloc_pages(GFP_MOVABLE)
    zone_watermark_ok() == false(MIGRATE_CMA is not available)
        wakeup_kswapd
            kswapd can't work(large number of CMA pages make free over watermark_high)

I would like to introduce the fallback way back when __rmqueue fail. Kernel could
work in original way as it is desired to with this commit and other
 xxx_cma_adjust_vendor_hooks which could remove __GFP_CMA.

Bug: 291695746
Test: build pass
Change-Id: I479ac1ca68fe02eb7ffc8c09e29805b0ec158391
Signed-off-by: zhaoyang.huang <zhaoyang.huang@unisoc.com>
This commit is contained in:
zhaoyang.huang
2023-07-28 10:47:09 +08:00
parent f9dbe76124
commit 255e289386
3 changed files with 10 additions and 1 deletions

View File

@@ -428,6 +428,7 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_highpage_movable_gfp_adjust);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_anon_gfp_adjust);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_alloc_flags_cma_adjust);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_rmqueue_cma_fallback);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_try_cma_fallback);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_dma_buf_stats_teardown);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_cold_or_pageout);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_madvise_cold_or_pageout_abort);

View File

@@ -240,6 +240,9 @@ DECLARE_HOOK(android_vh_look_around,
TP_PROTO(struct page_vma_mapped_walk *pvmw, struct page *page,
struct vm_area_struct *vma, int *referenced),
TP_ARGS(pvmw, page, vma, referenced));
DECLARE_HOOK(android_vh_try_cma_fallback,
TP_PROTO(struct zone *zone, unsigned int order, bool *try_cma),
TP_ARGS(zone, order, try_cma));
#endif /* _TRACE_HOOK_MM_H */
/* This part must be outside protection */

View File

@@ -3176,8 +3176,13 @@ retry:
/*
* let normal GFP_MOVABLE has chance to try MIGRATE_CMA
*/
if (unlikely(!page) && (migratetype == MIGRATE_MOVABLE))
if (unlikely(!page) && (migratetype == MIGRATE_MOVABLE)) {
bool try_cma = false;
trace_android_vh_rmqueue_cma_fallback(zone, order, &page);
trace_android_vh_try_cma_fallback(zone, order, &try_cma);
if (try_cma)
page = __rmqueue_cma_fallback(zone, order);
}
if (unlikely(!page) && __rmqueue_fallback(zone, order, migratetype,
alloc_flags))