From: Raghavendra K T <raghavendra.kt@amd.com>
To: <raghavendra.kt@amd.com>
Cc: <AneeshKumar.KizhakeVeetil@arm.com>, <Hasan.Maruf@amd.com>,
<Michael.Day@amd.com>, <akpm@linux-foundation.org>,
<bharata@amd.com>, <dave.hansen@intel.com>, <david@redhat.com>,
<dongjoo.linux.dev@gmail.com>, <feng.tang@intel.com>,
<gourry@gourry.net>, <hannes@cmpxchg.org>, <honggyu.kim@sk.com>,
<hughd@google.com>, <jhubbard@nvidia.com>, <jon.grimm@amd.com>,
<k.shutemov@gmail.com>, <kbusch@meta.com>,
<kmanaouil.dev@gmail.com>, <leesuyeon0506@gmail.com>,
<leillc@google.com>, <liam.howlett@oracle.com>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
<mgorman@techsingularity.net>, <mingo@redhat.com>,
<nadav.amit@gmail.com>, <nphamcs@gmail.com>,
<peterz@infradead.org>, <riel@surriel.com>, <rientjes@google.com>,
<rppt@kernel.org>, <santosh.shukla@amd.com>, <shivankg@amd.com>,
<shy828301@gmail.com>, <sj@kernel.org>, <vbabka@suse.cz>,
<weixugc@google.com>, <willy@infradead.org>,
<ying.huang@linux.alibaba.com>, <ziy@nvidia.com>,
<Jonathan.Cameron@huawei.com>, <dave@stgolabs.net>
Subject: [RFC PATCH V1 10/13] sysfs: Add sysfs support to tune scanning
Date: Wed, 19 Mar 2025 19:30:25 +0000 [thread overview]
Message-ID: <20250319193028.29514-11-raghavendra.kt@amd.com> (raw)
In-Reply-To: <20250319193028.29514-1-raghavendra.kt@amd.com>
Support below tunables:
scan_enable: turn on or turn off mm_struct scanning
scan_period: initial scan_period (default: 2sec)
scan_sleep_ms: sleep time between two successive round of scanning and
migration.
mms_to_scan: total mm_struct to scan before taking a pause.
target_node: default regular node to which migration of accessed pages
is done (this is only fall back mechnism, otherwise target_node
heuristic is used).
Signed-off-by: Raghavendra K T <raghavendra.kt@amd.com>
---
mm/kmmscand.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 206 insertions(+)
diff --git a/mm/kmmscand.c b/mm/kmmscand.c
index c2924b2e8a6d..618594d7c148 100644
--- a/mm/kmmscand.c
+++ b/mm/kmmscand.c
@@ -21,6 +21,7 @@
#include <linux/delay.h>
#include <linux/cleanup.h>
#include <linux/minmax.h>
+#include <trace/events/kmem.h>
#include <asm/pgalloc.h>
#include "internal.h"
@@ -158,6 +159,170 @@ static bool kmmscand_eligible_srcnid(int nid)
return false;
}
+#ifdef CONFIG_SYSFS
+static ssize_t scan_sleep_ms_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%u\n", kmmscand_scan_sleep_ms);
+}
+
+static ssize_t scan_sleep_ms_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned int msecs;
+ int err;
+
+ err = kstrtouint(buf, 10, &msecs);
+ if (err)
+ return -EINVAL;
+
+ kmmscand_scan_sleep_ms = msecs;
+ kmmscand_sleep_expire = 0;
+ wake_up_interruptible(&kmmscand_wait);
+
+ return count;
+}
+static struct kobj_attribute scan_sleep_ms_attr =
+ __ATTR_RW(scan_sleep_ms);
+
+static ssize_t mm_scan_period_ms_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%u\n", kmmscand_mm_scan_period_ms);
+}
+
+/* If a value less than MIN or greater than MAX asked for store value is clamped */
+static ssize_t mm_scan_period_ms_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned int msecs, stored_msecs;
+ int err;
+
+ err = kstrtouint(buf, 10, &msecs);
+ if (err)
+ return -EINVAL;
+
+ stored_msecs = clamp(msecs, KMMSCAND_SCAN_PERIOD_MIN, KMMSCAND_SCAN_PERIOD_MAX);
+
+ kmmscand_mm_scan_period_ms = stored_msecs;
+ kmmscand_sleep_expire = 0;
+ wake_up_interruptible(&kmmscand_wait);
+
+ return count;
+}
+
+static struct kobj_attribute mm_scan_period_ms_attr =
+ __ATTR_RW(mm_scan_period_ms);
+
+static ssize_t mms_to_scan_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%lu\n", kmmscand_mms_to_scan);
+}
+
+static ssize_t mms_to_scan_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned long val;
+ int err;
+
+ err = kstrtoul(buf, 10, &val);
+ if (err)
+ return -EINVAL;
+
+ kmmscand_mms_to_scan = val;
+ kmmscand_sleep_expire = 0;
+ wake_up_interruptible(&kmmscand_wait);
+
+ return count;
+}
+
+static struct kobj_attribute mms_to_scan_attr =
+ __ATTR_RW(mms_to_scan);
+
+static ssize_t scan_enabled_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%u\n", kmmscand_scan_enabled ? 1 : 0);
+}
+
+static ssize_t scan_enabled_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ unsigned int val;
+ int err;
+
+ err = kstrtouint(buf, 10, &val);
+ if (err || val > 1)
+ return -EINVAL;
+
+ if (val) {
+ kmmscand_scan_enabled = true;
+ need_wakeup = true;
+ } else
+ kmmscand_scan_enabled = false;
+
+ kmmscand_sleep_expire = 0;
+ wake_up_interruptible(&kmmscand_wait);
+
+ return count;
+}
+
+static struct kobj_attribute scan_enabled_attr =
+ __ATTR_RW(scan_enabled);
+
+static ssize_t target_node_show(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%u\n", kmmscand_target_node);
+}
+
+static ssize_t target_node_store(struct kobject *kobj,
+ struct kobj_attribute *attr,
+ const char *buf, size_t count)
+{
+ int err, node;
+
+ err = kstrtoint(buf, 10, &node);
+ if (err)
+ return -EINVAL;
+
+ kmmscand_sleep_expire = 0;
+ if (!node_is_toptier(node))
+ return -EINVAL;
+
+ kmmscand_target_node = node;
+ wake_up_interruptible(&kmmscand_wait);
+
+ return count;
+}
+static struct kobj_attribute target_node_attr =
+ __ATTR_RW(target_node);
+
+static struct attribute *kmmscand_attr[] = {
+ &scan_sleep_ms_attr.attr,
+ &mm_scan_period_ms_attr.attr,
+ &mms_to_scan_attr.attr,
+ &scan_enabled_attr.attr,
+ &target_node_attr.attr,
+ NULL,
+};
+
+struct attribute_group kmmscand_attr_group = {
+ .attrs = kmmscand_attr,
+ .name = "kmmscand",
+};
+#endif
+
static int kmmscand_has_work(void)
{
return !list_empty(&kmmscand_scan.mm_head);
@@ -1036,9 +1201,43 @@ static int kmmscand(void *none)
return 0;
}
+#ifdef CONFIG_SYSFS
+extern struct kobject *mm_kobj;
+static int __init kmmscand_init_sysfs(struct kobject **kobj)
+{
+ int err;
+
+ err = sysfs_create_group(*kobj, &kmmscand_attr_group);
+ if (err) {
+ pr_err("failed to register kmmscand group\n");
+ goto err_kmmscand_attr;
+ }
+
+ return 0;
+
+err_kmmscand_attr:
+ sysfs_remove_group(*kobj, &kmmscand_attr_group);
+ return err;
+}
+
+static void __init kmmscand_exit_sysfs(struct kobject *kobj)
+{
+ sysfs_remove_group(kobj, &kmmscand_attr_group);
+}
+#else
+static inline int __init kmmscand_init_sysfs(struct kobject **kobj)
+{
+ return 0;
+}
+static inline void __init kmmscand_exit_sysfs(struct kobject *kobj)
+{
+}
+#endif
+
static inline void kmmscand_destroy(void)
{
kmem_cache_destroy(kmmscand_slot_cache);
+ kmmscand_exit_sysfs(mm_kobj);
}
void __kmmscand_enter(struct mm_struct *mm)
@@ -1223,7 +1422,13 @@ static int __init kmmscand_init(void)
return -ENOMEM;
}
+ err = kmmscand_init_sysfs(&mm_kobj);
+
+ if (err)
+ goto err_init_sysfs;
+
init_list();
+
err = start_kmmscand();
if (err)
goto err_kmmscand;
@@ -1239,6 +1444,7 @@ static int __init kmmscand_init(void)
err_kmmscand:
stop_kmmscand();
+err_init_sysfs:
kmmscand_destroy();
return err;
--
2.34.1
next prev parent reply other threads:[~2025-03-19 19:32 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-19 19:30 [RFC PATCH V1 00/13] mm: slowtier page promotion based on PTE A bit Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 01/13] mm: Add kmmscand kernel daemon Raghavendra K T
2025-03-21 16:06 ` Jonathan Cameron
2025-03-24 15:09 ` Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 02/13] mm: Maintain mm_struct list in the system Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 03/13] mm: Scan the mm and create a migration list Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 04/13] mm: Create a separate kernel thread for migration Raghavendra K T
2025-03-21 17:29 ` Jonathan Cameron
2025-03-24 15:17 ` Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 05/13] mm/migration: Migrate accessed folios to toptier node Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 06/13] mm: Add throttling of mm scanning using scan_period Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 07/13] mm: Add throttling of mm scanning using scan_size Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 08/13] mm: Add initial scan delay Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 09/13] mm: Add heuristic to calculate target node Raghavendra K T
2025-03-21 17:42 ` Jonathan Cameron
2025-03-24 16:17 ` Raghavendra K T
2025-03-19 19:30 ` Raghavendra K T [this message]
2025-03-19 19:30 ` [RFC PATCH V1 11/13] vmstat: Add vmstat counters Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 12/13] trace/kmmscand: Add tracing of scanning and migration Raghavendra K T
2025-03-19 19:30 ` [RFC PATCH V1 13/13] prctl: Introduce new prctl to control scanning Raghavendra K T
2025-03-19 23:00 ` [RFC PATCH V1 00/13] mm: slowtier page promotion based on PTE A bit Davidlohr Bueso
2025-03-20 8:51 ` Raghavendra K T
2025-03-20 19:11 ` Raghavendra K T
2025-03-21 20:35 ` Davidlohr Bueso
2025-03-25 6:36 ` Raghavendra K T
2025-03-20 21:50 ` Davidlohr Bueso
2025-03-21 6:48 ` Raghavendra K T
2025-03-21 15:52 ` Jonathan Cameron
[not found] ` <20250321105309.3521-1-hdanton@sina.com>
2025-03-23 18:14 ` [RFC PATCH V1 09/13] mm: Add heuristic to calculate target node Raghavendra K T
[not found] ` <20250324110543.3599-1-hdanton@sina.com>
2025-03-24 14:54 ` Raghavendra K T
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=20250319193028.29514-11-raghavendra.kt@amd.com \
--to=raghavendra.kt@amd.com \
--cc=AneeshKumar.KizhakeVeetil@arm.com \
--cc=Hasan.Maruf@amd.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=Michael.Day@amd.com \
--cc=akpm@linux-foundation.org \
--cc=bharata@amd.com \
--cc=dave.hansen@intel.com \
--cc=dave@stgolabs.net \
--cc=david@redhat.com \
--cc=dongjoo.linux.dev@gmail.com \
--cc=feng.tang@intel.com \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=honggyu.kim@sk.com \
--cc=hughd@google.com \
--cc=jhubbard@nvidia.com \
--cc=jon.grimm@amd.com \
--cc=k.shutemov@gmail.com \
--cc=kbusch@meta.com \
--cc=kmanaouil.dev@gmail.com \
--cc=leesuyeon0506@gmail.com \
--cc=leillc@google.com \
--cc=liam.howlett@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=nphamcs@gmail.com \
--cc=peterz@infradead.org \
--cc=riel@surriel.com \
--cc=rientjes@google.com \
--cc=rppt@kernel.org \
--cc=santosh.shukla@amd.com \
--cc=shivankg@amd.com \
--cc=shy828301@gmail.com \
--cc=sj@kernel.org \
--cc=vbabka@suse.cz \
--cc=weixugc@google.com \
--cc=willy@infradead.org \
--cc=ying.huang@linux.alibaba.com \
--cc=ziy@nvidia.com \
/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
all inboxes | Powered by JetHome®