History

mm, memcg: consider subtrees in memory.events

memory.stat and other files already consider subtrees in their output, and we should too in order to not present an inconsistent interface. The current situation is fairly confusing, because people interacting with cgroups expect hierarchical behaviour in the vein of memory.stat, cgroup.events, and other files. For example, this causes confusion when debugging reclaim events under low, as currently these always read "0" at non-leaf memcg nodes, which frequently causes people to misdiagnose breach behaviour. The same confusion applies to other counters in this file when debugging issues. Aggregation is done at write time instead of at read-time since these counters aren't hot (unlike memory.stat which is per-page, so it does it at read time), and it makes sense to bundle this with the file notifications. After this patch, events are propagated up the hierarchy: [root@ktst ~]# cat /sys/fs/cgroup/system.slice/memory.events low 0 high 0 max 0 oom 0 oom_kill 0 [root@ktst ~]# systemd-run -p MemoryMax=1 true Running as unit: run-r251162a189fb4562b9dabfdc9b0422f5.service [root@ktst ~]# cat /sys/fs/cgroup/system.slice/memory.events low 0 high 0 max 7 oom 1 oom_kill 1 As this is a change in behaviour, this can be reverted to the old behaviour by mounting with the `memory_localevents' flag set. However, we use the new behaviour by default as there's a lack of evidence that there are any current users of memory.events that would find this change undesirable. akpm: this is a behaviour change, so Cc:stable. THis is so that forthcoming distros which use cgroup v2 are more likely to pick up the revised behaviour.

Chris Down committed 7 years ago

Commit 9852ae31 parent bc814264 files · +36 −4Browse files

Showing the changes to include/linux (2 of 4 files). Show all

Unified · Split

2 files
  1. include/linux/cgroup-defs.h +5 −0
  2. include/linux/memcontrol.h +8 −2
include/linux/cgroup-defs.h+5−0
@@ -89,6 +89,11 @@ enum { · 88 unmodified lines
8989 * Enable cpuset controller in v1 cgroup to use v2 behavior.
9090 */
9191 CGRP_ROOT_CPUSET_V2_MODE = (1 << 4),
92+
93+ /*
94+ * Enable legacy local memory.events.
95+ */
96+ CGRP_ROOT_MEMORY_LOCAL_EVENTS = (1 << 5),
9297 };
9398
9499 /* cftype->flags */
include/linux/memcontrol.h+8−2
@@ -737,8 +737,14 @@ static inline void count_memcg_event_mm(struct mm_struct *mm, · 736 unmodified lines
737737 static inline void memcg_memory_event(struct mem_cgroup *memcg,
738738 enum memcg_memory_event event)
739739 {
740− atomic_long_inc(&memcg->memory_events[event]);
741− cgroup_file_notify(&memcg->events_file);
740+ do {
741+ atomic_long_inc(&memcg->memory_events[event]);
742+ cgroup_file_notify(&memcg->events_file);
743+
744+ if (cgrp_dfl_root.flags & CGRP_ROOT_MEMORY_LOCAL_EVENTS)
745+ break;
746+ } while ((memcg = parent_mem_cgroup(memcg)) &&
747+ !mem_cgroup_is_root(memcg));
742748 }
743749
744750 static inline void memcg_memory_event_mm(struct mm_struct *mm,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t