From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967921AbcA1Wd4 (ORCPT ); Thu, 28 Jan 2016 17:33:56 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33114 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967566AbcA1Wdx (ORCPT ); Thu, 28 Jan 2016 17:33:53 -0500 Date: Thu, 28 Jan 2016 23:33:51 +0100 From: Michal Hocko To: Andrew Morton Cc: Johannes Weiner , Mel Gorman , Tetsuo Handa , David Rientjes , Linus Torvalds , Oleg Nesterov , Hugh Dickins , Andrea Argangeli , Rik van Riel , linux-mm@kvack.org, LKML Subject: Re: [PATCH 3/2] oom: clear TIF_MEMDIE after oom_reaper managed to unmap the address space Message-ID: <20160128223351.GA14803@dhcp22.suse.cz> References: <1452094975-551-1-git-send-email-mhocko@kernel.org> <1452516120-5535-1-git-send-email-mhocko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452516120-5535-1-git-send-email-mhocko@kernel.org> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I have missed one important point. exit_oom_victim has to do test_and_clear to make sure we do not race now with this patch. So we need to fold the following into the patch --- >>From 296166b049ceb8b3199019a24aebab032998ebb0 Mon Sep 17 00:00:00 2001 From: Michal Hocko Date: Thu, 28 Jan 2016 23:27:26 +0100 Subject: [PATCH] oom-clear-tif_memdie-after-oom_reaper-managed-to-unmap-the-address-space-fix Now that exit_oom_victim might be called on a remote task from __oom_reap_task we have to check and clear the flag atomically otherwise we might race and underflow oom_victims or wake up waiters too early. Signed-off-by: Michal Hocko --- mm/oom_kill.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 7209e517adf2..8f5488345c42 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -603,7 +603,8 @@ void mark_oom_victim(struct task_struct *tsk) */ void exit_oom_victim(struct task_struct *tsk) { - clear_tsk_thread_flag(tsk, TIF_MEMDIE); + if (!test_and_clear_tsk_thread_flag(tsk, TIF_MEMDIE)) + return; if (!atomic_dec_return(&oom_victims)) wake_up_all(&oom_victims_wait); -- 2.7.0.rc3 -- Michal Hocko SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by kanga.kvack.org (Postfix) with ESMTP id BDEBB6B0009 for ; Thu, 28 Jan 2016 17:33:53 -0500 (EST) Received: by mail-wm0-f53.google.com with SMTP id 128so30156663wmz.1 for ; Thu, 28 Jan 2016 14:33:53 -0800 (PST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com. [74.125.82.67]) by mx.google.com with ESMTPS id o123si6914266wmd.53.2016.01.28.14.33.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jan 2016 14:33:52 -0800 (PST) Received: by mail-wm0-f67.google.com with SMTP id 128so4311005wmz.3 for ; Thu, 28 Jan 2016 14:33:52 -0800 (PST) Date: Thu, 28 Jan 2016 23:33:51 +0100 From: Michal Hocko Subject: Re: [PATCH 3/2] oom: clear TIF_MEMDIE after oom_reaper managed to unmap the address space Message-ID: <20160128223351.GA14803@dhcp22.suse.cz> References: <1452094975-551-1-git-send-email-mhocko@kernel.org> <1452516120-5535-1-git-send-email-mhocko@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1452516120-5535-1-git-send-email-mhocko@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton Cc: Johannes Weiner , Mel Gorman , Tetsuo Handa , David Rientjes , Linus Torvalds , Oleg Nesterov , Hugh Dickins , Andrea Argangeli , Rik van Riel , linux-mm@kvack.org, LKML I have missed one important point. exit_oom_victim has to do test_and_clear to make sure we do not race now with this patch. So we need to fold the following into the patch ---