From: "Stefan Roesch" <shr@devkernel.io>
To: "David Hildenbrand" <david@redhat.com>, kernel-team@fb.com
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
hannes@cmpxchg.org, riel@surriel.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v4 2/4] mm/ksm: add sysfs knobs for advisor
Date: Mon, 18 Dec 2023 09:44:54 -0800 [thread overview]
Message-ID: <867b7cff-1061-45e8-86b1-f8006ebbdf6a@app.fastmail.com> (raw)
In-Reply-To: <bca31bff-5d5a-43e6-876f-0d8d20b4000b@redhat.com>
On Mon, Dec 18, 2023, at 3:25 AM, David Hildenbrand wrote:
> On 13.12.23 19:27, 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_to_scan: 500 (default)
>> - advisor_max_pages_to_scan: 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@devkernel.io>
>> ---
>> mm/ksm.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 139 insertions(+), 3 deletions(-)
>>
>> diff --git a/mm/ksm.c b/mm/ksm.c
>> index 4f7b71a1f3112..f7387a6d02050 100644
>> --- a/mm/ksm.c
>> +++ b/mm/ksm.c
>> @@ -302,10 +302,10 @@ unsigned long ksm_zero_pages;
>> static unsigned long ksm_pages_skipped;
>>
>> /* Don't scan more than max pages per batch. */
>> -static unsigned long ksm_advisor_max_pages = 30000;
>> +static unsigned long ksm_advisor_max_pages_to_scan = 30000;
>>
>> /* At least scan this many pages per batch. */
>> -static unsigned long ksm_advisor_min_pages = 500;
>> +static unsigned long ksm_advisor_min_pages_to_scan = 500;
>>
>
> That renaming should go into the previous patch.
>
Moved it to the previous patch.
>> /* Min CPU for scanning pages per scan */
>> static unsigned int ksm_advisor_min_cpu = 10;
>> @@ -341,6 +341,16 @@ enum ksm_advisor_type {
>> };
>> static enum ksm_advisor_type ksm_advisor;
>>
>> +static void set_advisor_defaults(void)
>> +{
>> + if (ksm_advisor == KSM_ADVISOR_NONE) {
>> + ksm_thread_pages_to_scan = DEFAULT_PAGES_TO_SCAN;
>> + } else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) {
>> + advisor_ctx = (const struct advisor_ctx){ 0 };
>> + ksm_thread_pages_to_scan = ksm_advisor_min_pages_to_scan;
>> + }
>> +}
>> +
>> static inline void advisor_start_scan(void)
>> {
>> if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
>> @@ -434,7 +444,7 @@ static void scan_time_advisor(void)
>>
>> pages = min(pages, per_page_cost * ksm_advisor_max_cpu);
>> pages = max(pages, per_page_cost * ksm_advisor_min_cpu);
>> - pages = min(pages, ksm_advisor_max_pages);
>> + pages = min(pages, ksm_advisor_max_pages_to_scan);
>>
>> /* Update advisor context */
>> advisor_ctx.change = change;
>> @@ -3722,6 +3732,127 @@ 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 */
>> + set_advisor_defaults();
>
> It probably makes sense to not reset the defaults if the ksm_advisor
> didn't change.
>
Added the above change.
> Apart form that, LGTM.
>
> --
> Cheers,
>
> David / dhildenb
next prev parent reply other threads:[~2023-12-18 17:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-13 18:27 [PATCH v4 0/4] mm/ksm: Add ksm advisor Stefan Roesch
2023-12-13 18:27 ` [PATCH v4 1/4] mm/ksm: add " Stefan Roesch
2023-12-18 11:29 ` David Hildenbrand
2023-12-18 17:27 ` Stefan Roesch
2023-12-13 18:27 ` [PATCH v4 2/4] mm/ksm: add sysfs knobs for advisor Stefan Roesch
2023-12-18 11:25 ` David Hildenbrand
2023-12-18 17:44 ` Stefan Roesch [this message]
2023-12-13 18:27 ` [PATCH v4 3/4] mm/ksm: add tracepoint for ksm advisor Stefan Roesch
2023-12-13 18:27 ` [PATCH v4 4/4] mm/ksm: document ksm advisor and its sysfs knobs Stefan Roesch
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=867b7cff-1061-45e8-86b1-f8006ebbdf6a@app.fastmail.com \
--to=shr@devkernel.io \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@surriel.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