From: Dan Schatzberg <schatzberg.dan@gmail.com>
To: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Yosry Ahmed <yosryahmed@google.com>, Huan Yang <link@vivo.com>,
linux-kernel@vger.kernel.org, cgroups@vger.kernel.org,
linux-mm@kvack.org, Tejun Heo <tj@kernel.org>,
Zefan Li <lizefan.x@bytedance.com>,
Jonathan Corbet <corbet@lwn.net>,
Shakeel Butt <shakeelb@google.com>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
SeongJae Park <sj@kernel.org>,
"Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
Nhat Pham <nphamcs@gmail.com>, Yue Zhao <findns94@gmail.com>
Subject: Re: [PATCH v5 2/2] mm: add swapiness= arg to memory.reclaim
Date: Tue, 2 Jan 2024 12:43:49 -0500 [thread overview]
Message-ID: <ZZRLVYeTjljn0dO5@dschatzberg-fedora-PF3DHTBV> (raw)
In-Reply-To: <ZYQFlynE7CU_Fjoc@tiehlicka>
On Thu, Dec 21, 2023 at 10:29:59AM +0100, Michal Hocko wrote:
> On Wed 20-12-23 07:26:51, Dan Schatzberg wrote:
> > ...
>
> LGTM
> Acked-by: Michal Hocko <mhocko@suse.com.
>
> Just one minor thing. It would be really great to prevent from potential
> incorrect use of mem_cgroup_swappiness. This should be internal function
> to memcg. Now, having scan_control internal to vmscan.c makes that
> harder and moving it out to swap.h or internal.h sounds overreaching.
>
> We could do this at least to reduce those mistakes. I can make it a
> proper patch if this seems reasonable or you can fold it into your patch
> directly.
> ---
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index f98dff23b758..5f3a182e9515 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -92,8 +92,10 @@ struct scan_control {
> unsigned long anon_cost;
> unsigned long file_cost;
>
> - /* Swappiness value for reclaim. NULL will fall back to per-memcg/global value */
> +#ifdef CONFIG_MEMCG
> + /* Swappiness value for reclaim. Always use sc_swappiness()! */
> int *swappiness;
> +#endif
>
> /* Can active folios be deactivated as part of reclaim? */
> #define DEACTIVATE_ANON 1
> @@ -230,6 +232,13 @@ static bool writeback_throttling_sane(struct scan_control *sc)
> #endif
> return false;
> }
> +
> +static int sc_swappiness(struct scan_control *sc, struct mem_cgroup *memcg)
> +{
> + if (sc->swappiness)
> + return *sc->swappiness;
> + return mem_cgroup_swappiness(memcg);
> +}
> #else
> static bool cgroup_reclaim(struct scan_control *sc)
> {
> @@ -245,6 +254,10 @@ static bool writeback_throttling_sane(struct scan_control *sc)
> {
> return true;
> }
> +static int sc_swappiness(struct scan_control *sc, struct mem_cgroup *memcg)
> +{
> + return READ_ONCE(vm_swappiness);
> +}
> #endif
>
> static void set_task_reclaim_state(struct task_struct *task,
> @@ -2330,8 +2343,7 @@ 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->swappiness : mem_cgroup_swappiness(memcg);
> + int swappiness = sc_swappiness(sc, memcg);
> u64 fraction[ANON_AND_FILE];
> u64 denominator = 0; /* gcc */
> enum scan_balance scan_balance;
> @@ -2612,10 +2624,7 @@ static int get_swappiness(struct lruvec *lruvec, struct scan_control *sc)
> mem_cgroup_get_nr_swap_pages(memcg) < MIN_LRU_BATCH)
> return 0;
>
> - if (sc->swappiness)
> - return *sc->swappiness;
> -
> - return mem_cgroup_swappiness(memcg);
> + return sc_swappiness(sc, memcg);
> }
>
> static int get_nr_gens(struct lruvec *lruvec, int type)
> --
> Michal Hocko
> SUSE Labs
Thanks for the review Michal and sorry for the delayed response. Your
patch looks reasonable to me but I'm a bit unclear about the need for
#ifdef - mem_cgroup_swappiness already works correctly regardless of
CONFIG_MEMCG or not - why not make sc->swappiness and sc_swappiness()
unconditional?
Happy to roll that into the next version of my patch.
next prev parent reply other threads:[~2024-01-02 17:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-20 15:26 [PATCH v5 0/2] Add swappiness argument " Dan Schatzberg
2023-12-20 15:26 ` [PATCH v5 1/2] mm: add defines for min/max swappiness Dan Schatzberg
2023-12-21 2:01 ` Nhat Pham
2023-12-22 4:38 ` David Rientjes
2023-12-24 17:14 ` Chris Li
2023-12-20 15:26 ` [PATCH v5 2/2] mm: add swapiness= arg to memory.reclaim Dan Schatzberg
2023-12-21 9:29 ` Michal Hocko
2024-01-02 17:43 ` Dan Schatzberg [this message]
2024-01-03 8:59 ` Michal Hocko
2023-12-22 4:38 ` David Rientjes
2023-12-22 5:31 ` Yu Zhao
2024-01-02 15:21 ` Dan Schatzberg
2024-01-03 0:27 ` Yu Zhao
2024-01-03 15:19 ` Dan Schatzberg
2024-01-03 9:03 ` Michal Hocko
2023-12-24 17:21 ` Chris Li
2024-01-02 22:42 ` Nhat Pham
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=ZZRLVYeTjljn0dO5@dschatzberg-fedora-PF3DHTBV \
--to=schatzberg.dan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=corbet@lwn.net \
--cc=findns94@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=link@vivo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizefan.x@bytedance.com \
--cc=mhocko@suse.com \
--cc=muchun.song@linux.dev \
--cc=nphamcs@gmail.com \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.com \
--cc=sj@kernel.org \
--cc=tj@kernel.org \
--cc=vishal.moola@gmail.com \
--cc=wangkefeng.wang@huawei.com \
--cc=yosryahmed@google.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