Skip to content

Commit 8e20d4b

Browse files
rganesanakpm00
authored andcommitted
mm/memcontrol: export memcg->watermark via sysfs for v2 memcg
We run a lot of automated tests when building our software and run into OOM scenarios when the tests run unbounded. v1 memcg exports memcg->watermark as "memory.max_usage_in_bytes" in sysfs. We use this metric to heuristically limit the number of tests that can run in parallel based on per test historical data. This metric is currently not exported for v2 memcg and there is no other easy way of getting this information. getrusage() syscall returns "ru_maxrss" which can be used as an approximation but that's the max RSS of a single child process across all children instead of the aggregated max for all child processes. The only work around is to periodically poll "memory.current" but that's not practical for short-lived one-off cgroups. Hence, expose memcg->watermark as "memory.peak" for v2 memcg. Link: https://lkml.kernel.org/r/20220507050916.GA13577@us192.sjc.aristanetworks.com Signed-off-by: Ganesan Rajagopal <rganesan@arista.com> Acked-by: Shakeel Butt <shakeelb@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Roman Gushchin <roman.gushchin@linux.dev> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Roman Gushchin <roman.gushchin@linux.dev> Reviewed-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 78f3908 commit 8e20d4b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,13 @@ PAGE_SIZE multiple when read back.
12291229
the target cgroup. If less bytes are reclaimed than the
12301230
specified amount, -EAGAIN is returned.
12311231

1232+
memory.peak
1233+
A read-only single value file which exists on non-root
1234+
cgroups.
1235+
1236+
The max memory usage recorded for the cgroup and its
1237+
descendants since the creation of the cgroup.
1238+
12321239
memory.oom.group
12331240
A read-write single value file which exists on non-root
12341241
cgroups. The default value is "0".

mm/memcontrol.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6103,6 +6103,14 @@ static u64 memory_current_read(struct cgroup_subsys_state *css,
61036103
return (u64)page_counter_read(&memcg->memory) * PAGE_SIZE;
61046104
}
61056105

6106+
static u64 memory_peak_read(struct cgroup_subsys_state *css,
6107+
struct cftype *cft)
6108+
{
6109+
struct mem_cgroup *memcg = mem_cgroup_from_css(css);
6110+
6111+
return (u64)memcg->memory.watermark * PAGE_SIZE;
6112+
}
6113+
61066114
static int memory_min_show(struct seq_file *m, void *v)
61076115
{
61086116
return seq_puts_memcg_tunable(m,
@@ -6406,6 +6414,11 @@ static struct cftype memory_files[] = {
64066414
.flags = CFTYPE_NOT_ON_ROOT,
64076415
.read_u64 = memory_current_read,
64086416
},
6417+
{
6418+
.name = "peak",
6419+
.flags = CFTYPE_NOT_ON_ROOT,
6420+
.read_u64 = memory_peak_read,
6421+
},
64096422
{
64106423
.name = "min",
64116424
.flags = CFTYPE_NOT_ON_ROOT,

0 commit comments

Comments
 (0)