[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c24d7fdf-4c4b-4379-a538-ae5847bf57e9@redhat.com>
Date: Thu, 25 Sep 2025 11:33:39 +0200
From: David Hildenbrand <david@...hat.com>
To: Kiryl Shutsemau <kirill@...temov.name>, Dev Jain <dev.jain@....com>
Cc: akpm@...ux-foundation.org, lorenzo.stoakes@...cle.com,
Liam.Howlett@...cle.com, vbabka@...e.cz, rppt@...nel.org, surenb@...gle.com,
mhocko@...e.com, linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm: move rmap of mTHP upon CoW reuse
On 25.09.25 11:31, Kiryl Shutsemau wrote:
> On Thu, Sep 25, 2025 at 02:24:29PM +0530, Dev Jain wrote:
>> At wp-fault time, when we find that a folio is exclusively mapped, we move
>> folio->mapping to the faulting VMA's anon_vma, so that rmap overhead
>> reduces. This is currently done for small folios (base pages) and
>> PMD-mapped THPs. Do this for mTHP too.
>>
>> Signed-off-by: Dev Jain <dev.jain@....com>
>> ---
>> mm-selftests pass.
>>
>> mm/memory.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/mm/memory.c b/mm/memory.c
>> index 7e32eb79ba99..ec04d2cec6b1 100644
>> --- a/mm/memory.c
>> +++ b/mm/memory.c
>> @@ -4014,6 +4014,11 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio,
>> * an additional folio reference and never ended up here.
>> */
>> exclusive = true;
>> +
>> + if (folio_trylock(folio)) {
>> + folio_move_anon_rmap(folio, vma);
>> + folio_unlock(folio);
>> + }
>
> Maybe take the folio lock earlier in wp_can_reuse_anon_folio() to cover
> large folio handling too and avoid trylock here.
>
> Something like this (untest):
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 812a7d9f6531..d95cf670b6a8 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3843,6 +3843,7 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio,
> * an additional folio reference and never ended up here.
> */
> exclusive = true;
> + folio_move_anon_rmap(folio, vma);
> unlock:
> folio_unlock_large_mapcount(folio);
> return exclusive;
> @@ -3858,8 +3859,15 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio,
> static bool wp_can_reuse_anon_folio(struct folio *folio,
> struct vm_area_struct *vma)
> {
> - if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && folio_test_large(folio))
> - return __wp_can_reuse_large_anon_folio(folio, vma);
> + bool exclusive = false;
> +
> + if (!folio_trylock(folio))
> + return false;
No, there is no need for that.
--
Cheers
David / dhildenb
Powered by blists - more mailing lists