]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/page_alloc: don't overload migratetype in find_suitable_fallback()
authorBrendan Jackman <jackmanb@google.com>
Wed, 13 May 2026 12:35:14 +0000 (12:35 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 2 Jun 2026 22:22:19 +0000 (15:22 -0700)
This function currently returns a signed integer that encodes status
in-band, as negative numbers, along with a migratetype.  Switch to a more
explicit/verbose style that encodes the status and migratetype separately.

In the spirit of making things more explicit, also create an enum to avoid
using magic integer literals with special meanings.  This enables
documenting the values at their definition instead of in one of the
callers.

Link: https://lore.kernel.org/20260513-page_alloc-unmapped-prep-v1-2-dacdf5402be8@google.com
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/compaction.c
mm/internal.h
mm/page_alloc.c

index 3648ce22c80728b894cffce502d8caa3e4532406..168e63940b78247e08aef8b177a4c68adb36db31 100644 (file)
@@ -2340,7 +2340,8 @@ static enum compact_result __compact_finished(struct compact_control *cc)
                 * Job done if allocation would steal freepages from
                 * other migratetype buddy lists.
                 */
-               if (find_suitable_fallback(area, order, migratetype, true) >= 0)
+               if (find_suitable_fallback(area, order, migratetype, true, NULL)
+                   == FALLBACK_FOUND)
                        /*
                         * Movable pages are OK in any pageblock. If we are
                         * stealing for a non-movable allocation, make sure
index 5a2ddcf68e0b6d1a9fbaeae07670dd252729f96a..09931b1e535f3f71887b5b6473f93ed21a41c7e7 100644 (file)
@@ -1104,9 +1104,17 @@ static inline void init_cma_pageblock(struct page *page)
 }
 #endif
 
-
-int find_suitable_fallback(struct free_area *area, unsigned int order,
-                          int migratetype, bool claimable);
+enum fallback_result {
+       /* Found suitable migratetype, *mt_out is valid. */
+       FALLBACK_FOUND,
+       /* No fallback found in requested order. */
+       FALLBACK_EMPTY,
+       /* Passed @claimable, but claiming whole block is a bad idea. */
+       FALLBACK_NOCLAIM,
+};
+enum fallback_result
+find_suitable_fallback(struct free_area *area, unsigned int order,
+                      int migratetype, bool claimable, int *mt_out);
 
 static inline bool free_area_empty(struct free_area *area, int migratetype)
 {
index 69a99af7777718eefd7b2642777a25ab186ca723..3e4c4af06f3705800e5970f9d35cec072d2036b3 100644 (file)
@@ -2259,25 +2259,29 @@ static bool should_try_claim_block(unsigned int order, int start_mt)
  * we would do this whole-block claiming. This would help to reduce
  * fragmentation due to mixed migratetype pages in one pageblock.
  */
-int find_suitable_fallback(struct free_area *area, unsigned int order,
-                          int migratetype, bool claimable)
+enum fallback_result
+find_suitable_fallback(struct free_area *area, unsigned int order,
+                      int migratetype, bool claimable, int *mt_out)
 {
        int i;
 
        if (claimable && !should_try_claim_block(order, migratetype))
-               return -2;
+               return FALLBACK_NOCLAIM;
 
        if (area->nr_free == 0)
-               return -1;
+               return FALLBACK_EMPTY;
 
        for (i = 0; i < MIGRATE_PCPTYPES - 1 ; i++) {
                int fallback_mt = fallbacks[migratetype][i];
 
-               if (!free_area_empty(area, fallback_mt))
-                       return fallback_mt;
+               if (!free_area_empty(area, fallback_mt)) {
+                       if (mt_out)
+                               *mt_out = fallback_mt;
+                       return FALLBACK_FOUND;
+               }
        }
 
-       return -1;
+       return FALLBACK_EMPTY;
 }
 
 /*
@@ -2387,16 +2391,16 @@ __rmqueue_claim(struct zone *zone, int order, int start_migratetype,
         */
        for (current_order = MAX_PAGE_ORDER; current_order >= min_order;
                                --current_order) {
+               enum fallback_result result;
+
                area = &(zone->free_area[current_order]);
-               fallback_mt = find_suitable_fallback(area, current_order,
-                                                    start_migratetype, true);
+               result = find_suitable_fallback(area, current_order,
+                                               start_migratetype, true, &fallback_mt);
 
-               /* No block in that order */
-               if (fallback_mt == -1)
+               if (result == FALLBACK_EMPTY)
                        continue;
 
-               /* Advanced into orders too low to claim, abort */
-               if (fallback_mt == -2)
+               if (result == FALLBACK_NOCLAIM)
                        break;
 
                page = get_page_from_free_area(area, fallback_mt);
@@ -2426,10 +2430,12 @@ __rmqueue_steal(struct zone *zone, int order, int start_migratetype)
        int fallback_mt;
 
        for (current_order = order; current_order < NR_PAGE_ORDERS; current_order++) {
+               enum fallback_result result;
+
                area = &(zone->free_area[current_order]);
-               fallback_mt = find_suitable_fallback(area, current_order,
-                                                    start_migratetype, false);
-               if (fallback_mt == -1)
+               result = find_suitable_fallback(area, current_order, start_migratetype,
+                                               false, &fallback_mt);
+               if (result == FALLBACK_EMPTY)
                        continue;
 
                page = get_page_from_free_area(area, fallback_mt);