Re: [PATCH v3 2/4] mm/ksm: add sysfs knobs for advisor

From: David Hildenbrand
Date: Tue Dec 12 2023 - 08:45:37 EST


On 05.12.23 00:49, Stefan Roesch wrote:
This adds four new knobs for the KSM advisor to influence its behaviour.

The knobs are:
- advisor_mode:
none: no advisor (default)
scan-time: scan time advisor
- advisor_max_cpu: 70 (default, cpu usage percent)
- advisor_min_pages: 500 (default)
- advisor_max_pages: 30000 (default)
- advisor_target_scan_time: 200 (default in seconds)

The new values will take effect on the next scan round.

Signed-off-by: Stefan Roesch <shr@xxxxxxxxxxxx>
---
mm/ksm.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 127 insertions(+)

diff --git a/mm/ksm.c b/mm/ksm.c
index b27010fa2e946..18b7185bbc65b 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -3735,6 +3735,128 @@ static ssize_t smart_scan_store(struct kobject *kobj,
}
KSM_ATTR(smart_scan);
+static ssize_t advisor_mode_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ const char *output;
+
+ if (ksm_advisor == KSM_ADVISOR_NONE)
+ output = "[none] scan-time";
+ else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
+ output = "none [scan-time]";
+
+ return sysfs_emit(buf, "%s\n", output);
+}
+
+static ssize_t advisor_mode_store(struct kobject *kobj,
+ struct kobj_attribute *attr, const char *buf,
+ size_t count)
+{
+ if (sysfs_streq("scan-time", buf))
+ ksm_advisor = KSM_ADVISOR_SCAN_TIME;
+ else if (sysfs_streq("none", buf))
+ ksm_advisor = KSM_ADVISOR_NONE;
+ else
+ return -EINVAL;
+
+ /* Set advisor default values */
+ init_advisor();

Is the "init_advisor()" really required?

+ set_advisor_defaults();

That function should go to this patch.



--
Cheers,

David / dhildenb