linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/memcontrol: respect zswap.writeback setting from parent cg too
@ 2024-08-14 17:20 Mike Yuan
  2024-08-14 19:52 ` Nhat Pham
  0 siblings, 1 reply; 18+ messages in thread
From: Mike Yuan @ 2024-08-14 17:20 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, cgroups, Andrew Morton, Muchun Song, Shakeel Butt,
	Roman Gushchin, Michal Hocko, Johannes Weiner, Nhat Pham,
	Mike Yuan

Currently, the behavior of zswap.writeback wrt.
the cgroup hierarchy seems a bit odd. Unlike zswap.max,
it doesn't honor the value from parent cgroups. This
surfaced when people tried to globally disable zswap writeback,
i.e. reserve physical swap space only for hibernation [1] -
disabling zswap.writeback only for the root cgroup results
in subcgroups with zswap.writeback=1 still performing writeback.

The consistency became more noticeable after I introduced
the MemoryZSwapWriteback= systemd unit setting [2] for
controlling the knob. The patch assumed that the kernel would
enforce the value of parent cgroups. It could probably be
workarounded from systemd's side, by going up the slice unit
tree and inherit the value. Yet I think it's more sensible
to make it behave consistently with zswap.max and friends.

[1] https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Disable_zswap_writeback_to_use_the_swap_space_only_for_hibernation
[2] https://github.com/systemd/systemd/pull/31734

Signed-off-by: Mike Yuan <me@yhndnzj.com>
---
 mm/memcontrol.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 8f2f1bb18c9c..2dcdaaf358ce 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -8423,7 +8423,14 @@ void obj_cgroup_uncharge_zswap(struct obj_cgroup *objcg, size_t size)
 bool mem_cgroup_zswap_writeback_enabled(struct mem_cgroup *memcg)
 {
 	/* if zswap is disabled, do not block pages going to the swapping device */
-	return !is_zswap_enabled() || !memcg || READ_ONCE(memcg->zswap_writeback);
+	if (!is_zswap_enabled())
+		return true;
+
+	for (; memcg; memcg = parent_mem_cgroup(memcg))
+		if (!READ_ONCE(memcg->zswap_writeback))
+			return false;
+
+	return true;
 }
 
 static u64 zswap_current_read(struct cgroup_subsys_state *css,
-- 
2.46.0




^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2024-08-22 17:49 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-14 17:20 [PATCH] mm/memcontrol: respect zswap.writeback setting from parent cg too Mike Yuan
2024-08-14 19:52 ` Nhat Pham
2024-08-14 19:53   ` Nhat Pham
2024-08-15 18:39     ` Mike Yuan
2024-08-15 19:10       ` Nhat Pham
2024-08-16 13:25         ` Mike Yuan
2024-08-14 20:22   ` Yosry Ahmed
2024-08-14 20:43     ` Mike Yuan
2024-08-15 19:12       ` Nhat Pham
2024-08-15 22:08         ` Andrew Morton
2024-08-15 22:10           ` Yosry Ahmed
2024-08-15 23:31             ` Nhat Pham
2024-08-19 19:05               ` Yosry Ahmed
2024-08-20  1:01                 ` Andrew Morton
2024-08-20  1:06                   ` Yosry Ahmed
2024-08-20 15:28                     ` Nhat Pham
2024-08-21 16:14     ` Michal Koutný
2024-08-22 17:49       ` Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox