Re: [RFC] mm: restrict zero-page remapping to underused THP splits

From: Lance Yang

Date: Thu May 14 2026 - 04:12:37 EST



On Tue, May 12, 2026 at 09:02:38PM +0200, David Hildenbrand (Arm) wrote:
>On 5/12/26 20:36, Nico Pache wrote:
>> On Tue, May 12, 2026 at 1:05 AM David Hildenbrand (Arm)
>> <david@xxxxxxxxxx> wrote:
>>>
>>> On 5/11/26 20:40, Nico Pache wrote:
>>>>
>>>> And what was the expected behavior before this commit? Did we just
>>>> deal with the wasted memory?
>>>
>>> Before your change, splitting will always free memory, no matter who triggers
>>> splitting. So there is no wasted memory (regarding underused THPs).
>>>
>>> With your change, if we happen to split before the deferred shrinker runs, we
>>> end up with zero-filled pages that waste memory. And reclaiming them (through
>>> the deferred shrinker) first requires another re-collapse to a THP.
>>>
>>> Or am I misunderstanding your question?
>>
>> I meant before b1f202060afe ("mm: remap unused subpages to shared
>> zeropage when splitting isolated thp"). Sorry, I should have been more
>> specific.
>>
>> As in before the underutilized shrinker (and commit b1f202060afe), we
>> had the exact problem you describe above and no way to handle it.
>> Correct?
>
>Right. That's why the underused shrinker was added, to directly free pages that
>have been over-allocated with a THP, but are actually never "used" (remain zero).
>
>>
>> I guess at reclaim THPs would be split and we would swap out a zero filled page?
>We don't necessarily split during swapout, we try to swap out the THP if
>supported. But yes, that can happen.
>
>I'm more thinking about other reasons to split a THP (e.g., migration, partial
>MADV_PAGEOUT/MADV_COLD/MADV_FREE), where the behavior would be changed.

Yeah. Today any successful anon split gets TTU_USE_SHARED_ZEROPAGE. Would
it be better to make KSM opt out, so other split paths keep the behavior
they have today?

That way we do not have to worry about changing anything else at the
same time :D

Cheers, Lance