mm: compaction: encapsulate defer reset logic
authorVlastimil Babka <vbabka@suse.cz>
Tue, 21 Jan 2014 23:51:07 +0000 (15:51 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 22 Jan 2014 00:19:48 +0000 (16:19 -0800)
Currently there are several functions to manipulate the deferred
compaction state variables.  The remaining case where the variables are
touched directly is when a successful allocation occurs in direct
compaction, or is expected to be successful in the future by kswapd.
Here, the lowest order that is expected to fail is updated, and in the
case of successful allocation, the deferred status and counter is reset
completely.

Create a new function compaction_defer_reset() to encapsulate this
functionality and make it easier to understand the code.  No functional
change.

Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Mel Gorman <mgorman@suse.de>
Reviewed-by: Rik van Riel <riel@redhat.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/compaction.h
mm/compaction.c
mm/page_alloc.c

index 091d72e70d8a708f55d447b8559814caa2952b1a..7e1c76e3cd6890387b983be96377bf7c19cd3c06 100644 (file)
@@ -62,6 +62,22 @@ static inline bool compaction_deferred(struct zone *zone, int order)
        return zone->compact_considered < defer_limit;
 }
 
+/*
+ * Update defer tracking counters after successful compaction of given order,
+ * which means an allocation either succeeded (alloc_success == true) or is
+ * expected to succeed.
+ */
+static inline void compaction_defer_reset(struct zone *zone, int order,
+               bool alloc_success)
+{
+       if (alloc_success) {
+               zone->compact_considered = 0;
+               zone->compact_defer_shift = 0;
+       }
+       if (order >= zone->compact_order_failed)
+               zone->compact_order_failed = order + 1;
+}
+
 /* Returns true if restarting compaction after many failures */
 static inline bool compaction_restarting(struct zone *zone, int order)
 {
index a03995eddedb9b8713b979890e4e82aa9fd11823..927de97cab8d1f8e494515ba5280276bc468762b 100644 (file)
@@ -1124,12 +1124,11 @@ static void __compact_pgdat(pg_data_t *pgdat, struct compact_control *cc)
                        compact_zone(zone, cc);
 
                if (cc->order > 0) {
-                       int ok = zone_watermark_ok(zone, cc->order,
-                                               low_wmark_pages(zone), 0, 0);
-                       if (ok && cc->order >= zone->compact_order_failed)
-                               zone->compact_order_failed = cc->order + 1;
+                       if (zone_watermark_ok(zone, cc->order,
+                                               low_wmark_pages(zone), 0, 0))
+                               compaction_defer_reset(zone, cc->order, false);
                        /* Currently async compaction is never deferred. */
-                       else if (!ok && cc->sync)
+                       else if (cc->sync)
                                defer_compaction(zone, cc->order);
                }
 
index b230e838883d020a0dc058d85e1f95400d31ced3..84da0e3bc8869e625b2ad57af17ac17319ce9fcd 100644 (file)
@@ -2235,10 +2235,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
                                preferred_zone, migratetype);
                if (page) {
                        preferred_zone->compact_blockskip_flush = false;
-                       preferred_zone->compact_considered = 0;
-                       preferred_zone->compact_defer_shift = 0;
-                       if (order >= preferred_zone->compact_order_failed)
-                               preferred_zone->compact_order_failed = order + 1;
+                       compaction_defer_reset(preferred_zone, order, true);
                        count_vm_event(COMPACTSUCCESS);
                        return page;
                }