Merge tag 'net-next-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev...
[linux-block.git] / mm / page_alloc.c
index 06aa1ebbd21c62c048d23e84e1cb6ab98172e077..62fc2e8f2733eac2e32dfa0bfc1436ea4f919d93 100644 (file)
@@ -4041,6 +4041,7 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
                                                struct alloc_context *ac)
 {
        bool can_direct_reclaim = gfp_mask & __GFP_DIRECT_RECLAIM;
+       bool can_compact = gfp_compaction_allowed(gfp_mask);
        const bool costly_order = order > PAGE_ALLOC_COSTLY_ORDER;
        struct page *page = NULL;
        unsigned int alloc_flags;
@@ -4111,7 +4112,7 @@ restart:
         * Don't try this for allocations that are allowed to ignore
         * watermarks, as the ALLOC_NO_WATERMARKS attempt didn't yet happen.
         */
-       if (can_direct_reclaim &&
+       if (can_direct_reclaim && can_compact &&
                        (costly_order ||
                           (order > 0 && ac->migratetype != MIGRATE_MOVABLE))
                        && !gfp_pfmemalloc_allowed(gfp_mask)) {
@@ -4209,9 +4210,10 @@ retry:
 
        /*
         * Do not retry costly high order allocations unless they are
-        * __GFP_RETRY_MAYFAIL
+        * __GFP_RETRY_MAYFAIL and we can compact
         */
-       if (costly_order && !(gfp_mask & __GFP_RETRY_MAYFAIL))
+       if (costly_order && (!can_compact ||
+                            !(gfp_mask & __GFP_RETRY_MAYFAIL)))
                goto nopage;
 
        if (should_reclaim_retry(gfp_mask, order, ac, alloc_flags,
@@ -4224,7 +4226,7 @@ retry:
         * implementation of the compaction depends on the sufficient amount
         * of free memory (see __compaction_suitable)
         */
-       if (did_some_progress > 0 &&
+       if (did_some_progress > 0 && can_compact &&
                        should_compact_retry(ac, order, alloc_flags,
                                compact_result, &compact_priority,
                                &compaction_retries))