From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753218Ab3K1JZJ (ORCPT ); Thu, 28 Nov 2013 04:25:09 -0500 Received: from gmmr7.centrum.cz ([46.255.225.249]:49470 "EHLO gmmr7.centrum.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751083Ab3K1JZD (ORCPT ); Thu, 28 Nov 2013 04:25:03 -0500 X-Greylist: delayed 369 seconds by postgrey-1.27 at vger.kernel.org; Thu, 28 Nov 2013 04:25:02 EST To: =?utf-8?q?Johannes_Weiner?= , =?utf-8?q?Ma=2C_Xindong?= Subject: =?utf-8?q?Re=3A_=5BPATCH=5D_Fix_race_between_oom_kill_and_task_exit?= Date: Thu, 28 Nov 2013 10:18:50 +0100 From: "azurIt" Cc: =?utf-8?q?akpm=40linux=2Dfoundation=2Eorg?= , =?utf-8?q?mhocko=40suse=2Ecz?= , =?utf-8?q?rientjes=40google=2Ecom?= , =?utf-8?q?rusty=40rustcorp=2Ecom=2Eau?= , =?utf-8?q?linux=2Dmm=40kvack=2Eorg?= , =?utf-8?q?linux=2Dkernel=40vger=2Ekernel=2Eorg?= , =?utf-8?q?=27Peter_Zijlstra=27?= , =?utf-8?q?=27gregkh=40linuxfoundation=2Eorg=27?= , =?utf-8?q?Tu=2C_Xiaobing?= , =?utf-8?q?William_Dauchy?= References: <3917C05D9F83184EAA45CE249FF1B1DD0253093A@shsmsx103.ccr.corp.intel.com> <20131128063505.GN3556@cmpxchg.org> In-Reply-To: <20131128063505.GN3556@cmpxchg.org> X-Mailer: Centrum Email 5.3 X-Priority: 3 X-Original-From: azurit@pobox.sk MIME-Version: 1.0 Message-Id: <20131128101850.9F8A4575@pobox.sk> X-Maser: oho Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Od: Johannes Weiner > Komu: "Ma, Xindong" > Dátum: 28.11.2013 07:54 > Predmet: Re: [PATCH] Fix race between oom kill and task exit > > CC: "akpm@linux-foundation.org" , "mhocko@suse.cz" , "rientjes@google.com" , "rusty@rustcorp.com.au" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "'Peter Zijlstra'" , "'gregkh@linuxfoundation.org'" , "Tu, Xiaobing" , "William Dauchy" >Cc William and azur who might have encountered this problem. > >On Thu, Nov 28, 2013 at 05:09:16AM +0000, Ma, Xindong wrote: >> From: Leon Ma >> Date: Thu, 28 Nov 2013 12:46:09 +0800 >> Subject: [PATCH] Fix race between oom kill and task exit >> >> There is a race between oom kill and task exit. Scenario is: >> TASK A TASK B >> TASK B is selected to oom kill >> in oom_kill_process() >> check PF_EXITING of TASK B >> task call do_exit() >> task set PF_EXITING flag >> write_lock_irq(&tasklist_lock); >> remove TASK B from thread group in __unhash_process() >> write_unlock_irq(&tasklist_lock); >> read_lock(&tasklist_lock); >> traverse threads of TASK B >> read_unlock(&tasklist_lock); >> >> After that, the following traversal of threads in TASK B will not end because TASK B is not in the thread group: >> do { >> .... >> } while_each_thread(p, t); >> >> Signed-off-by: Leon Ma >> Signed-off-by: xiaobing tu >> --- >> mm/oom_kill.c | 20 ++++++++++---------- >> 1 files changed, 10 insertions(+), 10 deletions(-) >> >> diff --git a/mm/oom_kill.c b/mm/oom_kill.c >> index 1e4a600..32ec88d 100644 >> --- a/mm/oom_kill.c >> +++ b/mm/oom_kill.c >> @@ -412,16 +412,6 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, >> static DEFINE_RATELIMIT_STATE(oom_rs, DEFAULT_RATELIMIT_INTERVAL, >> DEFAULT_RATELIMIT_BURST); >> >> - /* >> - * If the task is already exiting, don't alarm the sysadmin or kill >> - * its children or threads, just set TIF_MEMDIE so it can die quickly >> - */ >> - if (p->flags & PF_EXITING) { >> - set_tsk_thread_flag(p, TIF_MEMDIE); >> - put_task_struct(p); >> - return; >> - } >> - >> if (__ratelimit(&oom_rs)) >> dump_header(p, gfp_mask, order, memcg, nodemask); >> >> @@ -437,6 +427,16 @@ void oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, >> * still freeing memory. >> */ >> read_lock(&tasklist_lock); >> + /* >> + * If the task is already exiting, don't alarm the sysadmin or kill >> + * its children or threads, just set TIF_MEMDIE so it can die quickly >> + */ >> + if (p->flags & PF_EXITING) { >> + set_tsk_thread_flag(p, TIF_MEMDIE); >> + put_task_struct(p); >> + read_unlock(&tasklist_lock); >> + return; >> + } >> do { >> list_for_each_entry(child, &t->children, sibling) { >> unsigned int child_points; >> -- >> 1.7.4.1 >> > Hi Johannes, thank you very much! Fortunately, i didn't notice anything like this yet. azur