The patch titled do not miss MEMCG_MAX events for enforced allocations Date: Fri, 1 Jul has been added to the -mm mm-unstable branch. Its filename is mm-memcontrol-do-not-miss-memcg_max-events-for-enforced-allocations.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memcontrol-do-not-miss-memcg_max-events-for-enforced-allocations.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm 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 via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Roman Gushchin <roman.gushchin@xxxxxxxxx> Subject: mm: memcontrol: do not miss MEMCG_MAX events for enforced allocations Date: Fri, 1 Jul 2022 20:35:21 -0700 Yafang Shao reported an issue related to the accounting of bpf memory: if a bpf map is charged indirectly for memory consumed from an interrupt context and allocations are enforced, MEMCG_MAX events are not raised. It's not/less of an issue in a generic case because consequent allocations from a process context will trigger the reclaim and MEMCG_MAX events. However a bpf map can belong to a dying/abandoned memory cgroup, so it might never happen. So the cgroup can significantly exceed the memory.max limit without even triggering MEMCG_MAX events. Fix this by making sure that we never enforce allocations without raising a MEMCG_MAX event. Link: https://lkml.kernel.org/r/20220702033521.64630-1-roman.gushchin@xxxxxxxxx Signed-off-by: Roman Gushchin <roman.gushchin@xxxxxxxxx> Reported-by: Yafang Shao <laoar.shao@xxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Michal Hocko <mhocko@xxxxxxxxxx> Cc: Shakeel Butt <shakeelb@xxxxxxxxxx> Cc: Muchun Song <songmuchun@xxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memcontrol.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/mm/memcontrol.c~mm-memcontrol-do-not-miss-memcg_max-events-for-enforced-allocations +++ a/mm/memcontrol.c @@ -2712,6 +2712,7 @@ static int try_charge_memcg(struct mem_c bool passed_oom = false; bool may_swap = true; bool drained = false; + bool raised_max_event = false; unsigned long pflags; retry: @@ -2751,6 +2752,7 @@ retry: goto nomem; memcg_memory_event(mem_over_limit, MEMCG_MAX); + raised_max_event = true; psi_memstall_enter(&pflags); nr_reclaimed = try_to_free_mem_cgroup_pages(mem_over_limit, nr_pages, @@ -2818,6 +2820,13 @@ nomem: return -ENOMEM; force: /* + * If the allocation has to be enforced, don't forget to raise + * a MEMCG_MAX event. + */ + if (!raised_max_event) + memcg_memory_event(mem_over_limit, MEMCG_MAX); + + /* * The allocation either can't fail or will lead to more memory * being freed very soon. Allow memory usage go over the limit * temporarily by force charging it. _ Patches currently in -mm which might be from roman.gushchin@xxxxxxxxx are mm-memcontrol-introduce-mem_cgroup_ino-and-mem_cgroup_get_from_ino.patch mm-shrinkers-introduce-debugfs-interface-for-memory-shrinkers.patch mm-shrinkers-provide-shrinkers-with-names.patch mm-shrinkers-provide-shrinkers-with-names-fix.patch mm-docs-document-shrinker-debugfs.patch tools-add-memcg_shrinkerpy.patch mm-shrinkers-add-scan-interface-for-shrinker-debugfs.patch mm-shrinkers-add-scan-interface-for-shrinker-debugfs-fix.patch mm-memcontrol-do-not-miss-memcg_max-events-for-enforced-allocations.patch