From: Andrew Morton <akpm@linux-foundation.org>
To: 76824143@qq.com
Cc: linux-mm@kvack.org, Hao Zhang <zhanghao1@kylinos.cn>
Subject: Re: [PATCH v2] mm/vmscan: extract calculated pressure balance as a function
Date: Tue, 28 Jan 2025 20:15:28 -0800 [thread overview]
Message-ID: <20250128201528.5bf3f9226057f4ea0e12d18a@linux-foundation.org> (raw)
In-Reply-To: <tencent_735DB36A2306C08B8568049E4C0B99716C07@qq.com>
On Wed, 15 Jan 2025 09:58:29 +0800 76824143@qq.com wrote:
> From: Hao Zhang <zhanghao1@kylinos.cn>
>
> Extract pressure balance calculation into a function.This
> doesn't change current behaviour.
OK, I guess it's a slight improvement and the size of my vmscan.o is
unaltered.
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -2367,6 +2367,43 @@ static void prepare_scan_control(pg_data_t *pgdat, struct scan_control *sc)
> }
> }
>
> +static inline void calculate_pressure_balance(struct scan_control *sc, int swappiness,
> + u64 *fraction, u64 *denominator)
As we're wrapping, we may as well wrap within 80 cols:
--- a/mm/vmscan.c~mm-vmscan-extract-calculated-pressure-balance-as-a-function-fix
+++ a/mm/vmscan.c
@@ -2400,8 +2400,8 @@ static void prepare_scan_control(pg_data
}
}
-static inline void calculate_pressure_balance(struct scan_control *sc, int swappiness,
- u64 *fraction, u64 *denominator)
+static inline void calculate_pressure_balance(struct scan_control *sc,
+ int swappiness, u64 *fraction, u64 *denominator)
{
unsigned long anon_cost, file_cost, total_cost;
unsigned long ap, fp;
_
_
> +{
> + unsigned long anon_cost, file_cost, total_cost;
> + unsigned long ap, fp;
> +
> + /*
> + * Calculate the pressure balance between anon and file pages.
> + *
> + * The amount of pressure we put on each LRU is inversely
> + * proportional to the cost of reclaiming each list, as
> + * determined by the share of pages that are refaulting, times
> + * the relative IO cost of bringing back a swapped out
> + * anonymous page vs reloading a filesystem page (swappiness).
> + *
> + * Although we limit that influence to ensure no list gets
> + * left behind completely: at least a third of the pressure is
> + * applied, before swappiness.
> + *
> + * With swappiness at 100, anon and file have equal IO cost.
> + */
> + total_cost = sc->anon_cost + sc->file_cost;
> + anon_cost = total_cost + sc->anon_cost;
> + file_cost = total_cost + sc->file_cost;
> + total_cost = anon_cost + file_cost;
> +
> + ap = swappiness * (total_cost + 1);
> + ap /= anon_cost + 1;
> +
> + fp = (MAX_SWAPPINESS - swappiness) * (total_cost + 1);
> + fp /= file_cost + 1;
> +
> + fraction[WORKINGSET_ANON] = ap;
> + fraction[WORKINGSET_FILE] = fp;
> + *denominator = ap + fp;
> +}
> +
> /*
> * Determine how aggressively the anon and file LRU lists should be
> * scanned.
> @@ -2379,12 +2416,10 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
> {
> struct pglist_data *pgdat = lruvec_pgdat(lruvec);
> struct mem_cgroup *memcg = lruvec_memcg(lruvec);
> - unsigned long anon_cost, file_cost, total_cost;
> int swappiness = sc_swappiness(sc, memcg);
> u64 fraction[ANON_AND_FILE];
> u64 denominator = 0; /* gcc */
> enum scan_balance scan_balance;
> - unsigned long ap, fp;
> enum lru_list lru;
>
> /* If we have no swap space, do not bother scanning anon folios. */
> @@ -2433,35 +2468,8 @@ static void get_scan_count(struct lruvec *lruvec, struct scan_control *sc,
> }
>
> scan_balance = SCAN_FRACT;
> - /*
> - * Calculate the pressure balance between anon and file pages.
> - *
> - * The amount of pressure we put on each LRU is inversely
> - * proportional to the cost of reclaiming each list, as
> - * determined by the share of pages that are refaulting, times
> - * the relative IO cost of bringing back a swapped out
> - * anonymous page vs reloading a filesystem page (swappiness).
> - *
> - * Although we limit that influence to ensure no list gets
> - * left behind completely: at least a third of the pressure is
> - * applied, before swappiness.
> - *
> - * With swappiness at 100, anon and file have equal IO cost.
> - */
> - total_cost = sc->anon_cost + sc->file_cost;
> - anon_cost = total_cost + sc->anon_cost;
> - file_cost = total_cost + sc->file_cost;
> - total_cost = anon_cost + file_cost;
> -
> - ap = swappiness * (total_cost + 1);
> - ap /= anon_cost + 1;
> -
> - fp = (MAX_SWAPPINESS - swappiness) * (total_cost + 1);
> - fp /= file_cost + 1;
> + calculate_pressure_balance(sc, swappiness, fraction, &denominator);
>
> - fraction[0] = ap;
> - fraction[1] = fp;
> - denominator = ap + fp;
> out:
> for_each_evictable_lru(lru) {
> bool file = is_file_lru(lru);
>
> base-commit: eea6e4b4dfb8859446177c32961c96726d0117be
> --
> 2.25.1
prev parent reply other threads:[~2025-01-29 4:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 1:58 76824143
2025-01-29 4:15 ` Andrew Morton [this message]
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=20250128201528.5bf3f9226057f4ea0e12d18a@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=76824143@qq.com \
--cc=linux-mm@kvack.org \
--cc=zhanghao1@kylinos.cn \
/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