diff --git a/mm/memcontrol.c b/mm/memcontrol.c index fe51d5e61389fd9166c9153ab911c52a91eccb68..9e7a4e5219170955bc640dd1dc43b15bc2b174e7 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2381,13 +2381,14 @@ int __memcg_kmem_charge_memcg(struct page *page, gfp_t gfp, int order, if (!memcg_kmem_online(memcg)) return 0; - if (!page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) - return -ENOMEM; - ret = try_charge(memcg, gfp, nr_pages); - if (ret) { - page_counter_uncharge(&memcg->kmem, nr_pages); + if (ret) return ret; + + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && + !page_counter_try_charge(&memcg->kmem, nr_pages, &counter)) { + cancel_charge(memcg, nr_pages); + return -ENOMEM; } page->mem_cgroup = memcg; @@ -2416,7 +2417,9 @@ void __memcg_kmem_uncharge(struct page *page, int order) VM_BUG_ON_PAGE(mem_cgroup_is_root(memcg), page); - page_counter_uncharge(&memcg->kmem, nr_pages); + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) + page_counter_uncharge(&memcg->kmem, nr_pages); + page_counter_uncharge(&memcg->memory, nr_pages); if (do_memsw_account()) page_counter_uncharge(&memcg->memsw, nr_pages); @@ -2922,7 +2925,8 @@ static int memcg_propagate_kmem(struct mem_cgroup *memcg) * onlined after this point, because it has at least one child * already. */ - if (memcg_kmem_online(parent)) + if (cgroup_subsys_on_dfl(memory_cgrp_subsys) || + memcg_kmem_online(parent)) ret = memcg_online_kmem(memcg); mutex_unlock(&memcg_limit_mutex); return ret;