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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 include/linux/memcontrol.h |  2 ++
 mm/memcontrol.c            | 10 ++++++++++
 2 files changed, 12 insertions(+)

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,
 	},
 	{
-- 
2.45.1





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux