From: cgel.zte@gmail.com
To: lkp@intel.com
Cc: akpm@linux-foundation.org, bristot@redhat.com,
cgel.zte@gmail.com, juri.lelli@redhat.com,
kbuild-all@lists.01.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, mingo@redhat.com, peterz@infradead.org,
xu.xin16@zte.com.cn, Yang Yang <yang.yang29@zte.com.cn>,
Ran Xiaokai <ran.xiaokai@zte.com.cn>,
Zeal Robot <zealci@zte.com.cn>
Subject: [PATCH v2] ksm: Count ksm merging pages for each process
Date: Tue, 15 Mar 2022 11:48:49 +0000 [thread overview]
Message-ID: <20220315114849.2119443-1-xu.xin16@zte.com.cn> (raw)
In-Reply-To: <202203150131.oDjproo7-lkp@intel.com>
From: xu xin <xu.xin16@zte.com.cn>
As current KSM only counts the number of KSM merging pages(e.g.
ksm_pages_sharing and ksm_pages_shared) of the whole system, we cannot
see the more fine-grained KSM merging, for the upper application
optimization, the merging area cannot be set easily according to the
KSM page merging probability of each process. Therefore, it is necessary
to add extra statistical means so that the upper level users can know
the detailed KSM merging information of each process.
We add a new proc file named as ksm_merging_pages under /proc/<pid>/
to indicate the involved ksm merging pages of this process.
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Yang Yang <yang.yang29@zte.com.cn>
Reviewed-by: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
---
fs/proc/base.c | 22 ++++++++++++++++++++++
include/linux/mm_types.h | 8 ++++++++
mm/ksm.c | 11 +++++++++++
3 files changed, 41 insertions(+)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d654ce7..5c8feef 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3155,6 +3155,22 @@ static int proc_pid_patch_state(struct seq_file *m, struct pid_namespace *ns,
}
#endif /* CONFIG_LIVEPATCH */
+#ifdef CONFIG_KSM
+static int proc_pid_ksm_merging_pages(struct seq_file *m, struct pid_namespace *ns,
+ struct pid *pid, struct task_struct *task)
+{
+ struct mm_struct *mm;
+
+ mm = get_task_mm(task);
+ if (mm) {
+ seq_printf(m, "%lu\n", mm->ksm_merging_pages);
+ mmput(mm);
+ }
+
+ return 0;
+}
+#endif /* CONFIG_KSM */
+
#ifdef CONFIG_STACKLEAK_METRICS
static int proc_stack_depth(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task)
@@ -3286,6 +3302,9 @@ static const struct pid_entry tgid_base_stuff[] = {
#ifdef CONFIG_SECCOMP_CACHE_DEBUG
ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache),
#endif
+#ifdef CONFIG_KSM
+ ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages),
+#endif
};
static int proc_tgid_base_readdir(struct file *file, struct dir_context *ctx)
@@ -3619,6 +3638,9 @@ static const struct pid_entry tid_base_stuff[] = {
#ifdef CONFIG_SECCOMP_CACHE_DEBUG
ONE("seccomp_cache", S_IRUSR, proc_pid_seccomp_cache),
#endif
+#ifdef CONFIG_KSM
+ ONE("ksm_merging_pages", S_IRUSR, proc_pid_ksm_merging_pages),
+#endif
};
static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 9db36dc..4d98bd5 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -633,6 +633,14 @@ struct mm_struct {
#ifdef CONFIG_IOMMU_SUPPORT
u32 pasid;
#endif
+
+#ifdef CONFIG_KSM
+ /*
+ * Represet how many pages of this process are
+ * involved in KSM merging.
+ */
+ unsigned long ksm_merging_pages;
+#endif
} __randomize_layout;
/*
diff --git a/mm/ksm.c b/mm/ksm.c
index c20bd4d..5889733 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -638,6 +638,10 @@ static void remove_node_from_stable_tree(struct stable_node *stable_node)
ksm_pages_sharing--;
else
ksm_pages_shared--;
+
+ BUG_ON(rmap_item->mm == NULL);
+ rmap_item->mm->ksm_merging_pages--;
+
VM_BUG_ON(stable_node->rmap_hlist_len <= 0);
stable_node->rmap_hlist_len--;
put_anon_vma(rmap_item->anon_vma);
@@ -785,6 +789,10 @@ static void remove_rmap_item_from_tree(struct rmap_item *rmap_item)
ksm_pages_sharing--;
else
ksm_pages_shared--;
+
+ BUG_ON(rmap_item->mm == NULL);
+ rmap_item->mm->ksm_merging_pages--;
+
VM_BUG_ON(stable_node->rmap_hlist_len <= 0);
stable_node->rmap_hlist_len--;
@@ -2020,6 +2028,9 @@ static void stable_tree_append(struct rmap_item *rmap_item,
ksm_pages_sharing++;
else
ksm_pages_shared++;
+
+ BUG_ON(rmap_item->mm == NULL);
+ rmap_item->mm->ksm_merging_pages++;
}
/*
--
2.15.2
next prev parent reply other threads:[~2022-03-15 11:48 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-14 1:53 [PATCH linux-next] ksm: Count ksm-merging " cgel.zte
2022-03-14 17:34 ` kernel test robot
2022-03-15 11:48 ` cgel.zte [this message]
2022-03-22 8:46 ` [PATCH v2] ksm: Count ksm merging " cgel.zte
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=20220315114849.2119443-1-xu.xin16@zte.com.cn \
--to=cgel.zte@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=bristot@redhat.com \
--cc=juri.lelli@redhat.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=ran.xiaokai@zte.com.cn \
--cc=xu.xin16@zte.com.cn \
--cc=yang.yang29@zte.com.cn \
--cc=zealci@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