From: Daisuke Nishimura on
We should increase/decrease css->refcnt properly in charging/uncharging compound pages.

Without this patch, a bug like below happens:

1. create a memcg directory.
2. run a program which uses enough memory to allocate them as transparent huge pages.
3. kill the program.
4. try to remove the directory, which will never finish.

Signed-off-by: Daisuke Nishimura <nishimura(a)>
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index b1ac9b1..b74bd83 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1650,8 +1650,9 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm,
if (csize > page_size)
refill_stock(mem, csize - page_size);
+ /* increase css->refcnt by the number of tail pages */
if (page_size != PAGE_SIZE)
- __css_get(&mem->css, page_size);
+ __css_get(&mem->css, (page_size >> PAGE_SHIFT) - 1);
return 0;
@@ -2237,7 +2238,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
memcg_check_events(mem, page);
/* at swapout, this memcg will be accessed to record to swap */
- css_put(&mem->css);
+ __css_put(&mem->css, page_size >> PAGE_SHIFT);

return mem;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)
More majordomo info at
Please read the FAQ at