From 4053a7d0ec539442b05a9d9aa5c89e6eb37ab962 Mon Sep 17 00:00:00 2001 From: Tao Zeng Date: Tue, 12 Sep 2017 16:39:40 +0800 Subject: [PATCH] mm: forward memory reclaim process PD#150206: mm: forward memory reclaim process memory reclaim process is usually do when first allocate failed from buddy. This will cause some process crash especially when memory is low, because there is not enough time to do reclaim process. This change try to wake up kswapd process to reclaim memory if free memory is less than high water mark. After apply this change, free memory is usually keeps high than high_water mark. Change-Id: I03b5b931b6ec1fe1345d6f5cf8c15150438a26d3 Signed-off-by: Tao Zeng --- mm/page_alloc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c287b47..ed0f3098 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3888,6 +3888,31 @@ got_pg: return page; } +#ifdef CONFIG_AMLOGIC_MODIFY +static inline void should_wakeup_kswap(gfp_t gfp_mask, int order, + struct alloc_context *ac) +{ + unsigned long free_pages; + struct zoneref *z = ac->preferred_zoneref; + struct zone *zone; + + if (!(gfp_mask & __GFP_RECLAIM)) /* not allowed */ + return; + + for_next_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx, + ac->nodemask) { + free_pages = zone_page_state(zone, NR_FREE_PAGES); + /* + * wake up kswapd before get pages from buddy, this help to + * fast reclaim process and can avoid memory become too low + * some times + */ + if (free_pages <= high_wmark_pages(zone)) + wakeup_kswapd(zone, order, ac->high_zoneidx); + } +} +#endif + /* * This is the 'heart' of the zoned buddy allocator. */ @@ -3951,6 +3976,9 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, */ goto no_zone; } +#ifdef CONFIG_AMLOGIC_MODIFY + should_wakeup_kswap(gfp_mask, order, &ac); +#endif /* First allocation attempt */ page = get_page_from_freelist(alloc_mask, order, alloc_flags, &ac); -- 2.7.4