[Devel,rh7,6/7] mm/memcg: don't release memcg->css too early

Submitted by Andrey Ryabinin on March 31, 2017, 1:51 p.m.

Details

Message ID 20170331135111.16715-6-aryabinin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrey Ryabinin March 31, 2017, 1:51 p.m.
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>
---
 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;
 }