From: David Hildenbrand <david@redhat.com>
To: Stefan Roesch <shr@devkernel.io>, kernel-team@fb.com
Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, riel@surriel.com,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v3 1/4] mm/ksm: add ksm advisor
Date: Tue, 12 Dec 2023 14:44:04 +0100 [thread overview]
Message-ID: <9f81f89f-c3ad-4cef-a619-ad36348c8ef5@redhat.com> (raw)
In-Reply-To: <20231204234906.1237478-2-shr@devkernel.io>
[...]
> +
> +/**
> + * 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_time: cpu time consumed by the ksmd thread in the previous 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_SCAN_TIME,
> +};
> +static enum ksm_advisor_type ksm_advisor;
> +
> +static void init_advisor(void)
> +{
> + advisor_ctx = (const struct advisor_ctx){ 0 };
> +}
Again, you can drop this completely. The static values are already
initialized to 0.
Or is there any reason to initialize to 0 explicitly?
> +
> +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)
> + ksm_thread_pages_to_scan = ksm_advisor_min_pages;
> +}
That function is unused?
> +
> +static inline void advisor_start_scan(void)
> +{
> + if (ksm_advisor == KSM_ADVISOR_SCAN_TIME)
> + advisor_ctx.start_scan = ktime_get();
> +}
> +
> +static inline s64 advisor_stop_scan(void)
> +{
> + return ktime_ms_delta(ktime_get(), advisor_ctx.start_scan);
> +}
Just inline that into the caller. Then rename run_advisor() into
advisor_stop_scan(). So in scan_get_next_rmap_item)( you have paired
start+stop hooks.
> +
> +/*
> + * Use previous scan time if available, otherwise use current scan time as an
> + * approximation for the previous scan time.
> + */
> +static inline unsigned long prev_scan_time(struct advisor_ctx *ctx,
> + unsigned long scan_time)
> +{
> + return ctx->scan_time ? ctx->scan_time : scan_time;
> +}
> +
> +/* Calculate exponential weighted moving average */
> +static unsigned long ewma(unsigned long prev, unsigned long curr)
> +{
> + return ((100 - EWMA_WEIGHT) * prev + EWMA_WEIGHT * curr) / 100;
> +}
> +
> +/*
> + * The scan time advisor is based on the current scan rate and the target
> + * scan rate.
> + *
> + * new_pages_to_scan = pages_to_scan * (scan_time / target_scan_time)
> + *
> + * To avoid pertubations it calculates a change factor of previous changes.
s/pertubations/perturbations/
Do you also want to describe how min/max CPU comes into play?
> + * A new change factor is calculated for each iteration and it uses an
> + * exponentially weighted moving average. The new pages_to_scan value is
> + * multiplied with that change factor:
> + *
> + * new_pages_to_scan *= change facor
> + *
> + * In addition the new pages_to_scan value is capped by the max and min
> + * limits.
> + */
With that, LGTM
Acked-by: David Hildenbrand <david@redhat.com>
--
Cheers,
David / dhildenb
next prev parent reply other threads:[~2023-12-12 13:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-04 23:49 [PATCH v3 0/4] mm/ksm: Add " Stefan Roesch
2023-12-04 23:49 ` [PATCH v3 1/4] mm/ksm: add " Stefan Roesch
2023-12-06 15:17 ` kernel test robot
2023-12-12 13:44 ` David Hildenbrand [this message]
2023-12-12 18:32 ` Stefan Roesch
2023-12-04 23:49 ` [PATCH v3 2/4] mm/ksm: add sysfs knobs for advisor Stefan Roesch
2023-12-12 13:45 ` David Hildenbrand
2023-12-12 18:02 ` Stefan Roesch
2023-12-12 18:07 ` David Hildenbrand
2023-12-12 18:27 ` Stefan Roesch
2023-12-04 23:49 ` [PATCH v3 3/4] mm/ksm: add tracepoint for ksm advisor Stefan Roesch
2023-12-12 13:45 ` David Hildenbrand
2023-12-04 23:49 ` [PATCH v3 4/4] mm/ksm: document ksm advisor and its sysfs knobs Stefan Roesch
2023-12-12 13:46 ` David Hildenbrand
2023-12-05 20:46 ` [PATCH v3 0/4] mm/ksm: Add ksm advisor Andrew Morton
2023-12-07 23:18 ` 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=9f81f89f-c3ad-4cef-a619-ad36348c8ef5@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