From: cgel.zte@gmail.com
To: akpm@linux-foundation.org, willy@infradead.org
Cc: hughd@google.com, izik.eidus@ravellosystems.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
xu.xin16@zte.com.cn, CGEL <cgel.zte@gmail.com>
Subject: [PATCH v2 4/5] ksm: show ksmd status for auto mode
Date: Fri, 12 Aug 2022 10:12:23 +0000 [thread overview]
Message-ID: <20220812101223.41641-1-xu.xin16@zte.com.cn> (raw)
In-Reply-To: <20220812101102.41422-1-xu.xin16@zte.com.cn>
From: xu xin <xu.xin16@zte.com.cn>
Add a sysfs interface of ksmd_status to show some details related
with auto-mode.
Signed-off-by: xu xin <xu.xin16@zte.com.cn>
Signed-off-by: CGEL <cgel.zte@gmail.com>
---
mm/ksm.c | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index c5fd4f520f4a..478bcf26bfcd 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -307,6 +307,9 @@ unsigned int ksm_auto_threshold = 20;
/* Work in auto-mode. Whether trigger ksmd to compare and merge pages */
static bool auto_triggered;
+/* Count of times that ksmd is triggered due to low free memory */
+static unsigned long triggered_times;
+
#ifdef CONFIG_NUMA
/* Zeroed when merging across nodes is not allowed */
static unsigned int ksm_merge_across_nodes = 1;
@@ -2487,8 +2490,10 @@ static bool should_trigger_ksmd_to_merge(void)
static inline void trigger_ksmd_to_merge(void)
{
- if (!auto_triggered)
+ if (!auto_triggered) {
+ triggered_times++;
auto_triggered = true;
+ }
}
static inline void stop_ksmd_to_merge(void)
@@ -3118,6 +3123,40 @@ static ssize_t run_store(struct kobject *kobj, struct kobj_attribute *attr,
}
KSM_ATTR(run);
+static ssize_t ksmd_status_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ int len = 0;
+ unsigned int mergeable_mms = 0;
+ struct list_head *pos;
+
+ list_for_each(pos, &ksm_mm_head.mm_list)
+ mergeable_mms++;
+
+ if (ksm_run & KSM_RUN_AUTO) {
+ len += sysfs_emit_at(buf, len, "mode: auto\n");
+ len += sysfs_emit_at(buf, len, "auto_triggered: %d\n",
+ auto_triggered);
+ len += sysfs_emit_at(buf, len, "mergeable_mms: %u\n",
+ mergeable_mms);
+ len += sysfs_emit_at(buf, len, "scanning_factor: %u\n",
+ scanning_factor);
+ len += sysfs_emit_at(buf, len, "triggered_times: %lu\n",
+ triggered_times);
+ } else if (ksm_run & KSM_RUN_MERGE) {
+ len += sysfs_emit_at(buf, len, "mode: on\n");
+ len += sysfs_emit_at(buf, len, "mergeable_mms: %u\n",
+ mergeable_mms);
+ } else if (ksm_run & KSM_RUN_UNMERGE)
+ len += sysfs_emit_at(buf, len, "mode: unmerge\n");
+ else
+ len += sysfs_emit_at(buf, len, "mode: off\n");
+
+
+ return len;
+}
+KSM_ATTR_RO(ksmd_status);
+
static ssize_t auto_threshold_show(struct kobject *kobj,
struct kobj_attribute *attr, char *buf)
{
@@ -3355,6 +3394,7 @@ static struct attribute *ksm_attrs[] = {
&pages_to_scan_attr.attr,
&max_scanning_factor_attr.attr,
&run_attr.attr,
+ &ksmd_status_attr.attr,
&auto_threshold_attr.attr,
&pages_shared_attr.attr,
&pages_sharing_attr.attr,
--
2.25.1
next prev parent reply other threads:[~2022-08-12 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-12 10:11 [PATCH v2 0/5] propose auto-run mode of ksm and its tests cgel.zte
2022-08-12 10:11 ` [PATCH v2 1/5] ksm: add a auto-run mode of ksm cgel.zte
2022-08-12 10:12 ` [PATCH v2 2/5] ksm: implement scan-enhanced algorithm cgel.zte
2022-08-12 10:12 ` [PATCH v2 3/5] ksm: let ksmd auto-work with memory threshold cgel.zte
2022-08-12 10:12 ` cgel.zte [this message]
2022-08-12 10:12 ` [PATCH v2 5/5] ksm: add tests of ksm auto mode 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=20220812101223.41641-1-xu.xin16@zte.com.cn \
--to=cgel.zte@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=izik.eidus@ravellosystems.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
--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