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

Konstantin Khorenko khorenko at virtuozzo.com
Tue Mar 26 16:48:42 MSK 2024


The commit is pushed to "branch-rh9-5.14.0-362.18.1.vz9.40.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-362.18.1.vz9.40.3
------>
commit 41df73e2aec29cccec8d91235d99d707b844d731
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Mon Mar 25 17:33:54 2024 +0800

    mm/memcontrol: make memory.oom_guarantee file also available in cgroup-v2
    
    The interface is slightly reworked to be more v2 like:
    
     - switch from "-1" to "max" for max value following cgroup-v2 style
    
    While on it also:
     - make oom_guarantee (unsigned long) similar to regular cgroup limits,
       as we never set more than PAGE_COUNTER_MAX there anyway
     - set oom_guarantee with xchg(), this ensures that update is atomic
    
    https://virtuozzo.atlassian.net/browse/PSBM-154224
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Feature: mm/oom: OOM guarantee feature
---
 include/linux/memcontrol.h |  2 +-
 mm/memcontrol.c            | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 9c2b8774639e..2aa330cb81b4 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -263,7 +263,7 @@ struct mem_cgroup {
 	struct vmpressure vmpressure;
 
 	unsigned long overdraft;
-	unsigned long long oom_guarantee;
+	unsigned long oom_guarantee;
 
 	/*
 	 * Should the OOM killer kill all belonging tasks, had it kill one?
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 19abe1578093..506ce3ee4e6a 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;
+
+	xchg(&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 */
 };
 


More information about the Devel mailing list