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

From: David Hildenbrand (Arm)

Date: Tue May 12 2026 - 15:02:50 EST


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.

--
Cheers,

David