linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Barry Song <21cnbao@gmail.com>
Cc: Dev Jain <dev.jain@arm.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
	Suren Baghdasaryan <surenb@google.com>,
	Lokesh Gidra <lokeshgidra@google.com>,
	Tangquan Zheng <zhengtangquan@oppo.com>
Subject: Re: [PATCH RFC] mm: madvise: use walk_page_range_vma() for madvise_free_single_vma()
Date: Tue, 3 Jun 2025 14:15:16 +0200	[thread overview]
Message-ID: <0003a78b-e66f-41a5-9244-89c2c430cfa4@redhat.com> (raw)
In-Reply-To: <bd61e018-5fbb-4aac-8672-0c16254ba09e@lucifer.local>

On 03.06.25 11:41, Lorenzo Stoakes wrote:
> On Tue, Jun 03, 2025 at 08:47:04PM +1200, Barry Song wrote:
>> On Tue, Jun 3, 2025 at 6:11 PM Dev Jain <dev.jain@arm.com> wrote:
>>>
>>>
>>> On 03/06/25 7:01 am, Barry Song wrote:
>>>> From: Barry Song <v-songbaohua@oppo.com>
>>>>
>>>> We've already found the VMA before calling madvise_free_single_vma(),
>>>> so calling walk_page_range() and doing find_vma() again seems
>>>> unnecessary. It also prevents potential optimizations for MADV_FREE
>>>> to use a per-VMA lock.
>>>>
>>>> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
>>>> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
>>>> Cc: David Hildenbrand <david@redhat.com>
>>>> Cc: Vlastimil Babka <vbabka@suse.cz>
>>>> Cc: Jann Horn <jannh@google.com>
>>>> Cc: Suren Baghdasaryan <surenb@google.com>
>>>> Cc: Lokesh Gidra <lokeshgidra@google.com>
>>>> Cc: Tangquan Zheng <zhengtangquan@oppo.com>
>>>> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
>>>> ---
>>>>    mm/madvise.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/mm/madvise.c b/mm/madvise.c
>>>> index d408ffa404b3..c6a28a2d3ff8 100644
>>>> --- a/mm/madvise.c
>>>> +++ b/mm/madvise.c
>>>> @@ -826,7 +826,7 @@ static int madvise_free_single_vma(struct madvise_behavior *madv_behavior,
>>>>
>>>>        mmu_notifier_invalidate_range_start(&range);
>>>>        tlb_start_vma(tlb, vma);
>>>> -     walk_page_range(vma->vm_mm, range.start, range.end,
>>>> +     walk_page_range_vma(vma, range.start, range.end,
>>>>                        &madvise_free_walk_ops, tlb);
>>>>        tlb_end_vma(tlb, vma);
>>>>        mmu_notifier_invalidate_range_end(&range);
>>>
>>> Can similar optimizations be made in madvise_willneed(), madvise_cold_page_range(), etc?
>>
>> Yes, I think the same code flow applies to madvise_willneed,
>> madvise_cold_page_range, and similar functions, though my current
>> interest is more on madvise_free.
>>
>> Let me prepare a v2 that includes those as well.
> 
> FWIW Dev makes a great point here and I agree wholeheartedly, let's fix all such
> cases...
> 
> As an aside, I wonder if we previously didn't do this because we hadn't
> previously exposed the walk_page_range_vma() API or something?

IIRC, yes:

commit e07cda5f232fac4de0925d8a4c92e51e41fa2f6e
Author: David Hildenbrand <david@redhat.com>
Date:   Fri Oct 21 12:11:39 2022 +0200

     mm/pagewalk: add walk_page_range_vma()
     
     Let's add walk_page_range_vma(), which is similar to walk_page_vma(),
     however, is only interested in a subset of the VMA range.
     
     To be used in KSM code to stop using follow_page() next.


-- 
Cheers,

David / dhildenb



  reply	other threads:[~2025-06-03 12:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-03  1:31 Barry Song
2025-06-03  6:04 ` Anshuman Khandual
2025-06-03  6:11 ` Dev Jain
2025-06-03  8:47   ` Barry Song
2025-06-03  9:41     ` Lorenzo Stoakes
2025-06-03 12:15       ` David Hildenbrand [this message]
2025-06-03  7:44 ` David Hildenbrand
2025-06-03  8:16 ` Oscar Salvador
2025-06-03  9:40 ` Lorenzo Stoakes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0003a78b-e66f-41a5-9244-89c2c430cfa4@redhat.com \
    --to=david@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.com \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=surenb@google.com \
    --cc=v-songbaohua@oppo.com \
    --cc=vbabka@suse.cz \
    --cc=zhengtangquan@oppo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox