]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - mm/compaction.c
mm, compaction: distinguish COMPACT_DEFERRED from COMPACT_SKIPPED
[mirror_ubuntu-bionic-kernel.git] / mm / compaction.c
index eda3c2244f3056bec88e09195b1a9d5e30928200..b2b94474dd285b934851fa50aa4148d41418d63a 100644 (file)
@@ -1229,7 +1229,7 @@ static inline bool is_via_compact_memory(int order)
        return order == -1;
 }
 
-static int __compact_finished(struct zone *zone, struct compact_control *cc,
+static enum compact_result __compact_finished(struct zone *zone, struct compact_control *cc,
                            const int migratetype)
 {
        unsigned int order;
@@ -1292,8 +1292,9 @@ static int __compact_finished(struct zone *zone, struct compact_control *cc,
        return COMPACT_NO_SUITABLE_PAGE;
 }
 
-static int compact_finished(struct zone *zone, struct compact_control *cc,
-                           const int migratetype)
+static enum compact_result compact_finished(struct zone *zone,
+                       struct compact_control *cc,
+                       const int migratetype)
 {
        int ret;
 
@@ -1312,7 +1313,7 @@ static int compact_finished(struct zone *zone, struct compact_control *cc,
  *   COMPACT_PARTIAL  - If the allocation would succeed without compaction
  *   COMPACT_CONTINUE - If compaction should run now
  */
-static unsigned long __compaction_suitable(struct zone *zone, int order,
+static enum compact_result __compaction_suitable(struct zone *zone, int order,
                                        unsigned int alloc_flags,
                                        int classzone_idx)
 {
@@ -1358,11 +1359,11 @@ static unsigned long __compaction_suitable(struct zone *zone, int order,
        return COMPACT_CONTINUE;
 }
 
-unsigned long compaction_suitable(struct zone *zone, int order,
+enum compact_result compaction_suitable(struct zone *zone, int order,
                                        unsigned int alloc_flags,
                                        int classzone_idx)
 {
-       unsigned long ret;
+       enum compact_result ret;
 
        ret = __compaction_suitable(zone, order, alloc_flags, classzone_idx);
        trace_mm_compaction_suitable(zone, order, ret);
@@ -1372,9 +1373,9 @@ unsigned long compaction_suitable(struct zone *zone, int order,
        return ret;
 }
 
-static int compact_zone(struct zone *zone, struct compact_control *cc)
+static enum compact_result compact_zone(struct zone *zone, struct compact_control *cc)
 {
-       int ret;
+       enum compact_result ret;
        unsigned long start_pfn = zone->zone_start_pfn;
        unsigned long end_pfn = zone_end_pfn(zone);
        const int migratetype = gfpflags_to_migratetype(cc->gfp_mask);
@@ -1382,15 +1383,12 @@ static int compact_zone(struct zone *zone, struct compact_control *cc)
 
        ret = compaction_suitable(zone, cc->order, cc->alloc_flags,
                                                        cc->classzone_idx);
-       switch (ret) {
-       case COMPACT_PARTIAL:
-       case COMPACT_SKIPPED:
-               /* Compaction is likely to fail */
+       /* Compaction is likely to fail */
+       if (ret == COMPACT_PARTIAL || ret == COMPACT_SKIPPED)
                return ret;
-       case COMPACT_CONTINUE:
-               /* Fall through to compaction */
-               ;
-       }
+
+       /* huh, compaction_suitable is returning something unexpected */
+       VM_BUG_ON(ret != COMPACT_CONTINUE);
 
        /*
         * Clear pageblock skip if there were failures recently and compaction
@@ -1530,11 +1528,11 @@ out:
        return ret;
 }
 
-static unsigned long compact_zone_order(struct zone *zone, int order,
+static enum compact_result compact_zone_order(struct zone *zone, int order,
                gfp_t gfp_mask, enum migrate_mode mode, int *contended,
                unsigned int alloc_flags, int classzone_idx)
 {
-       unsigned long ret;
+       enum compact_result ret;
        struct compact_control cc = {
                .nr_freepages = 0,
                .nr_migratepages = 0,
@@ -1572,7 +1570,7 @@ int sysctl_extfrag_threshold = 500;
  *
  * This is the main entry point for direct page compaction.
  */
-unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
+enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
                unsigned int alloc_flags, const struct alloc_context *ac,
                enum migrate_mode mode, int *contended)
 {
@@ -1580,7 +1578,7 @@ unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
        int may_perform_io = gfp_mask & __GFP_IO;
        struct zoneref *z;
        struct zone *zone;
-       int rc = COMPACT_DEFERRED;
+       enum compact_result rc = COMPACT_SKIPPED;
        int all_zones_contended = COMPACT_CONTENDED_LOCK; /* init for &= op */
 
        *contended = COMPACT_CONTENDED_NONE;
@@ -1594,11 +1592,13 @@ unsigned long try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
        /* Compact each zone in the list */
        for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
                                                                ac->nodemask) {
-               int status;
+               enum compact_result status;
                int zone_contended;
 
-               if (compaction_deferred(zone, order))
+               if (compaction_deferred(zone, order)) {
+                       rc = max_t(enum compact_result, COMPACT_DEFERRED, rc);
                        continue;
+               }
 
                status = compact_zone_order(zone, order, gfp_mask, mode,
                                &zone_contended, alloc_flags,
@@ -1669,7 +1669,7 @@ break_loop:
         * If at least one zone wasn't deferred or skipped, we report if all
         * zones that were tried were lock contended.
         */
-       if (rc > COMPACT_SKIPPED && all_zones_contended)
+       if (rc > COMPACT_INACTIVE && all_zones_contended)
                *contended = COMPACT_CONTENDED_LOCK;
 
        return rc;