Commit 1e577f97 authored by Shakeel Butt's avatar Shakeel Butt Committed by Linus Torvalds

mm, memcg: introduce memory.events.local

The memory controller in cgroup v2 exposes memory.events file for each
memcg which shows the number of times events like low, high, max, oom
and oom_kill have happened for the whole tree rooted at that memcg.
Users can also poll or register notification to monitor the changes in
that file.  Any event at any level of the tree rooted at memcg will
notify all the listeners along the path till root_mem_cgroup.  There are
existing users which depend on this behavior.

However there are users which are only interested in the events
happening at a specific level of the memcg tree and not in the events in
the underlying tree rooted at that memcg.  One such use-case is a
centralized resource monitor which can dynamically adjust the limits of
the jobs running on a system.  The jobs can create their sub-hierarchy
for their own sub-tasks.  The centralized monitor is only interested in
the events at the top level memcgs of the jobs as it can then act and
adjust the limits of the jobs.  Using the current memory.events for such
centralized monitor is very inconvenient.  The monitor will keep
receiving events which it is not interested and to find if the received
event is interesting, it has to read memory.event files of the next
level and compare it with the top level one.  So, let's introduce
memory.events.local to the memcg which shows and notify for the events
at the memcg level.

Now, does memory.stat and memory.pressure need their local versions.  IMHO
no due to the no internal process contraint of the cgroup v2.  The
memory.stat file of the top level memcg of a job shows the stats and
vmevents of the whole tree.  The local stats or vmevents of the top level
memcg will only change if there is a process running in that memcg but v2
does not allow that.  Similarly for memory.pressure there will not be any
process in the internal nodes and thus no chance of local pressure.

Link: http://lkml.kernel.org/r/20190527174643.209172-1-shakeelb@google.comSigned-off-by: default avatarShakeel Butt <shakeelb@google.com>
Reviewed-by: default avatarRoman Gushchin <guro@fb.com>
Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Acked-by: default avatarMichal Hocko <mhocko@suse.com>
Cc: Vladimir Davydov <vdavydov.dev@gmail.com>
Cc: Chris Down <chris@chrisdown.name>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ec165450
...@@ -1146,6 +1146,11 @@ PAGE_SIZE multiple when read back. ...@@ -1146,6 +1146,11 @@ PAGE_SIZE multiple when read back.
otherwise, a value change in this file generates a file otherwise, a value change in this file generates a file
modified event. modified event.
Note that all fields in this file are hierarchical and the
file modified event can be generated due to an event down the
hierarchy. For for the local events at the cgroup level see
memory.events.local.
low low
The number of times the cgroup is reclaimed due to The number of times the cgroup is reclaimed due to
high memory pressure even though its usage is under high memory pressure even though its usage is under
...@@ -1185,6 +1190,11 @@ PAGE_SIZE multiple when read back. ...@@ -1185,6 +1190,11 @@ PAGE_SIZE multiple when read back.
The number of processes belonging to this cgroup The number of processes belonging to this cgroup
killed by any kind of OOM killer. killed by any kind of OOM killer.
memory.events.local
Similar to memory.events but the fields in the file are local
to the cgroup i.e. not hierarchical. The file modified event
generated on this file reflects only the local events.
memory.stat memory.stat
A read-only flat-keyed file which exists on non-root cgroups. A read-only flat-keyed file which exists on non-root cgroups.
......
...@@ -233,8 +233,9 @@ struct mem_cgroup { ...@@ -233,8 +233,9 @@ struct mem_cgroup {
/* OOM-Killer disable */ /* OOM-Killer disable */
int oom_kill_disable; int oom_kill_disable;
/* memory.events */ /* memory.events and memory.events.local */
struct cgroup_file events_file; struct cgroup_file events_file;
struct cgroup_file events_local_file;
/* handle for "memory.swap.events" */ /* handle for "memory.swap.events" */
struct cgroup_file swap_events_file; struct cgroup_file swap_events_file;
...@@ -281,6 +282,7 @@ struct mem_cgroup { ...@@ -281,6 +282,7 @@ struct mem_cgroup {
/* memory.events */ /* memory.events */
atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS]; atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
atomic_long_t memory_events_local[MEMCG_NR_MEMORY_EVENTS];
unsigned long socket_pressure; unsigned long socket_pressure;
...@@ -747,6 +749,9 @@ static inline void count_memcg_event_mm(struct mm_struct *mm, ...@@ -747,6 +749,9 @@ static inline void count_memcg_event_mm(struct mm_struct *mm,
static inline void memcg_memory_event(struct mem_cgroup *memcg, static inline void memcg_memory_event(struct mem_cgroup *memcg,
enum memcg_memory_event event) enum memcg_memory_event event)
{ {
atomic_long_inc(&memcg->memory_events_local[event]);
cgroup_file_notify(&memcg->events_local_file);
do { do {
atomic_long_inc(&memcg->memory_events[event]); atomic_long_inc(&memcg->memory_events[event]);
cgroup_file_notify(&memcg->events_file); cgroup_file_notify(&memcg->events_file);
......
...@@ -5624,21 +5624,29 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, ...@@ -5624,21 +5624,29 @@ static ssize_t memory_max_write(struct kernfs_open_file *of,
return nbytes; return nbytes;
} }
static void __memory_events_show(struct seq_file *m, atomic_long_t *events)
{
seq_printf(m, "low %lu\n", atomic_long_read(&events[MEMCG_LOW]));
seq_printf(m, "high %lu\n", atomic_long_read(&events[MEMCG_HIGH]));
seq_printf(m, "max %lu\n", atomic_long_read(&events[MEMCG_MAX]));
seq_printf(m, "oom %lu\n", atomic_long_read(&events[MEMCG_OOM]));
seq_printf(m, "oom_kill %lu\n",
atomic_long_read(&events[MEMCG_OOM_KILL]));
}
static int memory_events_show(struct seq_file *m, void *v) static int memory_events_show(struct seq_file *m, void *v)
{ {
struct mem_cgroup *memcg = mem_cgroup_from_seq(m); struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
seq_printf(m, "low %lu\n", __memory_events_show(m, memcg->memory_events);
atomic_long_read(&memcg->memory_events[MEMCG_LOW])); return 0;
seq_printf(m, "high %lu\n", }
atomic_long_read(&memcg->memory_events[MEMCG_HIGH]));
seq_printf(m, "max %lu\n", static int memory_events_local_show(struct seq_file *m, void *v)
atomic_long_read(&memcg->memory_events[MEMCG_MAX])); {
seq_printf(m, "oom %lu\n", struct mem_cgroup *memcg = mem_cgroup_from_seq(m);
atomic_long_read(&memcg->memory_events[MEMCG_OOM]));
seq_printf(m, "oom_kill %lu\n",
atomic_long_read(&memcg->memory_events[MEMCG_OOM_KILL]));
__memory_events_show(m, memcg->memory_events_local);
return 0; return 0;
} }
...@@ -5800,6 +5808,12 @@ static struct cftype memory_files[] = { ...@@ -5800,6 +5808,12 @@ static struct cftype memory_files[] = {
.file_offset = offsetof(struct mem_cgroup, events_file), .file_offset = offsetof(struct mem_cgroup, events_file),
.seq_show = memory_events_show, .seq_show = memory_events_show,
}, },
{
.name = "events.local",
.flags = CFTYPE_NOT_ON_ROOT,
.file_offset = offsetof(struct mem_cgroup, events_local_file),
.seq_show = memory_events_local_show,
},
{ {
.name = "stat", .name = "stat",
.flags = CFTYPE_NOT_ON_ROOT, .flags = CFTYPE_NOT_ON_ROOT,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment