mm: forward memory reclaim process
authorTao Zeng <tao.zeng@amlogic.com>
Tue, 12 Sep 2017 08:39:40 +0000 (16:39 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Wed, 13 Sep 2017 01:36:25 +0000 (18:36 -0700)
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 <tao.zeng@amlogic.com>
mm/page_alloc.c

index c287b47..ed0f309 100644 (file)
@@ -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);