Files
linux/mm
Wei Yang 4805ef3707 mm/page_alloc: check the correct buddy if it is a starting block
find_large_buddy() search buddy based on start_pfn, which maybe different
from page's pfn, e.g.  when page is not pageblock aligned, because
prep_move_freepages_block() always align start_pfn to pageblock.

This means when we found a starting block at start_pfn, it may check on
the wrong page theoretically.  And not split the free page as it is
supposed to, causing a freelist migratetype mismatch.

The good news is the page passed to __move_freepages_block_isolate() has
only two possible cases:

  * page is pageblock aligned
  * page is __first_valid_page() of this block

So it is safe for the first case, and it won't get a buddy larger than
pageblock for the second case.

To fix the issue, check the returned pfn of find_large_buddy() to decide
whether to split the free page:

  1. if it is not a PageBuddy pfn, no split;
  2. if it is a PageBuddy pfn but order <= pageblock_order, no split;
  3. if it is a PageBuddy pfn with order > pageblock_order, start_pfn is
     either in the starting block or tail block, split the PageBuddy at
     pageblock_order level.

Link: https://lkml.kernel.org/r/20250905140358.28849-1-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2025-09-21 14:22:21 -07:00
..
2025-09-21 14:22:09 -07:00
2025-06-05 22:02:25 -07:00
2024-11-03 01:28:06 -05:00
2025-08-02 12:06:09 -07:00
2025-09-21 14:21:59 -07:00
2025-09-21 14:22:00 -07:00
2025-09-13 16:54:50 -07:00
2025-09-13 16:54:58 -07:00
2025-09-13 16:55:07 -07:00
2025-08-02 12:06:09 -07:00
2025-09-13 16:54:46 -07:00
2024-07-10 12:14:54 -07:00
2025-09-13 16:55:08 -07:00
2025-09-13 16:55:08 -07:00
2025-09-13 16:55:07 -07:00
2025-09-13 16:55:02 -07:00
2025-09-13 16:55:02 -07:00
2025-09-13 16:55:20 -07:00
2025-09-13 16:55:07 -07:00
2025-09-21 14:21:59 -07:00