* [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
@ 2025-03-06 6:30 Dev Jain
2025-03-06 6:38 ` Andrew Morton
2025-03-06 8:18 ` Lorenzo Stoakes
0 siblings, 2 replies; 6+ messages in thread
From: Dev Jain @ 2025-03-06 6:30 UTC (permalink / raw)
To: akpm, Liam.Howlett, lorenzo.stoakes, vbabka, jannh, linux-mm,
linux-kernel
Cc: ryan.roberts, anshuman.khandual, aneesh.kumar, yang, david,
willy, hughd, ziy, Dev Jain
We already are registering private-anon VMAs with khugepaged during fault
time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
file vmas for khugepaged" moved the khugepaged registration logic from
shmem_mmap to the generic mmap path. Make this logic specific for non-anon
mappings.
Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
Signed-off-by: Dev Jain <dev.jain@arm.com>
---
mm/vma.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mm/vma.c b/mm/vma.c
index af1d549b179c..730a26bf14a5 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2377,7 +2377,8 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
* vma_merge_new_range() calls khugepaged_enter_vma() too, the below
* call covers the non-merge case.
*/
- khugepaged_enter_vma(vma, map->flags);
+ if (!vma_is_anonymous(vma))
+ khugepaged_enter_vma(vma, map->flags);
ksm_add_vma(vma);
*vmap = vma;
return 0;
--
2.30.2
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
2025-03-06 6:30 [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap Dev Jain
@ 2025-03-06 6:38 ` Andrew Morton
2025-03-06 7:44 ` Dev Jain
2025-03-06 8:18 ` Lorenzo Stoakes
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2025-03-06 6:38 UTC (permalink / raw)
To: Dev Jain
Cc: Liam.Howlett, lorenzo.stoakes, vbabka, jannh, linux-mm,
linux-kernel, ryan.roberts, anshuman.khandual, aneesh.kumar,
yang, david, willy, hughd, ziy
On Thu, 6 Mar 2025 12:00:37 +0530 Dev Jain <dev.jain@arm.com> wrote:
> We already are registering private-anon VMAs with khugepaged during fault
> time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
> file vmas for khugepaged" moved the khugepaged registration logic from
> shmem_mmap to the generic mmap path. Make this logic specific for non-anon
> mappings.
Please fully describe the userspace-visible effects of this bug.
> Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
> Signed-off-by: Dev Jain <dev.jain@arm.com>
Thanks, I'll add cc:stable.
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
2025-03-06 6:38 ` Andrew Morton
@ 2025-03-06 7:44 ` Dev Jain
0 siblings, 0 replies; 6+ messages in thread
From: Dev Jain @ 2025-03-06 7:44 UTC (permalink / raw)
To: Andrew Morton
Cc: Liam.Howlett, lorenzo.stoakes, vbabka, jannh, linux-mm,
linux-kernel, ryan.roberts, anshuman.khandual, aneesh.kumar,
yang, david, willy, hughd, ziy
On 06/03/25 12:08 pm, Andrew Morton wrote:
> On Thu, 6 Mar 2025 12:00:37 +0530 Dev Jain <dev.jain@arm.com> wrote:
>
>> We already are registering private-anon VMAs with khugepaged during fault
>> time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
>> file vmas for khugepaged" moved the khugepaged registration logic from
>> shmem_mmap to the generic mmap path. Make this logic specific for non-anon
>> mappings.
>
> Please fully describe the userspace-visible effects of this bug.
Apologies.
The userspace-visible effect should be this: khugepaged will
unnecessarily scan mm's which haven't yet faulted in. Note that it won't
actually collapse because all PTEs are none.
Now that I think about it, the mm is going to have a file VMA anyways
during fork+exec, so the mm already gets registered during mmap due to
the non-anon case (I *think*), so at least one of either the mmap
registration or fault-time registration is redundant.
>
>> Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>
> Thanks, I'll add cc:stable.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
2025-03-06 6:30 [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap Dev Jain
2025-03-06 6:38 ` Andrew Morton
@ 2025-03-06 8:18 ` Lorenzo Stoakes
2025-03-06 14:32 ` Dev Jain
1 sibling, 1 reply; 6+ messages in thread
From: Lorenzo Stoakes @ 2025-03-06 8:18 UTC (permalink / raw)
To: Dev Jain
Cc: akpm, Liam.Howlett, vbabka, jannh, linux-mm, linux-kernel,
ryan.roberts, anshuman.khandual, aneesh.kumar, yang, david,
willy, hughd, ziy
On Thu, Mar 06, 2025 at 12:00:37PM +0530, Dev Jain wrote:
> We already are registering private-anon VMAs with khugepaged during fault
> time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
> file vmas for khugepaged" moved the khugepaged registration logic from
> shmem_mmap to the generic mmap path. Make this logic specific for non-anon
> mappings.
This does sound reasonable, thanks! Though does need to be expanded as
Andrew says for user-visible effects just to be crystal clear.
>
> Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
> Signed-off-by: Dev Jain <dev.jain@arm.com>
> ---
> mm/vma.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vma.c b/mm/vma.c
> index af1d549b179c..730a26bf14a5 100644
> --- a/mm/vma.c
> +++ b/mm/vma.c
> @@ -2377,7 +2377,8 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
> * vma_merge_new_range() calls khugepaged_enter_vma() too, the below
> * call covers the non-merge case.
> */
> - khugepaged_enter_vma(vma, map->flags);
> + if (!vma_is_anonymous(vma))
> + khugepaged_enter_vma(vma, map->flags);
This really needs a comment :) as a Joe Bloggs coder coming to this my
immediate thought would be 'huh? Why?'
Something like:
/* Just added so khugepaged has nothing to do. We call again on fault. */
Would be great.
Thanks!
> ksm_add_vma(vma);
> *vmap = vma;
> return 0;
> --
> 2.30.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
2025-03-06 8:18 ` Lorenzo Stoakes
@ 2025-03-06 14:32 ` Dev Jain
2025-03-06 16:10 ` Lorenzo Stoakes
0 siblings, 1 reply; 6+ messages in thread
From: Dev Jain @ 2025-03-06 14:32 UTC (permalink / raw)
To: Lorenzo Stoakes
Cc: akpm, Liam.Howlett, vbabka, jannh, linux-mm, linux-kernel,
ryan.roberts, anshuman.khandual, aneesh.kumar, yang, david,
willy, hughd, ziy
On 06/03/25 1:48 pm, Lorenzo Stoakes wrote:
> On Thu, Mar 06, 2025 at 12:00:37PM +0530, Dev Jain wrote:
>> We already are registering private-anon VMAs with khugepaged during fault
>> time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
>> file vmas for khugepaged" moved the khugepaged registration logic from
>> shmem_mmap to the generic mmap path. Make this logic specific for non-anon
>> mappings.
>
> This does sound reasonable, thanks! Though does need to be expanded as
> Andrew says for user-visible effects just to be crystal clear.
Sure.
>
>>
>> Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
>> Signed-off-by: Dev Jain <dev.jain@arm.com>
>> ---
>> mm/vma.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/mm/vma.c b/mm/vma.c
>> index af1d549b179c..730a26bf14a5 100644
>> --- a/mm/vma.c
>> +++ b/mm/vma.c
>> @@ -2377,7 +2377,8 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
>> * vma_merge_new_range() calls khugepaged_enter_vma() too, the below
>> * call covers the non-merge case.
>> */
>> - khugepaged_enter_vma(vma, map->flags);
>> + if (!vma_is_anonymous(vma))
>> + khugepaged_enter_vma(vma, map->flags);
>
> This really needs a comment :) as a Joe Bloggs coder coming to this my
> immediate thought would be 'huh? Why?'
>
> Something like:
>
> /* Just added so khugepaged has nothing to do. We call again on fault. */
>
> Would be great.
>
> Thanks!
Sure.
BTW does this patch merit a CC:stable? I am not aware of the general
practice but I am not sure if this is a *serious bug*, as per
submitting-patches.rst.
>
>
>> ksm_add_vma(vma);
>> *vmap = vma;
>> return 0;
>> --
>> 2.30.2
>>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap
2025-03-06 14:32 ` Dev Jain
@ 2025-03-06 16:10 ` Lorenzo Stoakes
0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Stoakes @ 2025-03-06 16:10 UTC (permalink / raw)
To: Dev Jain
Cc: akpm, Liam.Howlett, vbabka, jannh, linux-mm, linux-kernel,
ryan.roberts, anshuman.khandual, aneesh.kumar, yang, david,
willy, hughd, ziy, Greg Kroah-Hartman
+cc Greg
On Thu, Mar 06, 2025 at 08:02:10PM +0530, Dev Jain wrote:
>
>
> On 06/03/25 1:48 pm, Lorenzo Stoakes wrote:
> > On Thu, Mar 06, 2025 at 12:00:37PM +0530, Dev Jain wrote:
> > > We already are registering private-anon VMAs with khugepaged during fault
> > > time, in do_huge_pmd_anonymous_page(). Commit "register suitable readonly
> > > file vmas for khugepaged" moved the khugepaged registration logic from
> > > shmem_mmap to the generic mmap path. Make this logic specific for non-anon
> > > mappings.
> >
> > This does sound reasonable, thanks! Though does need to be expanded as
> > Andrew says for user-visible effects just to be crystal clear.
>
> Sure.
Thanks!
>
> >
> > >
> > > Fixes: 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")
> > > Signed-off-by: Dev Jain <dev.jain@arm.com>
> > > ---
> > > mm/vma.c | 3 ++-
> > > 1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/mm/vma.c b/mm/vma.c
> > > index af1d549b179c..730a26bf14a5 100644
> > > --- a/mm/vma.c
> > > +++ b/mm/vma.c
> > > @@ -2377,7 +2377,8 @@ static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap)
> > > * vma_merge_new_range() calls khugepaged_enter_vma() too, the below
> > > * call covers the non-merge case.
> > > */
> > > - khugepaged_enter_vma(vma, map->flags);
> > > + if (!vma_is_anonymous(vma))
> > > + khugepaged_enter_vma(vma, map->flags);
> >
> > This really needs a comment :) as a Joe Bloggs coder coming to this my
> > immediate thought would be 'huh? Why?'
> >
> > Something like:
> >
> > /* Just added so khugepaged has nothing to do. We call again on fault. */
> >
> > Would be great.
> >
> > Thanks!
>
> Sure.
Thanks!
>
> BTW does this patch merit a CC:stable? I am not aware of the general
> practice but I am not sure if this is a *serious bug*, as per
> submitting-patches.rst.
I think it's fine to send 'not serious' bugs too :P I mean this is a perf
regression right? We don't want that in our stable kernels.
Unless Greg suggests otherwise (cc'd) I'd say it does merit it as there seems to
be no risk, only benefit and reduces overhead, so from my point of view seems
sensible.
>
> >
> >
> > > ksm_add_vma(vma);
> > > *vmap = vma;
> > > return 0;
> > > --
> > > 2.30.2
> > >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-03-06 16:11 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-06 6:30 [PATCH] mm/vma: Do not register private-anon mappings with khugepaged during mmap Dev Jain
2025-03-06 6:38 ` Andrew Morton
2025-03-06 7:44 ` Dev Jain
2025-03-06 8:18 ` Lorenzo Stoakes
2025-03-06 14:32 ` Dev Jain
2025-03-06 16:10 ` Lorenzo Stoakes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox