From: Tao Zeng Date: Tue, 12 Sep 2017 08:39:40 +0000 (+0800) Subject: mm: forward memory reclaim process X-Git-Tag: khadas-vims-v0.9.6-release~2860 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4053a7d0ec539442b05a9d9aa5c89e6eb37ab962;p=platform%2Fkernel%2Flinux-amlogic.git 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 --- 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);