mm/compaction: fix misbehaviors of fast_find_migrateblock()
[platform/kernel/linux-rpi.git] / mm / compaction.c
index 0846d4f..21dcae9 100644 (file)
@@ -1662,6 +1662,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
        unsigned long pfn = cc->migrate_pfn;
        unsigned long high_pfn;
        int order;
+       bool found_block = false;
 
        /* Skip hints are relied on to avoid repeats on the fast search */
        if (cc->ignore_skip_hint)
@@ -1704,7 +1705,7 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
        high_pfn = pageblock_start_pfn(cc->migrate_pfn + distance);
 
        for (order = cc->order - 1;
-            order >= PAGE_ALLOC_COSTLY_ORDER && pfn == cc->migrate_pfn && nr_scanned < limit;
+            order >= PAGE_ALLOC_COSTLY_ORDER && !found_block && nr_scanned < limit;
             order--) {
                struct free_area *area = &cc->zone->free_area[order];
                struct list_head *freelist;
@@ -1719,7 +1720,11 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
                list_for_each_entry(freepage, freelist, lru) {
                        unsigned long free_pfn;
 
-                       nr_scanned++;
+                       if (nr_scanned++ >= limit) {
+                               move_freelist_tail(freelist, freepage);
+                               break;
+                       }
+
                        free_pfn = page_to_pfn(freepage);
                        if (free_pfn < high_pfn) {
                                /*
@@ -1728,12 +1733,8 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
                                 * the list assumes an entry is deleted, not
                                 * reordered.
                                 */
-                               if (get_pageblock_skip(freepage)) {
-                                       if (list_is_last(freelist, &freepage->lru))
-                                               break;
-
+                               if (get_pageblock_skip(freepage))
                                        continue;
-                               }
 
                                /* Reorder to so a future search skips recent pages */
                                move_freelist_tail(freelist, freepage);
@@ -1741,15 +1742,10 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
                                update_fast_start_pfn(cc, free_pfn);
                                pfn = pageblock_start_pfn(free_pfn);
                                cc->fast_search_fail = 0;
+                               found_block = true;
                                set_pageblock_skip(freepage);
                                break;
                        }
-
-                       if (nr_scanned >= limit) {
-                               cc->fast_search_fail++;
-                               move_freelist_tail(freelist, freepage);
-                               break;
-                       }
                }
                spin_unlock_irqrestore(&cc->zone->lock, flags);
        }
@@ -1760,9 +1756,10 @@ static unsigned long fast_find_migrateblock(struct compact_control *cc)
         * If fast scanning failed then use a cached entry for a page block
         * that had free pages as the basis for starting a linear scan.
         */
-       if (pfn == cc->migrate_pfn)
+       if (!found_block) {
+               cc->fast_search_fail++;
                pfn = reinit_migrate_pfn(cc);
-
+       }
        return pfn;
 }