[Devel] [PATCH RHEL8 COMMIT] ms/mm: memcg: charge memcg percpu memory to the parent cgroup
Konstantin Khorenko
khorenko at virtuozzo.com
Mon Sep 28 14:54:27 MSK 2020
The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.9
------>
commit 9dc4432ee111848013875a98d6e594c336655255
Author: Roman Gushchin <guro at fb.com>
Date: Tue Aug 11 18:30:25 2020 -0700
ms/mm: memcg: charge memcg percpu memory to the parent cgroup
Memory cgroups are using large chunks of percpu memory to store vmstat
data. Yet this memory is not accounted at all, so in the case when there
are many (dying) cgroups, it's not exactly clear where all the memory is.
Because the size of memory cgroup internal structures can dramatically
exceed the size of object or page which is pinning it in the memory, it's
not a good idea to simply ignore it. It actually breaks the isolation
between cgroups.
Let's account the consumed percpu memory to the parent cgroup.
[guro at fb.com: add WARN_ON_ONCE()s, per Johannes]
Link: http://lkml.kernel.org/r/20200811170611.GB1507044@carbon.DHCP.thefacebook.com
Signed-off-by: Roman Gushchin <guro at fb.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Reviewed-by: Shakeel Butt <shakeelb at google.com>
Acked-by: Dennis Zhou <dennis at kernel.org>
Acked-by: Johannes Weiner <hannes at cmpxchg.org>
Cc: Christoph Lameter <cl at linux.com>
Cc: David Rientjes <rientjes at google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim at lge.com>
Cc: Mel Gorman <mgorman at techsingularity.net>
Cc: Michal Hocko <mhocko at kernel.org>
Cc: Pekka Enberg <penberg at kernel.org>
Cc: Tejun Heo <tj at kernel.org>
Cc: Tobin C. Harding <tobin at kernel.org>
Cc: Vlastimil Babka <vbabka at suse.cz>
Cc: Waiman Long <longman at redhat.com>
Cc: Bixuan Cui <cuibixuan at huawei.com>
Cc: Michal Koutný <mkoutny at suse.com>
Cc: Stephen Rothwell <sfr at canb.auug.org.au>
Link: http://lkml.kernel.org/r/20200623184515.4132564-5-guro@fb.com
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
(cherry picked from commit 3e38e0aaca9eafb12b1c4b731d1c10975cbe7974)
+ fix commit: 9f457179244a ("mm: memcontrol: fix warning when allocating
the root cgroup")
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
Found and suggested by Vasily Averin <vvs at virtuozzo.com>
Backport notices:
* pn->lruvec_stat_local hunk dropped
* memcg->vmstats_percpu is called memcg->stat_cpu in vz8
* memcg->vmstats_local hunk dropped
---
mm/memcontrol.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 68242a72be4d..ff751ca90562 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -4973,7 +4973,8 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node)
if (!pn)
return 1;
- pn->lruvec_stat_cpu = alloc_percpu(struct lruvec_stat);
+ pn->lruvec_stat_cpu = alloc_percpu_gpf(struct lruvec_stat,
+ GFP_KERNEL_ACCOUNT);
if (!pn->lruvec_stat_cpu) {
kfree(pn);
return 1;
@@ -5034,7 +5035,8 @@ static struct mem_cgroup *mem_cgroup_alloc(void)
if (memcg->id.id < 0)
goto fail;
- memcg->stat_cpu = alloc_percpu(struct mem_cgroup_stat_cpu);
+ memcg->stat_cpu = alloc_percpu_gpf(struct mem_cgroup_stat_cpu,
+ GFP_KERNEL_ACCOUNT);
if (!memcg->stat_cpu)
goto fail;
@@ -5075,7 +5077,9 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css)
struct mem_cgroup *memcg;
long error = -ENOMEM;
+ memalloc_use_memcg(parent);
memcg = mem_cgroup_alloc();
+ memalloc_unuse_memcg();
if (!memcg)
return ERR_PTR(error);
More information about the Devel
mailing list