Re: [-mm][PATCH 2/2] Memory rlimit enhance mm_owner_changed callback to deal with exited owner

From: Paul Menage
Date: Mon Aug 11 2008 - 20:39:49 EST


On Mon, Aug 11, 2008 at 3:07 AM, Balbir Singh <balbir@xxxxxxxxxxxxxxxxxx> wrote:
>
>
> 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 <balbir@xxxxxxxxxxxxxxxxxx>

Acked-by: Paul Menage <menage@xxxxxxxxxx>


> ---
>
> mm/memrlimitcgroup.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff -puN mm/memrlimitcgroup.c~memrlimit-handle-mm-owner-notification-with-task-null mm/memrlimitcgroup.c
> --- linux-2.6.27-rc1/mm/memrlimitcgroup.c~memrlimit-handle-mm-owner-notification-with-task-null 2008-08-05 10:56:56.000000000 +0530
> +++ linux-2.6.27-rc1-balbir/mm/memrlimitcgroup.c 2008-08-05 11:24:04.000000000 +0530
> @@ -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));
> }
> @@ -235,8 +241,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;
> @@ -246,7 +252,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:
> _
>
> --
> Warm Regards,
> Balbir Singh
> Linux Technology Center
> IBM, ISTL
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/