Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758143Ab1FJVtv (ORCPT ); Fri, 10 Jun 2011 17:49:51 -0400 Received: from smtp-out.google.com ([216.239.44.51]:46529 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753467Ab1FJVtu (ORCPT ); Fri, 10 Jun 2011 17:49:50 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=google.com; s=beta; h=date:from:x-x-sender:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; b=FF/u+7ntHLJXHgLjNkU18IOpGfxWbJDgvpcFxWmGWslmmaioIFA+yVPGkHZWQ/QdmY 9zzidqC8SnBsolFLyABw== Date: Fri, 10 Jun 2011 14:49:35 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@sister.anvils To: KAMEZAWA Hiroyuki cc: Andrea Arcangeli , Ying Han , Dave Jones , Linux Kernel , "linux-mm@kvack.org" , Oleg Nesterov , "akpm@linux-foundation.org" Subject: Re: [PATCH] [BUGFIX] update mm->owner even if no next owner. In-Reply-To: <20110610133021.2eaaf0da.kamezawa.hiroyu@jp.fujitsu.com> Message-ID: References: <20110609212956.GA2319@redhat.com> <20110610091355.2ce38798.kamezawa.hiroyu@jp.fujitsu.com> <20110610113311.409bb423.kamezawa.hiroyu@jp.fujitsu.com> <20110610121949.622e4629.kamezawa.hiroyu@jp.fujitsu.com> <20110610125551.385ea7ed.kamezawa.hiroyu@jp.fujitsu.com> <20110610133021.2eaaf0da.kamezawa.hiroyu@jp.fujitsu.com> User-Agent: Alpine 2.00 (LSU 1167 2008-08-23) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323584-1162693246-1307742583=:28334" X-System-Of-Record: true Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4811 Lines: 124 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323584-1162693246-1307742583=:28334 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE On Fri, 10 Jun 2011, KAMEZAWA Hiroyuki wrote: >=20 > I think this can be a fix.=20 Sorry, I think not: I've not digested your rationale, but three things stand out: 1. Why has this only just started happening? I may not have run that test on 3.0-rc1, but surely I ran it for hours with 2.6.39; maybe not with khugepaged, but certainly with ksmd. 2. Your hunk below: > -=09if (!mm_need_new_owner(mm, p)) > +=09if (!mm_need_new_owner(mm, p)) { > +=09=09rcu_assign_pointer(mm->owner, NULL); is now setting mm->owner to NULL at times when we were sure it did not need updating before (task is not the owner): you're damaging mm->owner. 3. There's a patch from Andrea in 3.0-rc1 which looks very likely to be relevant, 692e0b35427a "mm: thp: optimize memcg charge in khugepaged". I'll try reproducing without that tonight (I crashed in 20 minutes this morning, so it's not too hard). Hugh > maybe good to CC Oleg. > =3D=3D > From dff52fb35af0cf36486965d19ee79e04b59f1dc4 Mon Sep 17 00:00:00 2001 > From: KAMEZAWA Hiroyuki > Date: Fri, 10 Jun 2011 13:15:14 +0900 > Subject: [PATCH] [BUGFIX] update mm->owner even if no next owner. >=20 > A panic is reported. >=20 > > Call Trace: > > =C2=A0[] mem_cgroup_from_task+0x15/0x17 > > =C2=A0[] __mem_cgroup_try_charge+0x148/0x4b4 > > =C2=A0[] ? need_resched+0x23/0x2d > > =C2=A0[] ? preempt_schedule+0x46/0x4f > > =C2=A0[] mem_cgroup_charge_common+0x9a/0xce > > =C2=A0[] mem_cgroup_newpage_charge+0x5d/0x5f > > =C2=A0[] khugepaged+0x5da/0xfaf > > =C2=A0[] ? __init_waitqueue_head+0x4b/0x4b > > =C2=A0[] ? add_mm_counter.constprop.5+0x13/0x13 > > =C2=A0[] kthread+0xa8/0xb0 > > =C2=A0[] ? sub_preempt_count+0xa1/0xb4 > > =C2=A0[] kernel_thread_helper+0x4/0x10 > > =C2=A0[] ? retint_restore_args+0x13/0x13 > > =C2=A0[] ? __init_kthread_worker+0x5a/0x5a >=20 > The code is. > > return container_of(task_subsys_state(p, mem_cgroup_subsys_id), > > struct mem_cgroup, css); >=20 >=20 > What happens here is accssing a freed task struct "p" from mm->owner. > So, it's doubtful that mm->owner points to freed task struct. >=20 > At thread exit, we need to handle mm->owner. If exitting-thread =3D=3D mm= ->owner, > we modify mm->owner to points to other exisiting task. But, we do not upd= ate > mm->owner when there are no more threads. But if a kernel thread, like kh= ugepaged, > picks up a mm_struct without updating mm->users, there is a trouble. >=20 > When mm_users shows that the task is the last task belongs to mm. > mm->owner is not updated and remained to point to the task. So, in this c= ase, > mm->owner points to a not exisiting task. This was good because if there > are no thread, no charge happens in old days. But now, we have ksm and > khugepaged. >=20 > rcu_read_lock() used in memcg is of no use because mm->owner can be > freed before we take rcu_read_lock. > Then, mm->owner should be cleared if there are no next owner. >=20 > Reported-by: Hugh Dickins > Reported-by: Dave Jones > Signed-off-by: KAMEZAWA Hiroyuki > --- > kernel/exit.c | 6 ++++-- > 1 files changed, 4 insertions(+), 2 deletions(-) >=20 > diff --git a/kernel/exit.c b/kernel/exit.c > index 20a4064..dbc3736 100644 > --- a/kernel/exit.c > +++ b/kernel/exit.c > @@ -582,8 +582,10 @@ void mm_update_next_owner(struct mm_struct *mm) > =09struct task_struct *c, *g, *p =3D current; > =20 > retry: > -=09if (!mm_need_new_owner(mm, p)) > +=09if (!mm_need_new_owner(mm, p)) { > +=09=09rcu_assign_pointer(mm->owner, NULL); > =09=09return; > +=09} > =20 > =09read_lock(&tasklist_lock); > =09/* > @@ -617,7 +619,7 @@ retry: > =09 * most likely racing with swapoff (try_to_unuse()) or /proc or > =09 * ptrace or page migration (get_task_mm()). Mark owner as NULL. > =09 */ > -=09mm->owner =3D NULL; > +=09rcu_assign_pointer(mm->owner, NULL); > =09return; > =20 > assign_new_owner: > --=20 > 1.7.4.1 --8323584-1162693246-1307742583=:28334-- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/