Re: [PATCH mm-unstable v1 1/3] mm/ksm: export ksm_is_running() to check KSM merge state
From: Lorenzo Stoakes
Date: Tue Jun 09 2026 - 10:19:56 EST
On Tue, Jun 09, 2026 at 05:46:13AM -0600, Nico Pache wrote:
> Add ksm_is_running() which returns true when KSM is actively merging
> (ksm_run & KSM_RUN_MERGE).
>
> This will be used by try_to_map_unused_to_zeropage() to skip zero-page
> remapping in VM_MERGEABLE VMAs when KSM is active.
>
> Signed-off-by: Nico Pache <npache@xxxxxxxxxx>
> ---
> include/linux/ksm.h | 6 ++++++
> mm/ksm.c | 6 ++++++
> 2 files changed, 12 insertions(+)
>
> diff --git a/include/linux/ksm.h b/include/linux/ksm.h
> index d39d0d5483a2..c1048b690a92 100644
> --- a/include/linux/ksm.h
> +++ b/include/linux/ksm.h
> @@ -17,6 +17,7 @@
> #ifdef CONFIG_KSM
> int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
> unsigned long end, int advice, vm_flags_t *vm_flags);
> +bool ksm_is_running(void);
> vma_flags_t ksm_vma_flags(struct mm_struct *mm, const struct file *file,
> vma_flags_t vma_flags);
> int ksm_enable_merge_any(struct mm_struct *mm);
> @@ -144,6 +145,11 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
> return 0;
> }
>
> +static inline bool ksm_is_running(void)
> +{
> + return false;
> +}
> +
> static inline struct folio *ksm_might_need_to_copy(struct folio *folio,
> struct vm_area_struct *vma, unsigned long addr)
> {
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 7d5b76478f0b..edc2b961ff59 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -3015,6 +3015,12 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
> }
> EXPORT_SYMBOL_GPL(ksm_madvise);
>
> +bool ksm_is_running(void)
> +{
> + return ksm_run & KSM_RUN_MERGE;
> +}
> +EXPORT_SYMBOL_GPL(ksm_is_running);
Why are we exporting this? What modules need this? We should never export unless
we have a very specific reason to.
> +
> int __ksm_enter(struct mm_struct *mm)
> {
> struct ksm_mm_slot *mm_slot;
> --
> 2.54.0
>