From patchwork Sun Dec 7 10:45:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 5451241 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D91529F1D4 for ; Sun, 7 Dec 2014 10:45:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC1B920148 for ; Sun, 7 Dec 2014 10:45:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF57E2015A for ; Sun, 7 Dec 2014 10:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753167AbaLGKpn (ORCPT ); Sun, 7 Dec 2014 05:45:43 -0500 Received: from mail-wi0-f181.google.com ([209.85.212.181]:53578 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753161AbaLGKpn (ORCPT ); Sun, 7 Dec 2014 05:45:43 -0500 Received: by mail-wi0-f181.google.com with SMTP id r20so2352183wiv.14 for ; Sun, 07 Dec 2014 02:45:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=i5+kgODFMvpG+xZrf5EIYMZrBUif6n8l7ceynVdpVds=; b=c7yXBv3+ciL9QbWLnp+Sk25YOhBxJJuJYxhQqSANQjnyCcik0qkKYhWy+rMHnbggPR y8/VvojnthCEDKjUyd4ov0Tia+geV+Gkr0Oz9HZgo/5ZOgEepZ1KbAxtkpRcHNsxwFFW noVlk4JMxB/X8mmhpqbMG4NyVSiVZ0agpmQoZlZ5FZ2dB3TP9nisGE8+zLeK+K3m0vUV 5LXVUVfkJsRfyjME+XPNJoEqvubpU21OBNPWMj5+TzF4LSDigF7VRoKvrYihdaGud2hp Nd7B9IwKph6AHVEF7Qy+XACTnTEqx8cfx2wAnrm1jF0/5Ac4VyR9QCEBJoy48Qs9+rMN xSXA== X-Received: by 10.180.83.37 with SMTP id n5mr16707085wiy.83.1417949141556; Sun, 07 Dec 2014 02:45:41 -0800 (PST) Received: from localhost (ip-78-45-94-81.net.upcbroadband.cz. [78.45.94.81]) by mx.google.com with ESMTPSA id ej10sm5314138wib.1.2014.12.07.02.45.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Dec 2014 02:45:40 -0800 (PST) Date: Sun, 7 Dec 2014 11:45:39 +0100 From: Michal Hocko To: Tejun Heo Cc: linux-mm@kvack.org, Andrew Morton , "\\\"Rafael J. Wysocki\\\"" , David Rientjes , Johannes Weiner , Oleg Nesterov , Cong Wang , LKML , linux-pm@vger.kernel.org Subject: Re: [PATCH -v2 2/5] OOM: thaw the OOM victim if it is frozen Message-ID: <20141207104539.GK15892@dhcp22.suse.cz> References: <20141110163055.GC18373@dhcp22.suse.cz> <1417797707-31699-1-git-send-email-mhocko@suse.cz> <1417797707-31699-3-git-send-email-mhocko@suse.cz> <20141206130657.GC18711@htj.dyndns.org> <20141207102430.GF15892@dhcp22.suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20141207102430.GF15892@dhcp22.suse.cz> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun 07-12-14 11:24:30, Michal Hocko wrote: > On Sat 06-12-14 08:06:57, Tejun Heo wrote: > > Hello, > > > > On Fri, Dec 05, 2014 at 05:41:44PM +0100, Michal Hocko wrote: > > > oom_kill_process only sets TIF_MEMDIE flag and sends a signal to the > > > victim. This is basically noop when the task is frozen though because > > > the task sleeps in uninterruptible sleep. The victim is eventually > > > thawed later when oom_scan_process_thread meets the task again in a > > > later OOM invocation so the OOM killer doesn't live lock. But this is > > > less than optimal. Let's add the frozen check and thaw the task right > > > before we send SIGKILL to the victim. > > > > > > The check and thawing in oom_scan_process_thread has to stay because the > > > task might got access to memory reserves even without an explicit > > > SIGKILL from oom_kill_process (e.g. it already has fatal signal pending > > > or it is exiting already). > > > > How else would a task get TIF_MEMDIE? If there are other paths which > > set TIF_MEMDIE, the right thing to do is creating a function which > > thaws / wakes up the target task and use it there too. Please > > interlock these things properly from the get-go instead of scattering > > these things around. > > See __out_of_memory which sets TIF_MEMDIE on current when it is exiting > or has fatal signals pending. This task cannot be frozen obviously. On the other hand we are doing the same early in oom_kill_process which doesn't work on the current. I've moved the __thaw_task into mark_tsk_oom_victim so it catches all instances now. oom_scan_process_thread doesn't need to thaw anymore. --- From af8222df6c503fa1beab8279ff39a282fd90698b Mon Sep 17 00:00:00 2001 From: Michal Hocko Date: Wed, 12 Nov 2014 18:56:54 +0100 Subject: [PATCH] OOM: thaw the OOM victim if it is frozen oom_kill_process only sets TIF_MEMDIE flag and sends a signal to the victim. This is basically noop when the task is frozen though because the task sleeps in uninterruptible sleep. The victim is eventually thawed later when oom_scan_process_thread meets the task again in a later OOM invocation so the OOM killer doesn't live lock. But this is less than optimal. Let's add __thaw_task into mark_tsk_oom_victim after we set TIF_MEMDIE to the victim. We are not checking whether the task is frozen because that would be racy and __thaw_task does that already. oom_scan_process_thread doesn't need to care about freezer anymore as TIF_MEMDIE and freezer are excluded completely now. Signed-off-by: Michal Hocko --- mm/oom_kill.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 56eab9621c3a..19a08f3f00ba 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -266,8 +266,6 @@ enum oom_scan_t oom_scan_process_thread(struct task_struct *task, * Don't allow any other task to have access to the reserves. */ if (test_tsk_thread_flag(task, TIF_MEMDIE)) { - if (unlikely(frozen(task))) - __thaw_task(task); if (!force_kill) return OOM_SCAN_ABORT; } @@ -428,6 +426,7 @@ void note_oom_kill(void) void mark_tsk_oom_victim(struct task_struct *tsk) { set_tsk_thread_flag(tsk, TIF_MEMDIE); + __thaw_task(tsk); } /**