From: Brendan Jackman <jackmanb@google.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] mm: page_alloc: don't steal single pages from biggest buddy
Date: Tue, 25 Feb 2025 13:34:32 +0000 [thread overview]
Message-ID: <Z73G6A6asz_KrGTo@google.com> (raw)
In-Reply-To: <20250225001023.1494422-2-hannes@cmpxchg.org>
On Mon, Feb 23, 2025 at 07:08:24PM -0500, Johannes Weiner wrote:
> The fallback code searches for the biggest buddy first in an attempt
> to steal the whole block and encourage type grouping down the line.
>
> The approach used to be this:
>
> - Non-movable requests will split the largest buddy and steal the
> remainder. This splits up contiguity, but it allows subsequent
> requests of this type to fall back into adjacent space.
>
> - Movable requests go and look for the smallest buddy instead. The
> thinking is that movable requests can be compacted, so grouping is
> less important than retaining contiguity.
>
> c0cd6f557b90 ("mm: page_alloc: fix freelist movement during block
> conversion") enforces freelist type hygiene, which restricts stealing
> to either claiming the whole block or just taking the requested chunk;
> no additional pages or buddy remainders can be stolen any more.
>
> The patch mishandled when to switch to finding the smallest buddy in
> that new reality. As a result, it may steal the exact request size,
> but from the biggest buddy. This causes fracturing for no good reason.
>
> Fix this by committing to the new behavior: either steal the whole
> block, or fall back to the smallest buddy.
>
> Remove single-page stealing from steal_suitable_fallback(). Rename it
> to try_to_steal_block() to make the intentions clear. If this fails,
> always fall back to the smallest buddy.
Nit - I think the try_to_steal_block() changes could be a separate
patch, the history might be easier to understand if it went:
[1/N] mm: page_alloc: don't steal single pages from biggest buddy
[2/N] mm: page_alloc: drop unused logic in steal_suitable_fallback()
(But not a big deal, it's not that hard to follow as-is).
> static __always_inline struct page *
> __rmqueue_fallback(struct zone *zone, int order, int start_migratetype,
> @@ -2291,45 +2289,35 @@ __rmqueue_fallback(struct zone *zone, int order, int start_migratetype,
> if (fallback_mt == -1)
> continue;
>
> - /*
> - * We cannot steal all free pages from the pageblock and the
> - * requested migratetype is movable. In that case it's better to
> - * steal and split the smallest available page instead of the
> - * largest available page, because even if the next movable
> - * allocation falls back into a different pageblock than this
> - * one, it won't cause permanent fragmentation.
> - */
> - if (!can_steal && start_migratetype == MIGRATE_MOVABLE
> - && current_order > order)
> - goto find_smallest;
> + if (!can_steal)
> + break;
>
> - goto do_steal;
> + page = get_page_from_free_area(area, fallback_mt);
> + page = try_to_steal_block(zone, page, current_order, order,
> + start_migratetype, alloc_flags);
> + if (page)
> + goto got_one;
> }
>
> - return NULL;
> + if (alloc_flags & ALLOC_NOFRAGMENT)
> + return NULL;
Is this a separate change? Is it a bug that we currently allow
stealing a from a fallback type when ALLOC_NOFRAGMENT? (I wonder if
the second loop was supposed to start from min_order).
>
> -find_smallest:
> + /* No luck stealing blocks. Find the smallest fallback page */
> for (current_order = order; current_order < NR_PAGE_ORDERS; current_order++) {
> area = &(zone->free_area[current_order]);
> fallback_mt = find_suitable_fallback(area, current_order,
> start_migratetype, false, &can_steal);
> - if (fallback_mt != -1)
> - break;
> - }
> -
> - /*
> - * This should not happen - we already found a suitable fallback
> - * when looking for the largest page.
> - */
> - VM_BUG_ON(current_order > MAX_PAGE_ORDER);
> + if (fallback_mt == -1)
> + continue;
>
> -do_steal:
> - page = get_page_from_free_area(area, fallback_mt);
> + page = get_page_from_free_area(area, fallback_mt);
> + page_del_and_expand(zone, page, order, current_order, fallback_mt);
> + goto got_one;
> + }
>
> - /* take off list, maybe claim block, expand remainder */
> - page = steal_suitable_fallback(zone, page, current_order, order,
> - start_migratetype, alloc_flags, can_steal);
> + return NULL;
>
> +got_one:
> trace_mm_page_alloc_extfrag(page, order, current_order,
> start_migratetype, fallback_mt);
next prev parent reply other threads:[~2025-02-25 13:34 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-25 0:08 [PATCH 0/3] mm: page_alloc: freelist hygiene follow-up Johannes Weiner
2025-02-25 0:08 ` [PATCH 1/3] mm: page_alloc: don't steal single pages from biggest buddy Johannes Weiner
2025-02-25 10:50 ` Vlastimil Babka
2025-02-25 13:34 ` Brendan Jackman [this message]
2025-02-25 14:35 ` Vlastimil Babka
2025-02-25 14:40 ` Brendan Jackman
2025-02-25 15:04 ` Johannes Weiner
2025-02-25 0:08 ` [PATCH 2/3] mm: page_alloc: remove remnants of unlocked migratetype updates Johannes Weiner
2025-02-25 11:01 ` Vlastimil Babka
2025-02-25 13:43 ` Brendan Jackman
2025-02-25 15:09 ` Johannes Weiner
2025-02-25 15:19 ` Brendan Jackman
2025-02-25 0:08 ` [PATCH 3/3] mm: page_alloc: group fallback functions together Johannes Weiner
2025-02-25 11:02 ` Vlastimil Babka
2025-02-26 8:51 ` Vlastimil Babka
2025-02-25 13:50 ` Brendan Jackman
2025-02-25 15:14 ` Johannes Weiner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z73G6A6asz_KrGTo@google.com \
--to=jackmanb@google.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox