From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx156.postini.com [74.125.245.156]) by kanga.kvack.org (Postfix) with SMTP id D67B26B004D for ; Wed, 20 Jun 2012 12:23:33 -0400 (EDT) Received: by bkcjm19 with SMTP id jm19so8291882bkc.14 for ; Wed, 20 Jun 2012 09:23:32 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 20 Jun 2012 21:53:31 +0530 Message-ID: Subject: [PATCH] mm: offlining memory may block forever From: Aaditya Kumar Content-Type: text/plain; charset=ISO-8859-1 Sender: owner-linux-mm@kvack.org List-ID: To: KOSAKI Motohiro Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, Mel Gorman , KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Offlining memory may block forever, waiting for kswapd() to wake up because kswapd() does not check the event kthread->should_stop before sleeping. The proper pattern, from Documentation/memory-barriers.txt, is: --- waker --- event_indicated = 1; wake_up_process(event_daemon); --- sleeper --- for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); if (event_indicated) break; schedule(); } set_current_state() may be wrapped by: prepare_to_wait(); In the kswapd() case, event_indicated is kthread->should_stop. --- offlining memory (waker) --- kswapd_stop() kthread_stop() kthread->should_stop = 1 wake_up_process() wait_for_completion() --- kswapd_try_to_sleep (sleeper) --- kswapd_try_to_sleep() prepare_to_wait() . . schedule() . . finish_wait() The schedule() needs to be protected by a test of kthread->should_stop, which is wrapped by kthread_should_stop(). Reproducer: Do heavy file I/O in background. Do a memory offline/online in a tight loop Signed-off-by: Aaditya Kumar --- diff --git a/mm/vmscan.c b/mm/vmscan.c index eeb3bc9..b60691e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2688,7 +2688,10 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx) * them before going back to sleep. */ set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold); - schedule(); + + if (!kthread_should_stop()) + schedule(); + set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold); } else { if (remaining) -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx140.postini.com [74.125.245.140]) by kanga.kvack.org (Postfix) with SMTP id 3292C6B005D for ; Wed, 20 Jun 2012 13:13:43 -0400 (EDT) Received: by dakp5 with SMTP id p5so12714325dak.14 for ; Wed, 20 Jun 2012 10:13:42 -0700 (PDT) Date: Wed, 20 Jun 2012 10:13:37 -0700 From: Greg KH Subject: Re: [PATCH] mm: offlining memory may block forever Message-ID: <20120620171337.GA10287@kroah.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org List-ID: To: Aaditya Kumar Cc: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, Mel Gorman , KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com On Wed, Jun 20, 2012 at 09:53:31PM +0530, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly. -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx105.postini.com [74.125.245.105]) by kanga.kvack.org (Postfix) with SMTP id 829C26B005A for ; Wed, 20 Jun 2012 14:49:18 -0400 (EDT) Message-ID: <4FE21B21.6070608@jp.fujitsu.com> Date: Wed, 20 Jun 2012 14:49:05 -0400 From: KOSAKI Motohiro MIME-Version: 1.0 Subject: Re: [PATCH] mm: offlining memory may block forever References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: aaditya.kumar.30@gmail.com Cc: kosaki.motohiro@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, mel@csn.ul.ie, kamezawa.hiroyu@jp.fujitsu.com, minchan@kernel.org, mhocko@suse.cz, tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com On 6/20/2012 12:23 PM, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- Please avoid "---". This is used for a separator between a patch description and code. Other than that, Acked-by: KOSAKI Motohiro > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar > > --- > diff --git a/mm/vmscan.c b/mm/vmscan.c > index eeb3bc9..b60691e 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2688,7 +2688,10 @@ static void kswapd_try_to_sleep(pg_data_t > *pgdat, int order, int classzone_idx) > * them before going back to sleep. > */ > set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold); > - schedule(); > + > + if (!kthread_should_stop()) > + schedule(); > + > set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold); > } else { > if (remaining) > -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx196.postini.com [74.125.245.196]) by kanga.kvack.org (Postfix) with SMTP id D7D886B004D for ; Wed, 20 Jun 2012 21:37:36 -0400 (EDT) Message-ID: <4FE27AE8.2080906@kernel.org> Date: Thu, 21 Jun 2012 10:37:44 +0900 From: Minchan Kim MIME-Version: 1.0 Subject: Re: [PATCH] mm: offlining memory may block forever References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Aaditya Kumar Cc: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, Mel Gorman , KAMEZAWA Hiroyuki , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com On 06/21/2012 01:23 AM, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar Reviewed-by: Minchan Kim Nitpick: We can remove kthread_should_stop check earlier in kswapd_try_to_sleep. But it's no biggie. And I hope you change patch title Title : Fix loss of kswapd wakeup in kswapd_stop Description: Offlining memory may block forever because blah, blah, blah. -- Kind regards, Minchan Kim -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from psmtp.com (na3sys010amx109.postini.com [74.125.245.109]) by kanga.kvack.org (Postfix) with SMTP id 196DF6B00CA for ; Thu, 21 Jun 2012 09:04:36 -0400 (EDT) Date: Thu, 21 Jun 2012 14:04:32 +0100 From: Mel Gorman Subject: Re: [PATCH] mm: offlining memory may block forever Message-ID: <20120621130432.GB3953@csn.ul.ie> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: Sender: owner-linux-mm@kvack.org List-ID: To: Aaditya Kumar Cc: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com On Wed, Jun 20, 2012 at 09:53:31PM +0530, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > Acked-by: Mel Gorman -- Mel Gorman SUSE Labs -- 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757111Ab2FTQXe (ORCPT ); Wed, 20 Jun 2012 12:23:34 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:46753 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751301Ab2FTQXd (ORCPT ); Wed, 20 Jun 2012 12:23:33 -0400 MIME-Version: 1.0 Date: Wed, 20 Jun 2012 21:53:31 +0530 Message-ID: Subject: [PATCH] mm: offlining memory may block forever From: Aaditya Kumar To: KOSAKI Motohiro Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, Mel Gorman , KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Offlining memory may block forever, waiting for kswapd() to wake up because kswapd() does not check the event kthread->should_stop before sleeping. The proper pattern, from Documentation/memory-barriers.txt, is: --- waker --- event_indicated = 1; wake_up_process(event_daemon); --- sleeper --- for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); if (event_indicated) break; schedule(); } set_current_state() may be wrapped by: prepare_to_wait(); In the kswapd() case, event_indicated is kthread->should_stop. --- offlining memory (waker) --- kswapd_stop() kthread_stop() kthread->should_stop = 1 wake_up_process() wait_for_completion() --- kswapd_try_to_sleep (sleeper) --- kswapd_try_to_sleep() prepare_to_wait() . . schedule() . . finish_wait() The schedule() needs to be protected by a test of kthread->should_stop, which is wrapped by kthread_should_stop(). Reproducer: Do heavy file I/O in background. Do a memory offline/online in a tight loop Signed-off-by: Aaditya Kumar --- diff --git a/mm/vmscan.c b/mm/vmscan.c index eeb3bc9..b60691e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2688,7 +2688,10 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx) * them before going back to sleep. */ set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold); - schedule(); + + if (!kthread_should_stop()) + schedule(); + set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold); } else { if (remaining) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756902Ab2FTRNo (ORCPT ); Wed, 20 Jun 2012 13:13:44 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:56643 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754407Ab2FTRNm (ORCPT ); Wed, 20 Jun 2012 13:13:42 -0400 Date: Wed, 20 Jun 2012 10:13:37 -0700 From: Greg KH To: Aaditya Kumar Cc: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, Mel Gorman , KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Subject: Re: [PATCH] mm: offlining memory may block forever Message-ID: <20120620171337.GA10287@kroah.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 20, 2012 at 09:53:31PM +0530, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757644Ab2FTStU (ORCPT ); Wed, 20 Jun 2012 14:49:20 -0400 Received: from fgwmail5.fujitsu.co.jp ([192.51.44.35]:35727 "EHLO fgwmail5.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757227Ab2FTStS (ORCPT ); Wed, 20 Jun 2012 14:49:18 -0400 Message-ID: <4FE21B21.6070608@jp.fujitsu.com> Date: Wed, 20 Jun 2012 14:49:05 -0400 From: KOSAKI Motohiro User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 MIME-Version: 1.0 To: aaditya.kumar.30@gmail.com CC: kosaki.motohiro@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, mel@csn.ul.ie, kamezawa.hiroyu@jp.fujitsu.com, minchan@kernel.org, mhocko@suse.cz, tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Subject: Re: [PATCH] mm: offlining memory may block forever References: In-Reply-To: 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 On 6/20/2012 12:23 PM, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- Please avoid "---". This is used for a separator between a patch description and code. Other than that, Acked-by: KOSAKI Motohiro > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar > > --- > diff --git a/mm/vmscan.c b/mm/vmscan.c > index eeb3bc9..b60691e 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -2688,7 +2688,10 @@ static void kswapd_try_to_sleep(pg_data_t > *pgdat, int order, int classzone_idx) > * them before going back to sleep. > */ > set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold); > - schedule(); > + > + if (!kthread_should_stop()) > + schedule(); > + > set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold); > } else { > if (remaining) > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756862Ab2FUBhh (ORCPT ); Wed, 20 Jun 2012 21:37:37 -0400 Received: from LGEMRELSE6Q.lge.com ([156.147.1.121]:53755 "EHLO LGEMRELSE6Q.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756353Ab2FUBhg (ORCPT ); Wed, 20 Jun 2012 21:37:36 -0400 X-AuditID: 9c930179-b7befae000006417-e5-4fe27adc6c81 Message-ID: <4FE27AE8.2080906@kernel.org> Date: Thu, 21 Jun 2012 10:37:44 +0900 From: Minchan Kim User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 Newsgroups: gmane.linux.kernel,gmane.linux.kernel.mm,gmane.linux.kernel.stable To: Aaditya Kumar CC: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, Mel Gorman , KAMEZAWA Hiroyuki , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Subject: Re: [PATCH] mm: offlining memory may block forever References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06/21/2012 01:23 AM, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > > The proper pattern, from Documentation/memory-barriers.txt, is: > --- waker --- > event_indicated = 1; > wake_up_process(event_daemon); > > --- sleeper --- > for (;;) { > set_current_state(TASK_UNINTERRUPTIBLE); > if (event_indicated) > break; > schedule(); > } > > set_current_state() may be wrapped by: > prepare_to_wait(); > > In the kswapd() case, event_indicated is kthread->should_stop. > --- offlining memory (waker) --- > kswapd_stop() > kthread_stop() > kthread->should_stop = 1 > wake_up_process() > wait_for_completion() > > > --- kswapd_try_to_sleep (sleeper) --- > kswapd_try_to_sleep() > prepare_to_wait() > . > . > schedule() > . > . > finish_wait() > > The schedule() needs to be protected by a test of kthread->should_stop, > which is wrapped by kthread_should_stop(). > > Reproducer: > Do heavy file I/O in background. > Do a memory offline/online in a tight loop > > > Signed-off-by: Aaditya Kumar Reviewed-by: Minchan Kim Nitpick: We can remove kthread_should_stop check earlier in kswapd_try_to_sleep. But it's no biggie. And I hope you change patch title Title : Fix loss of kswapd wakeup in kswapd_stop Description: Offlining memory may block forever because blah, blah, blah. -- Kind regards, Minchan Kim From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932142Ab2FUNEh (ORCPT ); Thu, 21 Jun 2012 09:04:37 -0400 Received: from gir.skynet.ie ([193.1.99.77]:43177 "EHLO gir.skynet.ie" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759554Ab2FUNEg (ORCPT ); Thu, 21 Jun 2012 09:04:36 -0400 Date: Thu, 21 Jun 2012 14:04:32 +0100 From: Mel Gorman To: Aaditya Kumar Cc: KOSAKI Motohiro , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@kernel.org, kosaki.motohiro@jp.fujitsu.com, gregkh@linuxfoundation.org, KAMEZAWA Hiroyuki , Minchan Kim , Michal Hocko , tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar@ap.sony.com Subject: Re: [PATCH] mm: offlining memory may block forever Message-ID: <20120621130432.GB3953@csn.ul.ie> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 20, 2012 at 09:53:31PM +0530, Aaditya Kumar wrote: > Offlining memory may block forever, waiting for kswapd() to wake up because > kswapd() does not check the event kthread->should_stop before sleeping. > Acked-by: Mel Gorman -- Mel Gorman SUSE Labs