Re: [PATCH] mm/page_isolation: don't putback unisolated page
From: Miaohe Lin
Date: Mon Sep 06 2021 - 08:08:58 EST
On 2021/9/6 20:01, David Hildenbrand wrote:
> On 06.09.21 13:50, David Hildenbrand wrote:
>> On 06.09.21 13:32, Miaohe Lin wrote:
>>> On 2021/9/6 17:40, David Hildenbrand wrote:
>>>> On 04.09.21 11:18, Miaohe Lin wrote:
>>>>> If __isolate_free_page() failed, due to zone watermark check, the page is
>>>>> still on the free list. But this page will be put back to free list again
>>>>> via __putback_isolated_page() now. This may trigger page->flags checks in
>>>>> __free_one_page() if PageReported is set. Or we will corrupt the free list
>>>>> because list_add() will be called for pages already on another list.
>>>>>
>>>>> Fixes: 3c605096d315 ("mm/page_alloc: restrict max order of merging on isolated pageblock")
>>>>> Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx>
>>>>> ---
>>>>> mm/page_isolation.c | 6 ++----
>>>>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
>>>>> index 9bb562d5d194..7d70d772525c 100644
>>>>> --- a/mm/page_isolation.c
>>>>> +++ b/mm/page_isolation.c
>>>>> @@ -93,10 +93,8 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>>>>> buddy_pfn = __find_buddy_pfn(pfn, order);
>>>>> buddy = page + (buddy_pfn - pfn);
>>>>> - if (!is_migrate_isolate_page(buddy)) {
>>>>> - __isolate_free_page(page, order);
>>>>> - isolated_page = true;
>>>>> - }
>>>>> + if (!is_migrate_isolate_page(buddy))
>>>>> + isolated_page = !!__isolate_free_page(page, order);
>>>>> }
>>>>> }
>>>>>
>>>>
>>>> Shouldn't we much rather force to ignore watermarks here and make sure __isolate_free_page() never fails?
>>>
>>> It seems it is not easy to force to ignore watermarks here. And it's not a problem
>>> if __isolate_free_page() fails because we can do move_freepages_block() anyway.
>>> What do you think? Many thanks.
>>
>> I'm wondering if all this complexity in this function is even required. What about something like this: (completely untested)
>>
>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c
>> index bddf788f45bf..29ff2fcb339c 100644
>> --- a/mm/page_isolation.c
>> +++ b/mm/page_isolation.c
>> @@ -66,12 +66,10 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_
>> static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>> {
>> + bool buddy_merge_possible = false;
>> struct zone *zone;
>> unsigned long flags, nr_pages;
>> - bool isolated_page = false;
>> unsigned int order;
>> - unsigned long pfn, buddy_pfn;
>> - struct page *buddy;
>> zone = page_zone(page);
>> spin_lock_irqsave(&zone->lock, flags);
>> @@ -79,26 +77,15 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>> goto out;
>> /*
>> - * Because freepage with more than pageblock_order on isolated
>> - * pageblock is restricted to merge due to freepage counting problem,
>> - * it is possible that there is free buddy page.
>> - * move_freepages_block() doesn't care of merge so we need other
>> - * approach in order to merge them. Isolation and free will make
>> - * these pages to be merged.
>> + * If our free page spans at least this whole pageblock and could
>> + * eventually get merged into an even bigger page, go via
>> + * __putback_isolated_page(), because move_freepages_block() won't
>> + * trigger merging of free pages.
>> */
>> if (PageBuddy(page)) {
>> order = buddy_order(page);
>> - if (order >= pageblock_order && order < MAX_ORDER - 1) {
>> - pfn = page_to_pfn(page);
>> - buddy_pfn = __find_buddy_pfn(pfn, order);
>> - buddy = page + (buddy_pfn - pfn);
>> -
>> - if (pfn_valid_within(buddy_pfn) &&
>> - !is_migrate_isolate_page(buddy)) {
>> - __isolate_free_page(page, order);
>> - isolated_page = true;
>> - }
>> - }
>> + if (order >= pageblock_order && order < MAX_ORDER - 1)
>> + buddy_merge_possible = true;
>> }
>> /*
>> @@ -111,12 +98,12 @@ static void unset_migratetype_isolate(struct page *page, unsigned migratetype)
>> * onlining - just onlined memory won't immediately be considered for
>> * allocation.
>> */
>> - if (!isolated_page) {
>> + if (!buddy_merge_possible) {
>> nr_pages = move_freepages_block(zone, page, migratetype, NULL);
>> __mod_zone_freepage_state(zone, nr_pages, migratetype);
>> }
>> set_pageblock_migratetype(page, migratetype);
>> - if (isolated_page)
>> + if (buddy_merge_possible)
>> __putback_isolated_page(page, order, migratetype);
>> zone->nr_isolate_pageblock--;
>> out:
>
> Okay, I just had another look -- that won't work because as you correctly said, it still is on the freelist ...
>
> So your fix is certainly correct :)
Many thanks for your effort and suggestion. :)
>