From: Waiman Long <llong@redhat.com>
To: Gregory Price <gourry@gourry.net>, linux-mm@kvack.org
Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com, tj@kernel.org, hannes@cmpxchg.org,
mkoutny@suse.com, akpm@linux-foundation.org
Subject: Re: [RFC PATCH] vmscan,cgroup: apply mems_effective to reclaim
Date: Tue, 8 Apr 2025 14:36:16 -0400 [thread overview]
Message-ID: <b978ec91-306f-45d5-8d88-91febebb8e48@redhat.com> (raw)
In-Reply-To: <20250320210919.439964-1-gourry@gourry.net>
On 3/20/25 5:09 PM, Gregory Price wrote:
> It is possible for a reclaimer to cause demotions of an lruvec belonging
> to a cgroup with cpuset.mems set to exclude some nodes. Attempt to apply
> this limitation based on the lruvec's memcg and prevent demotion.
>
> Notably, this may still allow demotion of shared libraries or any memory
> first instantiated in another cgroup. This means cpusets still cannot
> cannot guarantee complete isolation when demotion is enabled, and the
> docs have been updated to reflect this.
>
>
> Note: This is a fairly hacked up method that probably overlooks some
> cgroup/cpuset controls or designs. RFCing now for some discussion
> at LSFMM '25.
>
>
> Signed-off-by: Gregory Price <gourry@gourry.net>
> ---
> .../ABI/testing/sysfs-kernel-mm-numa | 14 +++++---
> include/linux/cpuset.h | 2 ++
> kernel/cgroup/cpuset.c | 10 ++++++
> mm/vmscan.c | 32 ++++++++++++-------
> 4 files changed, 41 insertions(+), 17 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-numa b/Documentation/ABI/testing/sysfs-kernel-mm-numa
> index 77e559d4ed80..27cdcab901f7 100644
> --- a/Documentation/ABI/testing/sysfs-kernel-mm-numa
> +++ b/Documentation/ABI/testing/sysfs-kernel-mm-numa
> @@ -16,9 +16,13 @@ Description: Enable/disable demoting pages during reclaim
> Allowing page migration during reclaim enables these
> systems to migrate pages from fast tiers to slow tiers
> when the fast tier is under pressure. This migration
> - is performed before swap. It may move data to a NUMA
> - node that does not fall into the cpuset of the
> - allocating process which might be construed to violate
> - the guarantees of cpusets. This should not be enabled
> - on systems which need strict cpuset location
> + is performed before swap if an eligible numa node is
> + present in cpuset.mems for the cgroup. If cpusets.mems
> + changes at runtime, it may move data to a NUMA node that
> + does not fall into the cpuset of the new cpusets.mems,
> + which might be construed to violate the guarantees of
> + cpusets. Shared memory, such as libraries, owned by
> + another cgroup may still be demoted and result in memory
> + use on a node not present in cpusets.mem. This should not
> + be enabled on systems which need strict cpuset location
> guarantees.
> diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
> index 835e7b793f6a..d4169f1b1719 100644
> --- a/include/linux/cpuset.h
> +++ b/include/linux/cpuset.h
> @@ -171,6 +171,8 @@ static inline void set_mems_allowed(nodemask_t nodemask)
> task_unlock(current);
> }
>
> +bool memcg_mems_allowed(struct mem_cgroup *memcg, int nid);
> +
> #else /* !CONFIG_CPUSETS */
>
You should also define an inline function for the !CONFIG_CPUSETS case.
> static inline bool cpusets_enabled(void) { return false; }
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 0f910c828973..bb9669cc105d 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -4296,3 +4296,13 @@ void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task)
> seq_printf(m, "Mems_allowed_list:\t%*pbl\n",
> nodemask_pr_args(&task->mems_allowed));
> }
> +
> +bool memcg_mems_allowed(struct mem_cgroup *memcg, int nid)
> +{
> + struct cgroup_subsys_state *css;
> + struct cpuset *cs;
> +
> + css = cgroup_get_e_css(memcg->css.cgroup, &cpuset_cgrp_subsys);
> + cs = css ? container_of(css, struct cpuset, css) : NULL;
> + return cs ? node_isset(nid, cs->effective_mems) : true;
As said by Johannes, you will need to take the callback_lock to ensure
the stability of effective_mems. I also second his suggestion of
defining a cgroup_mems_allowed() here and do the the memcg to cgroup
translation outside of cpuset.c.
Cheers,
Longman
prev parent reply other threads:[~2025-04-08 18:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 21:09 [RFC PATCH] vmscan,cgroup: apply mems_effective to reclaim Gregory Price
2025-04-08 18:17 ` Johannes Weiner
2025-04-08 18:36 ` Waiman Long [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=b978ec91-306f-45d5-8d88-91febebb8e48@redhat.com \
--to=llong@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=gourry@gourry.net \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mkoutny@suse.com \
--cc=tj@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.