Commit 4805ef3
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>1 parent 5ce1dbf commit 4805ef3
1 file changed
+8
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2090 | 2090 | | |
2091 | 2091 | | |
2092 | 2092 | | |
2093 | | - | |
| 2093 | + | |
2094 | 2094 | | |
2095 | 2095 | | |
| 2096 | + | |
2096 | 2097 | | |
2097 | 2098 | | |
2098 | 2099 | | |
| |||
2107 | 2108 | | |
2108 | 2109 | | |
2109 | 2110 | | |
2110 | | - | |
2111 | | - | |
2112 | | - | |
2113 | | - | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
2114 | 2115 | | |
2115 | 2116 | | |
2116 | 2117 | | |
2117 | | - | |
| 2118 | + | |
2118 | 2119 | | |
2119 | | - | |
| 2120 | + | |
2120 | 2121 | | |
2121 | 2122 | | |
2122 | 2123 | | |
2123 | | - | |
2124 | | - | |
2125 | | - | |
2126 | | - | |
2127 | | - | |
2128 | | - | |
2129 | | - | |
2130 | | - | |
2131 | | - | |
2132 | | - | |
2133 | 2124 | | |
2134 | 2125 | | |
2135 | 2126 | | |
| |||
0 commit comments