mm/vma: Do not register private-anon mappings with khugepaged during mmap
Subsystems (2)
PATCH 1/1 mm/vma: Do not register private-anon mappings with khugepaged during mmap
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.
--- mm/vma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mm/vma.c +2 -1
@@ -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 ;
Signature · 1 line
2.30.2
Andrew Morton
maintainerQuoted 5 lines · On Thu, 6 Mar 2025 12:00:37 +0530 Dev Jain <[email protected]> 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 fromshmem_mmapto the generic mmap path. Make this logic specific for non-anon mappings.
Please fully describe the userspace-visible effects of this bug.
Quoted 2 lines
Fixes 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")Signed-off-by Dev Jain <[email protected]>
Thanks, I'll add cc:stable.
Quoted 9 lines · Andrew Morton
Quoted 5 lines · On Thu, 6 Mar 2025 12:00:37 +0530 Dev Jain <[email protected]> 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 fromshmem_mmapto 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.
Quoted 5 lines
Quoted 3 lines
Fixes 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")Signed-off-by Dev Jain <[email protected]>Thanks, I'll add cc:stable.
Quoted 5 lines · 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 fromshmem_mmapto 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.
Quoted 12 lines
Fixes 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")Signed-off-by Dev Jain <[email protected]>--- mm/vma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vma.c +0
-0
mm/vma.c static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) · line 2381
Quoted 6 lines
mm/vma.c +2
-1@@ -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!
Quoted 6 lines
mm/vma.c +0
-1ksm_add_vma (vma); *vmap = vma;return 0 ; --2.30.2
Quoted 9 lines · Lorenzo Stoakes
Quoted 5 lines · 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 fromshmem_mmapto 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.
Quoted 23 lines
Quoted 13 lines
Fixes 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")Signed-off-by Dev Jain <[email protected]>--- mm/vma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vma.c +0
-0mm/vma.c static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) · line 2381
Quoted 6 lines
mm/vma.c +2
-1@@ -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?'
Quoted 7 lines
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.
Quoted 8 lines
Quoted 8 lines
mm/vma.c +0
-1ksm_add_vma (vma); *vmap = vma;return 0 ; --2.30.2
+cc Greg
Quoted 10 lines · Dev Jain
Quoted 7 lines · Lorenzo Stoakes
Quoted 5 lines · 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 fromshmem_mmapto the generic mmap path. Make this logic specific for non-anon mappings.
Quoted 4 lines
Quoted 2 lines
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!
Quoted 26 lines
Quoted 26 lines
Quoted 14 lines
Fixes 613bec092fe7 ("mm: mmap: register suitable readonly file vmas for khugepaged")Signed-off-by Dev Jain <[email protected]>--- mm/vma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)mm/vma.c +0
-0mm/vma.c static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) · line 2381
Quoted 6 lines
mm/vma.c +2
-1@@ -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:
Quoted 7 lines
Quoted 5 lines
/* Just added so khugepaged has nothing to do. We call again on fault. */Would be great.
Thanks!
Sure.
Thanks!
Quoted 4 lines
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.
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
mm/vma.c +0
-1ksm_add_vma (vma); *vmap = vma;return 0 ; --2.30.2