[PATCH mm-unstable v1 1/3] mm/ksm: export ksm_is_running() to check KSM merge state

From: Nico Pache

Date: Tue Jun 09 2026 - 07:53:20 EST


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);
+
int __ksm_enter(struct mm_struct *mm)
{
struct ksm_mm_slot *mm_slot;
--
2.54.0