[Devel] [PATCH VZ9 3/3] mm/memcontrol: make memory.oom_guarantee file also available in cgroup-v2

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Fri Mar 22 08:21:36 MSK 2024


The interface is slightly reworked to be more v2 like:

- show "max" when uninitialized and allow to write it

https://virtuozzo.atlassian.net/browse/PSBM-154224
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>

Feature: mm/oom: OOM guarantee feature
---
 mm/memcontrol.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fcc4b24ba330..f709ed6be891 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5239,6 +5239,14 @@ static u64 mem_cgroup_oom_guarantee_read(struct cgroup_subsys_state *css,
 	return mem_cgroup_from_css(css)->oom_guarantee << PAGE_SHIFT;
 }
 
+static int seq_puts_memcg_tunable(struct seq_file *m, unsigned long value);
+
+static int memory_oom_guarantee_show(struct seq_file *m, void *v)
+{
+	return seq_puts_memcg_tunable(m,
+		READ_ONCE(mem_cgroup_from_seq(m)->oom_guarantee));
+}
+
 static ssize_t mem_cgroup_oom_guarantee_write(struct kernfs_open_file *kops,
 					char *buffer, size_t nbytes, loff_t off)
 {
@@ -5255,6 +5263,22 @@ static ssize_t mem_cgroup_oom_guarantee_write(struct kernfs_open_file *kops,
 	return nbytes;
 }
 
+static ssize_t memory_oom_guarantee_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));
+	unsigned long oom_guarantee;
+	int err;
+
+	buf = strstrip(buf);
+	err = page_counter_memparse(buf, "max", &oom_guarantee);
+	if (err)
+		return err;
+
+	memcg->oom_guarantee = oom_guarantee;
+	return nbytes;
+}
+
 #ifdef CONFIG_CLEANCACHE
 static u64 mem_cgroup_disable_cleancache_read(struct cgroup_subsys_state *css,
 					      struct cftype *cft)
@@ -7629,6 +7653,12 @@ static struct cftype memory_files[] = {
 		.flags = CFTYPE_NS_DELEGATABLE,
 		.write = memory_reclaim,
 	},
+	{
+		.name = "oom_guarantee",
+		.flags = CFTYPE_NOT_ON_ROOT,
+		.seq_show = memory_oom_guarantee_show,
+		.write = memory_oom_guarantee_write,
+	},
 	{ }	/* terminate */
 };
 
-- 
2.43.0



More information about the Devel mailing list