mm: don't emit warning from pagefault_out_of_memory()
[cascardo/linux.git] / mm / page_alloc.c
index 634806f..bcfa647 100644 (file)
@@ -3160,25 +3160,24 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
                     enum compact_result compact_result,
                     enum compact_priority *compact_priority,
-                    int compaction_retries)
+                    int *compaction_retries)
 {
        int max_retries = MAX_COMPACT_RETRIES;
+       int min_priority;
 
        if (!order)
                return false;
 
+       if (compaction_made_progress(compact_result))
+               (*compaction_retries)++;
+
        /*
         * compaction considers all the zone as desperately out of memory
         * so it doesn't really make much sense to retry except when the
         * failure could be caused by insufficient priority
         */
-       if (compaction_failed(compact_result)) {
-               if (*compact_priority > MIN_COMPACT_PRIORITY) {
-                       (*compact_priority)--;
-                       return true;
-               }
-               return false;
-       }
+       if (compaction_failed(compact_result))
+               goto check_priority;
 
        /*
         * make sure the compaction wasn't deferred or didn't bail out early
@@ -3199,9 +3198,21 @@ should_compact_retry(struct alloc_context *ac, int order, int alloc_flags,
         */
        if (order > PAGE_ALLOC_COSTLY_ORDER)
                max_retries /= 4;
-       if (compaction_retries <= max_retries)
+       if (*compaction_retries <= max_retries)
                return true;
 
+       /*
+        * Make sure there are attempts at the highest priority if we exhausted
+        * all retries or failed at the lower priorities.
+        */
+check_priority:
+       min_priority = (order > PAGE_ALLOC_COSTLY_ORDER) ?
+                       MIN_COMPACT_COSTLY_PRIORITY : MIN_COMPACT_PRIORITY;
+       if (*compact_priority > min_priority) {
+               (*compact_priority)--;
+               *compaction_retries = 0;
+               return true;
+       }
        return false;
 }
 #else
@@ -3218,7 +3229,7 @@ static inline bool
 should_compact_retry(struct alloc_context *ac, unsigned int order, int alloc_flags,
                     enum compact_result compact_result,
                     enum compact_priority *compact_priority,
-                    int compaction_retries)
+                    int *compaction_retries)
 {
        struct zone *zone;
        struct zoneref *z;
@@ -3391,16 +3402,26 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
 static inline bool
 should_reclaim_retry(gfp_t gfp_mask, unsigned order,
                     struct alloc_context *ac, int alloc_flags,
-                    bool did_some_progress, int no_progress_loops)
+                    bool did_some_progress, int *no_progress_loops)
 {
        struct zone *zone;
        struct zoneref *z;
 
+       /*
+        * Costly allocations might have made a progress but this doesn't mean
+        * their order will become available due to high fragmentation so
+        * always increment the no progress counter for them
+        */
+       if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
+               *no_progress_loops = 0;
+       else
+               (*no_progress_loops)++;
+
        /*
         * Make sure we converge to OOM if we cannot make any progress
         * several times in the row.
         */
-       if (no_progress_loops > MAX_RECLAIM_RETRIES)
+       if (*no_progress_loops > MAX_RECLAIM_RETRIES)
                return false;
 
        /*
@@ -3415,7 +3436,7 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order,
                unsigned long reclaimable;
 
                available = reclaimable = zone_reclaimable_pages(zone);
-               available -= DIV_ROUND_UP(no_progress_loops * available,
+               available -= DIV_ROUND_UP((*no_progress_loops) * available,
                                          MAX_RECLAIM_RETRIES);
                available += zone_page_state_snapshot(zone, NR_FREE_PAGES);
 
@@ -3620,9 +3641,6 @@ retry:
        if (page)
                goto got_pg;
 
-       if (order && compaction_made_progress(compact_result))
-               compaction_retries++;
-
        /* Do not loop if specifically requested */
        if (gfp_mask & __GFP_NORETRY)
                goto nopage;
@@ -3634,18 +3652,8 @@ retry:
        if (order > PAGE_ALLOC_COSTLY_ORDER && !(gfp_mask & __GFP_REPEAT))
                goto nopage;
 
-       /*
-        * Costly allocations might have made a progress but this doesn't mean
-        * their order will become available due to high fragmentation so
-        * always increment the no progress counter for them
-        */
-       if (did_some_progress && order <= PAGE_ALLOC_COSTLY_ORDER)
-               no_progress_loops = 0;
-       else
-               no_progress_loops++;
-
        if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
-                                did_some_progress > 0, no_progress_loops))
+                                did_some_progress > 0, &no_progress_loops))
                goto retry;
 
        /*
@@ -3657,7 +3665,7 @@ retry:
        if (did_some_progress > 0 &&
                        should_compact_retry(ac, order, alloc_flags,
                                compact_result, &compact_priority,
-                               compaction_retries))
+                               &compaction_retries))
                goto retry;
 
        /* Reclaim has failed us, start killing things */