diff mbox series

[RFC,v5,3/3] memcg: Notify on memory.max.effective changes

Message ID 20240606152232.20253-4-mkoutny@suse.com (mailing list archive)
State New
Headers show
Series Add memory.max.effective for application's allocators | expand

Commit Message

Michal Koutný June 6, 2024, 3:22 p.m. UTC
When users are interested in cgroup's effective limit, they typically
respond to the value somehow and therefore they should be notified when
the value changes. Use the standard menchanism of triggering a
modification of respective cgroup file.

Signed-off-by: Michal Koutný <mkoutny@suse.com>
---
 include/linux/memcontrol.h |  2 ++
 mm/memcontrol.c            | 10 ++++++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 030d34e9d117..79ecbbd87c4c 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -232,6 +232,8 @@  struct mem_cgroup {
 	/* memory.events and memory.events.local */
 	struct cgroup_file events_file;
 	struct cgroup_file events_local_file;
+	/* memory.max.effective */
+	struct cgroup_file mem_max_file;
 
 	/* handle for "memory.swap.events" */
 	struct cgroup_file swap_events_file;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index a889385f6033..72c8e4693506 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -7022,6 +7022,7 @@  static ssize_t memory_max_write(struct kernfs_open_file *of,
 				char *buf, size_t nbytes, loff_t off)
 {
 	struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
+	struct mem_cgroup *iter;
 	unsigned int nr_reclaims = MAX_RECLAIM_RETRIES;
 	bool drained = false;
 	unsigned long max;
@@ -7061,6 +7062,14 @@  static ssize_t memory_max_write(struct kernfs_open_file *of,
 			break;
 	}
 
+	/*
+	 * Notification about limit tightening, not about coming OOMs, so it
+	 * can be after reclaim.
+	 */
+	for_each_mem_cgroup_tree(iter, memcg) {
+		cgroup_file_notify(&iter->mem_max_file);
+	}
+
 	memcg_wb_domain_size_changed(memcg);
 	return nbytes;
 }
@@ -7275,6 +7284,7 @@  static struct cftype memory_files[] = {
 	{
 		.name = "max.effective",
 		.flags = CFTYPE_NOT_ON_ROOT,
+		.file_offset = offsetof(struct mem_cgroup, mem_max_file),
 		.seq_show = memory_max_effective_show,
 	},
 	{