The patch titled Subject: mm/page_alloc: clarify should_claim_block() commentary has been added to the -mm mm-unstable branch. Its filename is mm-page_alloc-clarify-should_claim_block-commentary.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-page_alloc-clarify-should_claim_block-commentary.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Brendan Jackman <jackmanb@xxxxxxxxxx> Subject: mm/page_alloc: clarify should_claim_block() commentary Date: Tue, 25 Feb 2025 15:29:49 +0000 There's lots of text here but it's a little hard to follow, this is an attempt to break it up and align its structure more closely with the code. Reword the top-level function comment to just explain what question the function answers from the point of view of the caller. Break up the internal logic into different sections that can have their own commentary describing why that part of the rationale is present. Note the page_groupy_by_mobility_disabled logic is not explained in the commentary, that is outside the scope of this patch... Link: https://lkml.kernel.org/r/20250225-clarify-steal-v3-2-f2550ead0139@xxxxxxxxxx Signed-off-by: Brendan Jackman <jackmanb@xxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Mel Gorman <mgorman@xxxxxxxxxxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Cc: Yosry Ahmed <yosry.ahmed@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/page_alloc.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) --- a/mm/page_alloc.c~mm-page_alloc-clarify-should_claim_block-commentary +++ a/mm/page_alloc.c @@ -1941,16 +1941,9 @@ static inline bool boost_watermark(struc } /* - * When we are falling back to another migratetype during allocation, try to - * claim entire blocks to satisfy further allocations, instead of polluting - * multiple pageblocks. - * - * If we are stealing a relatively large buddy page, it is likely there will be - * more free pages in the pageblock, so try to claim the whole block. For - * reclaimable and unmovable allocations, we claim the whole block regardless of - * page size, as fragmentation caused by those allocations polluting movable - * pageblocks is worse than movable allocations stealing from unmovable and - * reclaimable pageblocks. + * When we are falling back to another migratetype during allocation, should we + * try to claim an entire block to satisfy further allocations, instead of + * polluting multiple pageblocks? */ static bool should_claim_block(unsigned int order, int start_mt) { @@ -1965,6 +1958,26 @@ static bool should_claim_block(unsigned return true; /* + * Above a certain threshold, always try to claim, as it's likely there + * will be more free pages in the pageblock. + */ + if (order >= pageblock_order / 2) + return true; + + /* + * Unmovable/reclaimable allocations would cause permanent + * fragmentations if they fell back to allocating from a movable block + * (polluting it), so we try to claim the whole block regardless of the + * allocation size. Later movable allocations can always steal from this + * block, which is less problematic. + */ + if (start_mt == MIGRATE_RECLAIMABLE || start_mt == MIGRATE_UNMOVABLE) + return true; + + if (page_group_by_mobility_disabled) + return true; + + /* * Movable pages won't cause permanent fragmentation, so when you alloc * small pages, you just need to temporarily steal unmovable or * reclaimable pages that are closest to the request size. After a @@ -1972,12 +1985,6 @@ static bool should_claim_block(unsigned * and the next movable allocation may not need to steal. Unmovable and * reclaimable allocations need to actually claim the whole block. */ - if (order >= pageblock_order / 2 || - start_mt == MIGRATE_RECLAIMABLE || - start_mt == MIGRATE_UNMOVABLE || - page_group_by_mobility_disabled) - return true; - return false; } _ Patches currently in -mm which might be from jackmanb@xxxxxxxxxx are mm-mmu_gather-update-comment-on-rcu-freeing.patch selftests-mm-report-errno-when-things-fail-in-gup_longterm.patch selftests-mm-fix-assumption-that-sudo-is-present.patch selftests-mm-skip-uffd-stress-if-userfaultfd-not-available.patch selftests-mm-skip-uffd-wp-mremap-if-userfaultfd-not-available.patch selftests-mm-uffd-rename-nr_cpus-nr_threads.patch selftests-mm-print-some-details-when-uffd-stress-gets-bad-params.patch selftests-mm-dont-fail-uffd-stress-if-too-many-cpus.patch selftests-mm-skip-map_populate-on-weird-filesystems.patch selftests-mm-skip-gup_longerm-tests-on-weird-filesystems.patch mm-page_alloc-warn-on-nr_reserved_highatomic-underflow.patch mm-page_alloc-clarify-terminology-in-migratetype-fallback-code.patch mm-page_alloc-clarify-should_claim_block-commentary.patch scripts-gdb-add-lx_per_cpu_ptr.patch