Re: [PATCH v3] mm/huge_memory: prevent losing PG_waiters in __split_folio_to_order()

From: David Hildenbrand (Arm)

Date: Tue Nov 10 2026 - 14:17:26 EST


On 11/10/26 18:03, Zi Yan wrote:
> On 10 Nov 2026, at 6:31, David Hildenbrand (Arm) wrote:
>
>> On 11/9/26 22:05, Zi Yan wrote:
>>>
>>>
>>> This is V3 of the patch. Instead of using prep_compound_page_atomic(),
>>> PG_head is written before clear_compound_page(), after which new_head
>>> is visible to the reference-less writers.
>>
>> I'm confused, how is it then valid to have PG_waiters set concurrently while we
>> read new_folio->flags.f? Because that's what your comment states.
>>
>>>
>>>
>>> IMHO, memory_failure()’s reference-less access violates the frozen
>>> page contract and should be fixed.
>>
>> Exactly.
>>
>>> But I do not think it needs to go
>>> along with this patch. We discussed HWPoison flag race with
>>> Michael S. Tsirkin and Miaohe before [1]:
>>>
>>> 1. Miaohe proposed to reset HWPoison in memory_failure() as a best effort,
>>> 2. mst used RCU for all non-atomic flag accesses,
>>> 3. you also proposed to move HWPoison out of ->flags.
>>>
>>> So memory_failure() needs a separate and proper fix series after
>>> we decide the right solution.
>>>
>>
>> Vlasta raised the idea to set hwpoison only after we actually managed to
>> isolate/grab the page. Which might be the proper fix.
>
> I was bouncing the same idea with LLM yesterday, but it does not solve
> all cases:
>
> 1. normal page: taking a ref just prevents it from going to be a free page,
> but atomically set PG_hwpoison can still be lost when another one uses
> a plain write, __folio_set/clear_*().
> 2. free page: isolating works if the free page on its free list, but it
> could be on pcplist and we then need to drain all pcplists. That could
> hurt performance.

We can make memory failure slow.

> 3. we cannot take a ref on slab page and other frozen pages, then we will
> need a case by case handling for them.

Yes, we need some way to isolate them, or to sync with them.

>
> Anyway, this probably belongs a separate discussion on hwpoison.
Yes, memory-failure is the last of our priority right now when it comes to
fixing things.

--
Cheers,

David