vmscan,cgroup: apply mems_effective to reclaim
authorGregory Price <gourry@gourry.net>
Thu, 24 Apr 2025 20:28:06 +0000 (16:28 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 13 May 2025 06:50:33 +0000 (23:50 -0700)
commit7d709f49babc28907b0ac60228f522d2e6216add
tree91a64b10cdb6b772b69a499a281f689e2c7bd9d9
parent8adce0857769d596c5b000d118119e3bb1d63a32
vmscan,cgroup: apply mems_effective to reclaim

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.

This is useful for isolating workloads on a multi-tenant system from
certain classes of memory more consistently - with the noted exceptions.

Note on locking:

The cgroup_get_e_css reference protects the css->effective_mems, and calls
of this interface would be subject to the same race conditions associated
with a non-atomic access to cs->effective_mems.

So while this interface cannot make strong guarantees of correctness, it
can therefore avoid taking a global or rcu_read_lock for performance.

Link: https://lkml.kernel.org/r/20250424202806.52632-3-gourry@gourry.net
Signed-off-by: Gregory Price <gourry@gourry.net>
Suggested-by: Shakeel Butt <shakeel.butt@linux.dev>
Suggested-by: Waiman Long <longman@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Reviewed-by: Waiman Long <longman@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Koutný <mkoutny@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Documentation/ABI/testing/sysfs-kernel-mm-numa
include/linux/cpuset.h
include/linux/memcontrol.h
kernel/cgroup/cpuset.c
mm/memcontrol.c
mm/vmscan.c