Re: [PATCH v2 1/1] mm: skip mlocked THPs that are underused early in deferred_split_scan()

Lance Yang
2025-09-08T11:33:13Z

On 2025/9/8 18:38, Kiryl Shutsemau wrote:
> On Mon, Sep 08, 2025 at 05:07:41PM +0800, Lance Yang wrote:
>> From: Lance Yang <lance.yang@linux.dev>
>>
>> When we stumble over a fully-mapped mlocked THP in the deferred shrinker,
>> it does not make sense to try to detect whether it is underused, because
>> try_to_map_unused_to_zeropage(), called while splitting the folio, will not
>> actually replace any zeroed pages by the shared zeropage.
>
> It makes me think, does KSM follows the same logic as
> try_to_map_unused_to_zeropage()?
>
> I cannot immediately find what prevents KSM from replacing zeroed mlocked
> folio with ZERO_PAGE().
>
> Hm?

Good catch!

Surprisingly, my test shows that KSM is indeed able to replace a zeroed
mlocked THP with ZERO_PAGE(). And MADV_MERGEABLE allows a VMA to be marked
as mergeable even if it's already locked(VM_LOCKED) ...