From: Chengming Zhou <chengming.zhou@linux.dev>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
"Liam R . Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
Pedro Falcato <pfalcato@suse.de>,
David Hildenbrand <david@redhat.com>,
Xu Xin <xu.xin16@zte.com.cn>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 1/4] mm: ksm: have KSM VMA checks not require a VMA pointer
Date: Tue, 20 May 2025 11:14:25 +0800 [thread overview]
Message-ID: <c5feb16f-d524-42ce-bdf0-f09a9ca4ccda@linux.dev> (raw)
In-Reply-To: <daf12021354ce7302ad90b42790d8776173b3a81.1747431920.git.lorenzo.stoakes@oracle.com>
On 2025/5/19 16:51, Lorenzo Stoakes wrote:
> In subsequent commits we are going to determine KSM eligibility prior to a
> VMA being constructed, at which point we will of course not yet have access
> to a VMA pointer.
>
> It is trivial to boil down the check logic to be parameterised on
> mm_struct, file and VMA flags, so do so.
>
> As a part of this change, additionally expose and use file_is_dax() to
> determine whether a file is being mapped under a DAX inode.
>
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Looks good to me.
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Thanks!
> ---
> include/linux/fs.h | 7 ++++++-
> mm/ksm.c | 32 ++++++++++++++++++++------------
> 2 files changed, 26 insertions(+), 13 deletions(-)
>
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 09c8495dacdb..e1397e2b55ea 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -3691,9 +3691,14 @@ void setattr_copy(struct mnt_idmap *, struct inode *inode,
>
> extern int file_update_time(struct file *file);
>
> +static inline bool file_is_dax(const struct file *file)
> +{
> + return file && IS_DAX(file->f_mapping->host);
> +}
> +
> static inline bool vma_is_dax(const struct vm_area_struct *vma)
> {
> - return vma->vm_file && IS_DAX(vma->vm_file->f_mapping->host);
> + return file_is_dax(vma->vm_file);
> }
>
> static inline bool vma_is_fsdax(struct vm_area_struct *vma)
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 8583fb91ef13..08d486f188ff 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -677,28 +677,33 @@ static int break_ksm(struct vm_area_struct *vma, unsigned long addr, bool lock_v
> return (ret & VM_FAULT_OOM) ? -ENOMEM : 0;
> }
>
> -static bool vma_ksm_compatible(struct vm_area_struct *vma)
> +static bool ksm_compatible(const struct file *file, vm_flags_t vm_flags)
> {
> - if (vma->vm_flags & (VM_SHARED | VM_MAYSHARE | VM_PFNMAP |
> - VM_IO | VM_DONTEXPAND | VM_HUGETLB |
> - VM_MIXEDMAP| VM_DROPPABLE))
> + if (vm_flags & (VM_SHARED | VM_MAYSHARE | VM_PFNMAP |
> + VM_IO | VM_DONTEXPAND | VM_HUGETLB |
> + VM_MIXEDMAP | VM_DROPPABLE))
> return false; /* just ignore the advice */
>
> - if (vma_is_dax(vma))
> + if (file_is_dax(file))
> return false;
>
> #ifdef VM_SAO
> - if (vma->vm_flags & VM_SAO)
> + if (vm_flags & VM_SAO)
> return false;
> #endif
> #ifdef VM_SPARC_ADI
> - if (vma->vm_flags & VM_SPARC_ADI)
> + if (vm_flags & VM_SPARC_ADI)
> return false;
> #endif
>
> return true;
> }
>
> +static bool vma_ksm_compatible(struct vm_area_struct *vma)
> +{
> + return ksm_compatible(vma->vm_file, vma->vm_flags);
> +}
> +
> static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,
> unsigned long addr)
> {
> @@ -2696,14 +2701,17 @@ static int ksm_scan_thread(void *nothing)
> return 0;
> }
>
> -static void __ksm_add_vma(struct vm_area_struct *vma)
> +static bool __ksm_should_add_vma(const struct file *file, vm_flags_t vm_flags)
> {
> - unsigned long vm_flags = vma->vm_flags;
> -
> if (vm_flags & VM_MERGEABLE)
> - return;
> + return false;
> +
> + return ksm_compatible(file, vm_flags);
> +}
>
> - if (vma_ksm_compatible(vma))
> +static void __ksm_add_vma(struct vm_area_struct *vma)
> +{
> + if (__ksm_should_add_vma(vma->vm_file, vma->vm_flags))
> vm_flags_set(vma, VM_MERGEABLE);
> }
>
next prev parent reply other threads:[~2025-05-20 3:14 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-19 8:51 [PATCH 0/4] mm: ksm: prevent KSM from entirely breaking VMA merging Lorenzo Stoakes
2025-05-19 8:51 ` [PATCH 1/4] mm: ksm: have KSM VMA checks not require a VMA pointer Lorenzo Stoakes
2025-05-19 17:40 ` David Hildenbrand
2025-05-20 3:14 ` Chengming Zhou [this message]
2025-05-19 8:51 ` [PATCH 2/4] mm: ksm: refer to special VMAs via VM_SPECIAL in ksm_compatible() Lorenzo Stoakes
2025-05-19 17:41 ` David Hildenbrand
2025-05-20 3:15 ` Chengming Zhou
2025-05-19 8:51 ` [PATCH 3/4] mm: prevent KSM from completely breaking VMA merging Lorenzo Stoakes
2025-05-19 13:08 ` Chengming Zhou
2025-05-19 13:13 ` Lorenzo Stoakes
2025-05-19 13:19 ` kernel test robot
2025-05-19 13:36 ` Lorenzo Stoakes
2025-05-19 18:00 ` David Hildenbrand
2025-05-19 18:04 ` David Hildenbrand
2025-05-19 19:02 ` Lorenzo Stoakes
2025-05-19 19:11 ` David Hildenbrand
2025-05-19 19:26 ` Lorenzo Stoakes
2025-05-19 19:29 ` David Hildenbrand
2025-05-19 18:52 ` Lorenzo Stoakes
2025-05-19 18:59 ` David Hildenbrand
2025-05-19 19:14 ` Lorenzo Stoakes
2025-05-19 19:18 ` Lorenzo Stoakes
2025-05-19 19:28 ` David Hildenbrand
2025-05-19 21:57 ` Andrew Morton
2025-05-20 5:25 ` Lorenzo Stoakes
2025-05-20 3:55 ` Chengming Zhou
2025-05-20 5:24 ` Lorenzo Stoakes
2025-05-19 8:51 ` [PATCH 4/4] tools/testing/selftests: add VMA merge tests for KSM merge Lorenzo Stoakes
2025-05-21 8:07 ` Chengming Zhou
2025-05-21 8:10 ` Lorenzo Stoakes
2025-05-19 11:53 ` [PATCH 0/4] mm: ksm: prevent KSM from entirely breaking VMA merging David Hildenbrand
2025-05-19 11:56 ` 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=c5feb16f-d524-42ce-bdf0-f09a9ca4ccda@linux.dev \
--to=chengming.zhou@linux.dev \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=david@redhat.com \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=pfalcato@suse.de \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=xu.xin16@zte.com.cn \
/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;
as well as URLs for NNTP newsgroup(s).