linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Stefan Roesch <shr@devkernel.io>
Cc: kernel-team@fb.com, akpm@linux-foundation.org,
	hannes@cmpxchg.org, riel@surriel.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v2 1/4] mm/ksm: add ksm advisor
Date: Fri, 24 Nov 2023 16:37:01 +0100	[thread overview]
Message-ID: <c1c266cd-a943-461e-b8ff-5f2eaba96a35@redhat.com> (raw)
In-Reply-To: <8734wxsn4u.fsf@devkernel.io>

>>
> 
> The min cpu case is to make sure that we scan fast enough to be able to
> react fast enough to the changes in the number of pages. This helps in
> determining in how quick we want to react to changes. This helps
> especially with the startup phase of applications.
> 
> We can certainly only set a default value, that is not exposed in sysfs.

Less toggles is better. So if we can just use some sane starting 
default, that would be great.

> 
>>> +/**
>>> + * struct advisor_ctx - metadata for KSM advisor
>>> + * @start_scan: start time of the current scan
>>> + * @scan_time: scan time of previous scan
>>> + * @change: change in percent to pages_to_scan parameter
>>> + * @cpu_percent: average cpu percent usage of the ksmd thread for the last scan
>>> + */
>>> +struct advisor_ctx {
>>> +	ktime_t start_scan;
>>> +	unsigned long scan_time;
>>> +	unsigned long change;
>>> +	unsigned long long cpu_time;
>>> +};
>>> +static struct advisor_ctx advisor_ctx;
>>> +
>>> +/* Define different advisor's */
>>> +enum ksm_advisor_type {
>>> +	KSM_ADVISOR_NONE,
>>> +	KSM_ADVISOR_FIRST = KSM_ADVISOR_NONE,
>>
>> Unused, better drop it. 0 is the implicit first one.
>>
> Will change it accordingly.
> 
>>> +	KSM_ADVISOR_SCAN_TIME,
>>> +	KSM_ADVISOR_LAST = KSM_ADVISOR_SCAN_TIME
>>
>> Instead of "_LAST", maybe use "_COUNT" and use that when checking for valid
>> values.
>>
>> But: we likely want to store "strings" instead of magic numbers from user space
>> instead.
>>
> 
> Any recommendation for the naming of the parameters when I switch to
> strings?

Probably just "none" and "scan-time" ?

>>> +}
>>> +
>>> +static void run_advisor(void)
>>> +{
>>> +	if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) {
>>> +		s64 scan_time;
>>> +
>>> +		/* Convert scan time to seconds */
>>> +		scan_time = ktime_ms_delta(ktime_get(), advisor_ctx.start_scan);
>>> +		scan_time = div_s64(scan_time, MSEC_PER_SEC);
>>> +		scan_time = scan_time ? scan_time : 1;
>>> +
>>> +		scan_time_advisor((unsigned long)scan_time);
>>> +	}
>>
>> We could have rescheduled in the meantime, right? Doesn't that mean that our CPU
>> load consumption might be wrong in some cases?
>>
> Does it matter? I'm interested how long it takes to complete the scan,
> including any scheduling.

But isn't this also required to compute CPU load, so you can stay 
between min-load and max-load?

- ksm_advisor_min_cpu (minimum value for cpu percent usage)
- ksm_advisor_max_cpu (maximum value for cpu percent usage)

Likely, you want to exclude any rescheduling from there?

I'll have to recheck the logic.

-- 
Cheers,

David / dhildenb



  reply	other threads:[~2023-11-24 15:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-28  0:09 [PATCH v2 0/4] mm/ksm: Add ksm advisor Stefan Roesch
2023-10-28  0:09 ` [PATCH v2 1/4] mm/ksm: add " Stefan Roesch
2023-10-28  7:33   ` kernel test robot
2023-11-20 10:51   ` David Hildenbrand
2023-11-22 17:20     ` Stefan Roesch
2023-11-24 15:37       ` David Hildenbrand [this message]
2023-11-24 15:39   ` David Hildenbrand
2023-10-28  0:09 ` [PATCH v2 2/4] mm/ksm: add sysfs knobs for advisor Stefan Roesch
2023-11-20 10:32   ` David Hildenbrand
2023-11-22 17:42     ` Stefan Roesch
2023-11-22 17:43     ` Stefan Roesch
2023-11-20 10:53   ` David Hildenbrand
2023-11-22 17:41     ` Stefan Roesch
2023-10-28  0:09 ` [PATCH v2 3/4] mm/ksm: add tracepoint for ksm advisor Stefan Roesch
2023-10-28  0:09 ` [PATCH v2 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=c1c266cd-a943-461e-b8ff-5f2eaba96a35@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@surriel.com \
    --cc=shr@devkernel.io \
    /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;
as well as URLs for NNTP newsgroup(s).