diff mbox series

[RESEND,RFC,v1,12/20] mm: add ksm_merge_type() function

Message ID 20230123173748.1734238-13-shr@devkernel.io (mailing list archive)
State New
Headers show
Series mm: process/cgroup ksm support | expand

Commit Message

Stefan Roesch Jan. 23, 2023, 5:37 p.m. UTC
This adds the ksm_merge_type function. The function returns the merge
type for the process. For madvise it returns "madvise", for prctl it
returns "process" and otherwise it returns "none".

Signed-off-by: Stefan Roesch <shr@devkernel.io>
---
 include/linux/ksm.h |  1 +
 mm/ksm.c            | 11 +++++++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index a18cd03efcfb..d5f69f18ee5a 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -57,6 +57,7 @@  void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
 
 #ifdef CONFIG_PROC_FS
 long ksm_process_profit(struct mm_struct *);
+const char *ksm_merge_type(struct mm_struct *mm);
 #endif /* CONFIG_PROC_FS */
 
 #else  /* !CONFIG_KSM */
diff --git a/mm/ksm.c b/mm/ksm.c
index 288689b59527..57183deaf529 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2941,6 +2941,17 @@  long ksm_process_profit(struct mm_struct *mm)
 	return (long)mm->ksm_merging_pages * PAGE_SIZE -
 		mm->ksm_rmap_items * sizeof(struct ksm_rmap_item);
 }
+
+/* Return merge type name as string. */
+const char *ksm_merge_type(struct mm_struct *mm)
+{
+	if (test_bit(MMF_VM_MERGE_ANY, &mm->flags))
+		return "process";
+	else if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
+		return "madvise";
+	else
+		return "none";
+}
 #endif /* CONFIG_PROC_FS */
 
 #ifdef CONFIG_SYSFS