[Devel] [PATCH VZ9 3/3] mm/memcontrol: make memory.oom_guarantee file also available in cgroup-v2
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Mon Mar 25 12:33:54 MSK 2024
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
---
v2:
- correct commit message part about "max"
- make oom_guarantee unsigned long
- update oom_guarantee with xchg()
---
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 fcc4b24ba330..1722a49855ac 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 */
};
--
2.43.0
More information about the Devel
mailing list