switch xattr_handler->set() to passing dentry and inode separately
[linux-2.6-microblaze.git] / mm / compaction.c
index 455ecd8..1427366 100644 (file)
@@ -1252,7 +1252,10 @@ static enum compact_result __compact_finished(struct zone *zone, struct compact_
                if (cc->direct_compaction)
                        zone->compact_blockskip_flush = true;
 
-               return COMPACT_COMPLETE;
+               if (cc->whole_zone)
+                       return COMPACT_COMPLETE;
+               else
+                       return COMPACT_PARTIAL_SKIPPED;
        }
 
        if (is_via_compact_memory(cc->order))
@@ -1315,7 +1318,8 @@ static enum compact_result compact_finished(struct zone *zone,
  */
 static enum compact_result __compaction_suitable(struct zone *zone, int order,
                                        unsigned int alloc_flags,
-                                       int classzone_idx)
+                                       int classzone_idx,
+                                       unsigned long wmark_target)
 {
        int fragindex;
        unsigned long watermark;
@@ -1338,7 +1342,8 @@ static enum compact_result __compaction_suitable(struct zone *zone, int order,
         * allocated and for a short time, the footprint is higher
         */
        watermark += (2UL << order);
-       if (!zone_watermark_ok(zone, 0, watermark, classzone_idx, alloc_flags))
+       if (!__zone_watermark_ok(zone, 0, watermark, classzone_idx,
+                                alloc_flags, wmark_target))
                return COMPACT_SKIPPED;
 
        /*
@@ -1365,7 +1370,8 @@ enum compact_result compaction_suitable(struct zone *zone, int order,
 {
        enum compact_result ret;
 
-       ret = __compaction_suitable(zone, order, alloc_flags, classzone_idx);
+       ret = __compaction_suitable(zone, order, alloc_flags, classzone_idx,
+                                   zone_page_state(zone, NR_FREE_PAGES));
        trace_mm_compaction_suitable(zone, order, ret);
        if (ret == COMPACT_NOT_SUITABLE_ZONE)
                ret = COMPACT_SKIPPED;
@@ -1373,6 +1379,39 @@ enum compact_result compaction_suitable(struct zone *zone, int order,
        return ret;
 }
 
+bool compaction_zonelist_suitable(struct alloc_context *ac, int order,
+               int alloc_flags)
+{
+       struct zone *zone;
+       struct zoneref *z;
+
+       /*
+        * Make sure at least one zone would pass __compaction_suitable if we continue
+        * retrying the reclaim.
+        */
+       for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->high_zoneidx,
+                                       ac->nodemask) {
+               unsigned long available;
+               enum compact_result compact_result;
+
+               /*
+                * Do not consider all the reclaimable memory because we do not
+                * want to trash just for a single high order allocation which
+                * is even not guaranteed to appear even if __compaction_suitable
+                * is happy about the watermark check.
+                */
+               available = zone_reclaimable_pages(zone) / order;
+               available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
+               compact_result = __compaction_suitable(zone, order, alloc_flags,
+                               ac_classzone_idx(ac), available);
+               if (compact_result != COMPACT_SKIPPED &&
+                               compact_result != COMPACT_NOT_SUITABLE_ZONE)
+                       return true;
+       }
+
+       return false;
+}
+
 static enum compact_result compact_zone(struct zone *zone, struct compact_control *cc)
 {
        enum compact_result ret;
@@ -1413,6 +1452,10 @@ static enum compact_result compact_zone(struct zone *zone, struct compact_contro
                zone->compact_cached_migrate_pfn[0] = cc->migrate_pfn;
                zone->compact_cached_migrate_pfn[1] = cc->migrate_pfn;
        }
+
+       if (cc->migrate_pfn == start_pfn)
+               cc->whole_zone = true;
+
        cc->last_migrated_pfn = 0;
 
        trace_mm_compaction_begin(start_pfn, cc->migrate_pfn,
@@ -1578,7 +1621,7 @@ enum compact_result 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;
-       enum compact_result rc = COMPACT_DEFERRED;
+       enum compact_result rc = COMPACT_SKIPPED;
        int all_zones_contended = COMPACT_CONTENDED_LOCK; /* init for &= op */
 
        *contended = COMPACT_CONTENDED_NONE;
@@ -1595,8 +1638,10 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
                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,
@@ -1632,7 +1677,8 @@ enum compact_result try_to_compact_pages(gfp_t gfp_mask, unsigned int order,
                        goto break_loop;
                }
 
-               if (mode != MIGRATE_ASYNC && status == COMPACT_COMPLETE) {
+               if (mode != MIGRATE_ASYNC && (status == COMPACT_COMPLETE ||
+                                       status == COMPACT_PARTIAL_SKIPPED)) {
                        /*
                         * We think that allocation won't succeed in this zone
                         * so we defer compaction there. If it ends up
@@ -1667,7 +1713,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;
@@ -1816,7 +1862,7 @@ static bool kcompactd_node_suitable(pg_data_t *pgdat)
        struct zone *zone;
        enum zone_type classzone_idx = pgdat->kcompactd_classzone_idx;
 
-       for (zoneid = 0; zoneid < classzone_idx; zoneid++) {
+       for (zoneid = 0; zoneid <= classzone_idx; zoneid++) {
                zone = &pgdat->node_zones[zoneid];
 
                if (!populated_zone(zone))
@@ -1851,7 +1897,7 @@ static void kcompactd_do_work(pg_data_t *pgdat)
                                                        cc.classzone_idx);
        count_vm_event(KCOMPACTD_WAKE);
 
-       for (zoneid = 0; zoneid < cc.classzone_idx; zoneid++) {
+       for (zoneid = 0; zoneid <= cc.classzone_idx; zoneid++) {
                int status;
 
                zone = &pgdat->node_zones[zoneid];
@@ -1879,7 +1925,7 @@ static void kcompactd_do_work(pg_data_t *pgdat)
                                                cc.classzone_idx, 0)) {
                        success = true;
                        compaction_defer_reset(zone, cc.order, false);
-               } else if (status == COMPACT_COMPLETE) {
+               } else if (status == COMPACT_PARTIAL_SKIPPED || status == COMPACT_COMPLETE) {
                        /*
                         * We use sync migration mode here, so we defer like
                         * sync direct compaction does.