From: Balbir Singh mm_owner_changed callback can also be called with new task set to NULL. (race between try_to_unuse() and mm->owner exiting). Surprisingly the order of cgroup arguments being passed was incorrect (proves that we did not run into mm_owner_changed callback at all). Signed-off-by: Balbir Singh Cc: Sudhir Kumar Cc: YAMAMOTO Takashi Cc: Paul Menage Cc: Li Zefan Cc: Pavel Emelianov Cc: Balbir Singh Cc: KAMEZAWA Hiroyuki Cc: David Rientjes Cc: Vivek Goyal Cc: Hugh Dickins Signed-off-by: Andrew Morton --- mm/memrlimitcgroup.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff -puN mm/memrlimitcgroup.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-enhance-mm_owner_changed-callback-to-deal-with-exited-owner mm/memrlimitcgroup.c --- a/mm/memrlimitcgroup.c~memrlimit-add-memrlimit-controller-accounting-and-control-memory-rlimit-enhance-mm_owner_changed-callback-to-deal-with-exited-owner +++ a/mm/memrlimitcgroup.c @@ -73,6 +73,12 @@ void memrlimit_cgroup_uncharge_as(struct { struct memrlimit_cgroup *memrcg; + /* + * Uncharge happened as a part of the mm_owner_changed callback + */ + if (!mm->owner) + return; + memrcg = memrlimit_cgroup_from_task(mm->owner); res_counter_uncharge(&memrcg->as_res, (nr_pages << PAGE_SHIFT)); } @@ -193,8 +199,8 @@ out: * This callback is called with mmap_sem held */ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, - struct cgroup *cgrp, struct cgroup *old_cgrp, + struct cgroup *cgrp, struct task_struct *p) { struct memrlimit_cgroup *memrcg, *old_memrcg; @@ -204,7 +210,12 @@ static void memrlimit_cgroup_mm_owner_ch memrcg = memrlimit_cgroup_from_cgrp(cgrp); old_memrcg = memrlimit_cgroup_from_cgrp(old_cgrp); - if (res_counter_charge(&memrcg->as_res, (mm->total_vm << PAGE_SHIFT))) + /* + * If we don't have a new cgroup, we just uncharge from the old one. + * It means that the task is going away + */ + if (memrcg && + res_counter_charge(&memrcg->as_res, (mm->total_vm << PAGE_SHIFT))) goto out; res_counter_uncharge(&old_memrcg->as_res, (mm->total_vm << PAGE_SHIFT)); out: _