Message ID | 20240605095304.66389-1-alexs@kernel.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [RFC,1/3] mm/ksm: add anonymous check in find_mergeable_vma | expand |
On 6/5/24 5:56 PM, David Hildenbrand wrote: > On 05.06.24 11:53, alexs@kernel.org wrote: >> From: "Alex Shi (tencent)" <alexs@kernel.org> >> >> We do vma_set_anonyous in do_mmap(), and then vma_is_anonymous() >> checking workable, use it as a extra check since ksm only care anonymous >> pages. >> >> Signed-off-by: Alex Shi (tencent) <alexs@kernel.org> >> --- >> mm/ksm.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/mm/ksm.c b/mm/ksm.c >> index f5138f43f0d2..088bce39cd33 100644 >> --- a/mm/ksm.c >> +++ b/mm/ksm.c >> @@ -742,7 +742,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, >> if (ksm_test_exit(mm)) >> return NULL; >> vma = vma_lookup(mm, addr); >> - if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) >> + if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma || >> + !vma_is_anonymous(vma)) > > Doesn't KSM also apply to COW'ed pages in !anon mappings? At least that's what I recall. I didn't a evidence for this. :( In write_protect_page(), "PageAnonExclusive(&folio->page);" has a "VM_BUG_ON_PGFLAGS(!PageAnon(page), page);" So is this hints the vma also need to be anonymous one? Thanks a lot! Alex >
On 07.06.24 11:33, Alex Shi wrote: > > > On 6/5/24 5:56 PM, David Hildenbrand wrote: >> On 05.06.24 11:53, alexs@kernel.org wrote: >>> From: "Alex Shi (tencent)" <alexs@kernel.org> >>> >>> We do vma_set_anonyous in do_mmap(), and then vma_is_anonymous() >>> checking workable, use it as a extra check since ksm only care anonymous >>> pages. >>> >>> Signed-off-by: Alex Shi (tencent) <alexs@kernel.org> >>> --- >>> mm/ksm.c | 3 ++- >>> 1 file changed, 2 insertions(+), 1 deletion(-) >>> >>> diff --git a/mm/ksm.c b/mm/ksm.c >>> index f5138f43f0d2..088bce39cd33 100644 >>> --- a/mm/ksm.c >>> +++ b/mm/ksm.c >>> @@ -742,7 +742,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, >>> if (ksm_test_exit(mm)) >>> return NULL; >>> vma = vma_lookup(mm, addr); >>> - if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) >>> + if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma || >>> + !vma_is_anonymous(vma)) >> >> Doesn't KSM also apply to COW'ed pages in !anon mappings? At least that's what I recall. > I didn't a evidence for this. :( > > In write_protect_page(), "PageAnonExclusive(&folio->page);" has a "VM_BUG_ON_PGFLAGS(!PageAnon(page), page);" > So is this hints the vma also need to be anonymous one? vma_is_anonymous(vma) is restricted to anonymous folios and the shared zeropage, but other VMAs (MAP_PRIVATE file-backed VMAs) can contain anonymous folios as well.
diff --git a/mm/ksm.c b/mm/ksm.c index f5138f43f0d2..088bce39cd33 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -742,7 +742,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm, if (ksm_test_exit(mm)) return NULL; vma = vma_lookup(mm, addr); - if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) + if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma || + !vma_is_anonymous(vma)) return NULL; return vma; }