From: Raghavendra K T <raghavendra.kt@amd.com>
To: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<gourry@gourry.net>, <nehagholkar@meta.com>, <abhishekd@meta.com>,
<david@redhat.com>, <ying.huang@intel.com>, <nphamcs@gmail.com>,
<akpm@linux-foundation.org>, <hannes@cmpxchg.org>,
<feng.tang@intel.com>, <kbusch@meta.com>, <bharata@amd.com>,
<Hasan.Maruf@amd.com>, <sj@kernel.org>
Cc: <willy@infradead.org>, <kirill.shutemov@linux.intel.com>,
<mgorman@techsingularity.net>, <vbabka@suse.cz>,
<hughd@google.com>, <rientjes@google.com>, <shy828301@gmail.com>,
<Liam.Howlett@Oracle.com>, <peterz@infradead.org>,
<mingo@redhat.com>, Raghavendra K T <raghavendra.kt@amd.com>
Subject: [RFC PATCH V0 07/10] sysfs: Add sysfs support to tune scanning
Date: Sun, 1 Dec 2024 15:38:15 +0000 [thread overview]
Message-ID: <20241201153818.2633616-8-raghavendra.kt@amd.com> (raw)
In-Reply-To: <20241201153818.2633616-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
Signed-off-by: Raghavendra K T <raghavendra.kt@amd.com>
---
mm/kmmscand.c | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 205 insertions(+)
diff --git a/mm/kmmscand.c b/mm/kmmscand.c
index 2efef53f9402..344a45bd2d3e 100644
--- a/mm/kmmscand.c
+++ b/mm/kmmscand.c
@@ -20,6 +20,7 @@
#include <linux/string.h>
#include <linux/cleanup.h>
#include <linux/minmax.h>
+#include <trace/events/kmem.h>
#include <asm/pgalloc.h>
#include "internal.h"
@@ -114,6 +115,170 @@ struct kmmscand_migrate_info {
unsigned long address;
};
+#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);
@@ -738,9 +903,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)
@@ -857,6 +1056,11 @@ static int __init kmmscand_init(void)
return -ENOMEM;
}
+ err = kmmscand_init_sysfs(&mm_kobj);
+
+ if (err)
+ goto err_init_sysfs;
+
err = start_kmmscand();
if (err)
goto err_kmmscand;
@@ -865,6 +1069,7 @@ static int __init kmmscand_init(void)
err_kmmscand:
stop_kmmscand();
+err_init_sysfs:
kmmscand_destroy();
return err;
--
2.39.3
next prev parent reply other threads:[~2024-12-01 15:39 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-01 15:38 [RFC PATCH V0 0/10] mm: slowtier page promotion based on PTE A bit Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 01/10] mm: Add kmmscand kernel daemon Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 02/10] mm: Maintain mm_struct list in the system Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 03/10] mm: Scan the mm and create a migration list Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 04/10] mm/migration: Migrate accessed folios to toptier node Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 05/10] mm: Add throttling of mm scanning using scan_period Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 06/10] mm: Add throttling of mm scanning using scan_size Raghavendra K T
2024-12-01 15:38 ` Raghavendra K T [this message]
2024-12-01 15:38 ` [RFC PATCH V0 08/10] vmstat: Add vmstat counters Raghavendra K T
2024-12-01 15:38 ` [RFC PATCH V0 09/10] trace/kmmscand: Add tracing of scanning and migration Raghavendra K T
2024-12-05 17:46 ` Steven Rostedt
2024-12-06 6:33 ` Raghavendra K T
2024-12-06 14:49 ` Steven Rostedt
2024-12-01 15:38 ` [RFC PATCH V0 DO NOT MERGE 10/10] kmmscand: Add scanning Raghavendra K T
2024-12-10 18:53 ` [RFC PATCH V0 0/10] mm: slowtier page promotion based on PTE A bit SeongJae Park
2024-12-20 6:30 ` Raghavendra K T
2025-02-12 17:02 ` Davidlohr Bueso
2025-02-13 5:39 ` 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=20241201153818.2633616-8-raghavendra.kt@amd.com \
--to=raghavendra.kt@amd.com \
--cc=Hasan.Maruf@amd.com \
--cc=Liam.Howlett@Oracle.com \
--cc=abhishekd@meta.com \
--cc=akpm@linux-foundation.org \
--cc=bharata@amd.com \
--cc=david@redhat.com \
--cc=feng.tang@intel.com \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=kbusch@meta.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@techsingularity.net \
--cc=mingo@redhat.com \
--cc=nehagholkar@meta.com \
--cc=nphamcs@gmail.com \
--cc=peterz@infradead.org \
--cc=rientjes@google.com \
--cc=shy828301@gmail.com \
--cc=sj@kernel.org \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=ying.huang@intel.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