[Devel,RHEL7,COMMIT] mm/memcg: don't release memcg->css too early

Submitted by Konstantin Khorenko on March 31, 2017, 3:13 p.m.

Details

Message ID 201703311513.v2VFDJJu001826@finist_cl7.x64_64.work.ct
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko March 31, 2017, 3:13 p.m.
The commit is pushed to "branch-rh7-3.10.0-514.10.2.vz7.29.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.10.2.vz7.29.9
------>
commit 34ce21ef4c667a7229a1d42634d68f8298a5321f
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
Date:   Fri Mar 31 19:13:19 2017 +0400

    mm/memcg: don't release memcg->css too early
    
    We can put css only after assigning memcg to pc->mem_cgroup:
    	pc->mem_cgroup = memcg;
    
    https://jira.sw.ru/browse/PSBM-62827
    Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
    
    Note: mainstream has already reworked this code, so not affected.
---
 mm/memcontrol.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 4e1dbbb..1999dff 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3387,10 +3387,10 @@  __memcg_kmem_newpage_charge(struct page *page, gfp_t gfp, int order)
 	}
 
 	ret = memcg_charge_kmem(memcg, gfp, 1 << order);
-	css_put(&memcg->css);
-
-	if (ret)
+	if (ret) {
+		css_put(&memcg->css);
 		return false;
+	}
 
 	pc = lookup_page_cgroup(page);
 	pc->mem_cgroup = memcg;
@@ -3398,6 +3398,7 @@  __memcg_kmem_newpage_charge(struct page *page, gfp_t gfp, int order)
 
 	__SetPageKmemcg(page);
 
+	css_put(&memcg->css);
 	return true;
 }