From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757081AbYISD3a (ORCPT ); Thu, 18 Sep 2008 23:29:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756063AbYISD3V (ORCPT ); Thu, 18 Sep 2008 23:29:21 -0400 Received: from E23SMTP06.au.ibm.com ([202.81.18.175]:32914 "EHLO e23smtp06.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755831AbYISD3V (ORCPT ); Thu, 18 Sep 2008 23:29:21 -0400 Message-ID: <48D31C59.7050404@linux.vnet.ibm.com> Date: Thu, 18 Sep 2008 20:28:25 -0700 From: Balbir Singh Reply-To: balbir@linux.vnet.ibm.com Organization: IBM User-Agent: Thunderbird 2.0.0.16 (X11/20080725) MIME-Version: 1.0 To: righi.andrea@gmail.com CC: Andrew Morton , KAMEZAWA Hiroyuki , Paul Menage , containers@lists.linux-foundation.org, linux-mm@kvack.org, LKML Subject: Re: [PATCH -mm] memrlimit: fix task_lock() recursive locking (v2) References: <48D2CD1D.9040202@gmail.com> In-Reply-To: <48D2CD1D.9040202@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrea Righi wrote: > Since we hold task_lock(), we know that p->mm cannot change and we don't have > to worry about incrementing mm_users. So, just use p->mm directly and > check that we've not picked a kernel thread. > > Signed-off-by: Andrea Righi > --- > kernel/cgroup.c | 3 ++- > mm/memrlimitcgroup.c | 10 ++++------ > 2 files changed, 6 insertions(+), 7 deletions(-) > > diff --git a/kernel/cgroup.c b/kernel/cgroup.c > index 678a680..03cc925 100644 > --- a/kernel/cgroup.c > +++ b/kernel/cgroup.c > @@ -2757,7 +2757,8 @@ void cgroup_fork_callbacks(struct task_struct *child) > * invoke this routine, since it assigns the mm->owner the first time > * and does not change it. > * > - * The callbacks are invoked with mmap_sem held in read mode. > + * The callbacks are invoked with task_lock held and mmap_sem held in read > + * mode. > */ > void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) > { > diff --git a/mm/memrlimitcgroup.c b/mm/memrlimitcgroup.c > index 8ee74f6..b3d20f5 100644 > --- a/mm/memrlimitcgroup.c > +++ b/mm/memrlimitcgroup.c > @@ -238,7 +238,7 @@ out: > } > > /* > - * This callback is called with mmap_sem held > + * This callback is called with mmap_sem and task_lock held > */ > static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > struct cgroup *old_cgrp, > @@ -246,9 +246,9 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > struct task_struct *p) > { > struct memrlimit_cgroup *memrcg, *old_memrcg; > - struct mm_struct *mm = get_task_mm(p); > + struct mm_struct *mm = p->mm; > > - BUG_ON(!mm); > + BUG_ON(!mm || (p->flags & PF_KTHREAD)); > > /* > * If we don't have a new cgroup, we just uncharge from the old one. > @@ -258,7 +258,7 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > memrcg = memrlimit_cgroup_from_cgrp(cgrp); > if (res_counter_charge(&memrcg->as_res, > mm->total_vm << PAGE_SHIFT)) > - goto out; > + return; > } > > if (old_cgrp) { > @@ -266,8 +266,6 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > res_counter_uncharge(&old_memrcg->as_res, > mm->total_vm << PAGE_SHIFT); > } > -out: > - mmput(mm); > } Seems reasonable Acked-by: Balbir Singh -- Balbir From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from sd0109e.au.ibm.com (d23rh905.au.ibm.com [202.81.18.225]) by e23smtp06.au.ibm.com (8.13.1/8.13.1) with ESMTP id m8J3STEA001437 for ; Fri, 19 Sep 2008 13:28:29 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by sd0109e.au.ibm.com (8.13.8/8.13.8/NCO v9.1) with ESMTP id m8J3Sjxh266904 for ; Fri, 19 Sep 2008 13:29:18 +1000 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m8J3Sit5024645 for ; Fri, 19 Sep 2008 13:28:45 +1000 Message-ID: <48D31C59.7050404@linux.vnet.ibm.com> Date: Thu, 18 Sep 2008 20:28:25 -0700 From: Balbir Singh Reply-To: balbir@linux.vnet.ibm.com MIME-Version: 1.0 Subject: Re: [PATCH -mm] memrlimit: fix task_lock() recursive locking (v2) References: <48D2CD1D.9040202@gmail.com> In-Reply-To: <48D2CD1D.9040202@gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org Return-Path: To: righi.andrea@gmail.com Cc: Andrew Morton , KAMEZAWA Hiroyuki , Paul Menage , containers@lists.linux-foundation.org, linux-mm@kvack.org, LKML List-ID: Andrea Righi wrote: > Since we hold task_lock(), we know that p->mm cannot change and we don't have > to worry about incrementing mm_users. So, just use p->mm directly and > check that we've not picked a kernel thread. > > Signed-off-by: Andrea Righi > --- > kernel/cgroup.c | 3 ++- > mm/memrlimitcgroup.c | 10 ++++------ > 2 files changed, 6 insertions(+), 7 deletions(-) > > diff --git a/kernel/cgroup.c b/kernel/cgroup.c > index 678a680..03cc925 100644 > --- a/kernel/cgroup.c > +++ b/kernel/cgroup.c > @@ -2757,7 +2757,8 @@ void cgroup_fork_callbacks(struct task_struct *child) > * invoke this routine, since it assigns the mm->owner the first time > * and does not change it. > * > - * The callbacks are invoked with mmap_sem held in read mode. > + * The callbacks are invoked with task_lock held and mmap_sem held in read > + * mode. > */ > void cgroup_mm_owner_callbacks(struct task_struct *old, struct task_struct *new) > { > diff --git a/mm/memrlimitcgroup.c b/mm/memrlimitcgroup.c > index 8ee74f6..b3d20f5 100644 > --- a/mm/memrlimitcgroup.c > +++ b/mm/memrlimitcgroup.c > @@ -238,7 +238,7 @@ out: > } > > /* > - * This callback is called with mmap_sem held > + * This callback is called with mmap_sem and task_lock held > */ > static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > struct cgroup *old_cgrp, > @@ -246,9 +246,9 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > struct task_struct *p) > { > struct memrlimit_cgroup *memrcg, *old_memrcg; > - struct mm_struct *mm = get_task_mm(p); > + struct mm_struct *mm = p->mm; > > - BUG_ON(!mm); > + BUG_ON(!mm || (p->flags & PF_KTHREAD)); > > /* > * If we don't have a new cgroup, we just uncharge from the old one. > @@ -258,7 +258,7 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > memrcg = memrlimit_cgroup_from_cgrp(cgrp); > if (res_counter_charge(&memrcg->as_res, > mm->total_vm << PAGE_SHIFT)) > - goto out; > + return; > } > > if (old_cgrp) { > @@ -266,8 +266,6 @@ static void memrlimit_cgroup_mm_owner_changed(struct cgroup_subsys *ss, > res_counter_uncharge(&old_memrcg->as_res, > mm->total_vm << PAGE_SHIFT); > } > -out: > - mmput(mm); > } Seems reasonable Acked-by: Balbir Singh -- Balbir -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org