The patch titled Subject: mm, memcg: prevent memory.max load tearing has been added to the -mm tree. Its filename is mm-memcg-prevent-memorymax-load-tearing.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-memcg-prevent-memorymax-load-tearing.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-memcg-prevent-memorymax-load-tearing.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Chris Down <chris@xxxxxxxxxxxxxx> Subject: mm, memcg: prevent memory.max load tearing This one is a bit more nuanced because we have memcg_max_mutex, which is mostly just used for enforcing invariants, but we still need to READ_ONCE since (despite its name) it doesn't really protect memory.max access. On write (page_counter_set_max() and memory_max_write()) we use xchg(), which uses smp_mb(), so that's already fine. Link: http://lkml.kernel.org/r/50a31e5f39f8ae6c8fb73966ba1455f0924e8f44.1584034301.git.chris@xxxxxxxxxxxxxx Signed-off-by: Chris Down <chris@xxxxxxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Roman Gushchin <guro@xxxxxx> Cc: Tejun Heo <tj@xxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memcontrol.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/mm/memcontrol.c~mm-memcg-prevent-memorymax-load-tearing +++ a/mm/memcontrol.c @@ -1521,7 +1521,7 @@ void mem_cgroup_print_oom_meminfo(struct pr_info("memory: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->memory)), - K((u64)memcg->memory.max), memcg->memory.failcnt); + K((u64)READ_ONCE(memcg->memory.max)), memcg->memory.failcnt); if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) pr_info("swap: usage %llukB, limit %llukB, failcnt %lu\n", K((u64)page_counter_read(&memcg->swap)), @@ -1552,7 +1552,7 @@ unsigned long mem_cgroup_get_max(struct { unsigned long max; - max = memcg->memory.max; + max = READ_ONCE(memcg->memory.max); if (mem_cgroup_swappiness(memcg)) { unsigned long memsw_max; unsigned long swap_max; @@ -3068,7 +3068,7 @@ static int mem_cgroup_resize_max(struct * Make sure that the new limit (memsw or memory limit) doesn't * break our basic invariant rule memory.max <= memsw.max. */ - limits_invariant = memsw ? max >= memcg->memory.max : + limits_invariant = memsw ? max >= READ_ONCE(memcg->memory.max) : max <= memcg->memsw.max; if (!limits_invariant) { mutex_unlock(&memcg_max_mutex); @@ -3816,8 +3816,8 @@ static int memcg_stat_show(struct seq_fi /* Hierarchical information */ memory = memsw = PAGE_COUNTER_MAX; for (mi = memcg; mi; mi = parent_mem_cgroup(mi)) { - memory = min(memory, mi->memory.max); - memsw = min(memsw, mi->memsw.max); + memory = min(memory, READ_ONCE(mi->memory.max)); + memsw = min(memsw, READ_ONCE(mi->memsw.max)); } seq_printf(m, "hierarchical_memory_limit %llu\n", (u64)memory * PAGE_SIZE); @@ -4326,7 +4326,7 @@ void mem_cgroup_wb_stats(struct bdi_writ *pheadroom = PAGE_COUNTER_MAX; while ((parent = parent_mem_cgroup(memcg))) { - unsigned long ceiling = min(memcg->memory.max, + unsigned long ceiling = min(READ_ONCE(memcg->memory.max), READ_ONCE(memcg->high)); unsigned long used = page_counter_read(&memcg->memory); _ Patches currently in -mm which might be from chris@xxxxxxxxxxxxxx are mm-memcg-fix-corruption-on-64-bit-divisor-in-memoryhigh-throttling.patch mm-memcg-throttle-allocators-based-on-ancestral-memoryhigh.patch mm-memcg-prevent-memoryhigh-load-store-tearing.patch mm-memcg-prevent-memorymax-load-tearing.patch mm-memcg-prevent-memorylow-load-store-tearing.patch mm-memcg-prevent-memorymin-load-store-tearing.patch mm-memcg-prevent-memoryswapmax-load-tearing.patch mm-memcg-prevent-mem_cgroup_protected-store-tearing.patch