From patchwork Sat Aug 4 13:29:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10555767 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7369713AC for ; Sat, 4 Aug 2018 13:30:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62A1429C2E for ; Sat, 4 Aug 2018 13:30:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5643F29C34; Sat, 4 Aug 2018 13:30:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C511B29C2E for ; Sat, 4 Aug 2018 13:30:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A4C1D6B0006; Sat, 4 Aug 2018 09:30:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9D5726B0007; Sat, 4 Aug 2018 09:30:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73FA16B0008; Sat, 4 Aug 2018 09:30:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 2E1F66B0006 for ; Sat, 4 Aug 2018 09:30:06 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id q2-v6so2730237plh.12 for ; Sat, 04 Aug 2018 06:30:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id; bh=PzHMqTHGkeVfIpqMr3dznoknOPFw/ZDvViubXcE+XEs=; b=jFJlg2x2qo3TiReGjlLGQjHLJjJcDVJgwSFV0kKoyZWZQ2lc6vBFQF7o8i0EiiOE2s iqi2tY95w9vNGTVbcsiprYha7B8LfZliz9dRewk4tGLPgd2XtYdmShRSSVrdHYFebbuc dA4Y+42r2dw3Tu4AQ4IPwRhUEMUiSC1WWtJZloaiMDyjwWk15ejcROjk60PgsQphmgzC N2cjN9EtM2tUfW9cBGgOgGKNUQH6I/47EAjuthqE3Rc/zeiF8xOmoxrUJLwaFF4SyNUt 3+zA9Nxd0Z8EGeC5T1jbuBQ24uMhgSjmDMr/SO19lP+7cvuSRdyNtdeQLlD0h3XQH50E 20rA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp X-Gm-Message-State: AOUpUlEPHIPr82lGhSmHPqJIfzPmaRnayWKOoqSGcKAS1C3tfn1gHTc6 xc/ICNtvJMZngWRKfNXR+DO/C9cgKkaeWe3CgAFFEpg4ebF3nSbrZDQizkCgIBPLDa/+brarO2P sFf4EwPbo1zXCr7OH3cMX+vRUVL6jWCZJ8m2FhQj/7Wg8YQpoF2wGbmTLA1NbaBVZAA== X-Received: by 2002:a63:5866:: with SMTP id i38-v6mr7693899pgm.63.1533389405853; Sat, 04 Aug 2018 06:30:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcRy8ZauH9IfehRagk7wODWaqF6R/D7NI+/XjCtzAlEUgYfveDrhqpAMkBHmDUCCLotKvYn X-Received: by 2002:a63:5866:: with SMTP id i38-v6mr7693828pgm.63.1533389404452; Sat, 04 Aug 2018 06:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533389404; cv=none; d=google.com; s=arc-20160816; b=p+3zndiY5cUwm2CooXfx4vzUHUUS896ecpPw0VeLz8FPvxq5W1uMqmp9SyONQ6gf5C 52DkikovKWMvCEeXXTjJ3kx5jhu6zCXPs6w3aLlRaVIc9ciVILC7pqYe84fzAiQiJCRV 75gP/cZHwnWFjDaQMqWk+57KcNPyNh4E1eDkN+zaYFbAqxWjS0Su0GII6NsSHAPSeqOj 10d6v1FgYJgHSdsQ91mRF6wMFEBrs3Th0uXsT3jQDcDuLvCzZj8+1zvcvQKyt789Iak8 tKr7xCgk5qO1HG+mIm/ebG9zWVQA75vg1AtaNF4z7hGbjXsQaY0cin95Q8XdYzlvGuuF w4tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=PzHMqTHGkeVfIpqMr3dznoknOPFw/ZDvViubXcE+XEs=; b=bHI0WtzRVeFnHb7Dusq0f28Ff+t4GJQddCGo1NwWDTiCzFhePYds7dqtRpaNRjc29f rjVvz8afVeNnolqEQ0GSEbHnRsPfLIeH7iAMRGnZOJ0AqclKiFDoKiNFOCihbFUlmto0 UNloImuC3e1n4bGgxUVV9oNHJtws0jOqfzM0XawzjjvQoLQwz1R0JhFjItJQUrzB13YG 8tooMiBuPlHk7k9TZ6WJti3UeDD0nqe6aScm1E1++5lijl2AB7lR1mbJFs2LUPgG5G1v ni8fEkoLWcx1DfNEMftiApthEE22blmwzoSBMzrgmP7JFCrX1DYgBWi0ltq9Zn1NLTuW /2YA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [202.181.97.72]) by mx.google.com with ESMTPS id v203-v6si8155178pgb.333.2018.08.04.06.30.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Aug 2018 06:30:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) client-ip=202.181.97.72; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w74DTn8j005263; Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Sat, 04 Aug 2018 22:29:49 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w74DTiDI005246 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: linux-mm@kvack.org Cc: Tetsuo Handa , David Rientjes , Michal Hocko , Roman Gushchin Subject: [PATCH 1/4] mm, oom: Remove wake_oom_reaper(). Date: Sat, 4 Aug 2018 22:29:43 +0900 Message-Id: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Currently, wake_oom_reaper() is checking whether an OOM victim thread is already chained to the OOM victim list. But chaining one thread from each OOM victim process is sufficient. Since mark_oom_victim() sets signal->oom_mm for one thread from each OOM victim process, we can chain that OOM victim thread there. Since oom_lock is held during __oom_kill_process(), by replacing oom_reaper_lock with oom_lock, it becomes safe to use mark_oom_victim() even if MMF_OOM_SKIP is later set due to is_global_init() case. Signed-off-by: Tetsuo Handa Cc: Michal Hocko Cc: David Rientjes Cc: Roman Gushchin --- mm/oom_kill.c | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 0e10b86..dad0409 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -486,7 +486,6 @@ bool process_shares_mm(struct task_struct *p, struct mm_struct *mm) static struct task_struct *oom_reaper_th; static DECLARE_WAIT_QUEUE_HEAD(oom_reaper_wait); static struct task_struct *oom_reaper_list; -static DEFINE_SPINLOCK(oom_reaper_lock); bool __oom_reap_task_mm(struct mm_struct *mm) { @@ -607,7 +606,7 @@ static void oom_reap_task(struct task_struct *tsk) */ set_bit(MMF_OOM_SKIP, &mm->flags); - /* Drop a reference taken by wake_oom_reaper */ + /* Drop a reference taken by mark_oom_victim(). */ put_task_struct(tsk); } @@ -617,12 +616,12 @@ static int oom_reaper(void *unused) struct task_struct *tsk = NULL; wait_event_freezable(oom_reaper_wait, oom_reaper_list != NULL); - spin_lock(&oom_reaper_lock); + mutex_lock(&oom_lock); if (oom_reaper_list != NULL) { tsk = oom_reaper_list; oom_reaper_list = tsk->oom_reaper_list; } - spin_unlock(&oom_reaper_lock); + mutex_unlock(&oom_lock); if (tsk) oom_reap_task(tsk); @@ -631,32 +630,12 @@ static int oom_reaper(void *unused) return 0; } -static void wake_oom_reaper(struct task_struct *tsk) -{ - /* tsk is already queued? */ - if (tsk == oom_reaper_list || tsk->oom_reaper_list) - return; - - get_task_struct(tsk); - - spin_lock(&oom_reaper_lock); - tsk->oom_reaper_list = oom_reaper_list; - oom_reaper_list = tsk; - spin_unlock(&oom_reaper_lock); - trace_wake_reaper(tsk->pid); - wake_up(&oom_reaper_wait); -} - static int __init oom_init(void) { oom_reaper_th = kthread_run(oom_reaper, NULL, "oom_reaper"); return 0; } subsys_initcall(oom_init) -#else -static inline void wake_oom_reaper(struct task_struct *tsk) -{ -} #endif /* CONFIG_MMU */ /** @@ -682,6 +661,13 @@ static void mark_oom_victim(struct task_struct *tsk) if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) { mmgrab(tsk->signal->oom_mm); set_bit(MMF_OOM_VICTIM, &mm->flags); +#ifdef CONFIG_MMU + get_task_struct(tsk); + tsk->oom_reaper_list = oom_reaper_list; + oom_reaper_list = tsk; + trace_wake_reaper(tsk->pid); + wake_up(&oom_reaper_wait); +#endif } /* @@ -833,7 +819,6 @@ static void __oom_kill_process(struct task_struct *victim) { struct task_struct *p; struct mm_struct *mm; - bool can_oom_reap = true; p = find_lock_task_mm(victim); if (!p) { @@ -883,7 +868,6 @@ static void __oom_kill_process(struct task_struct *victim) if (same_thread_group(p, victim)) continue; if (is_global_init(p)) { - can_oom_reap = false; set_bit(MMF_OOM_SKIP, &mm->flags); pr_info("oom killer %d (%s) has mm pinned by %d (%s)\n", task_pid_nr(victim), victim->comm, @@ -900,9 +884,6 @@ static void __oom_kill_process(struct task_struct *victim) } rcu_read_unlock(); - if (can_oom_reap) - wake_oom_reaper(victim); - mmdrop(mm); put_task_struct(victim); } @@ -941,7 +922,6 @@ static void oom_kill_process(struct oom_control *oc, const char *message) task_lock(p); if (task_will_free_mem(p)) { mark_oom_victim(p); - wake_oom_reaper(p); task_unlock(p); put_task_struct(p); return; @@ -1071,7 +1051,6 @@ bool out_of_memory(struct oom_control *oc) */ if (task_will_free_mem(current)) { mark_oom_victim(current); - wake_oom_reaper(current); return true; } From patchwork Sat Aug 4 13:29:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10555771 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CCE0157D for ; Sat, 4 Aug 2018 13:30:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B6DC29C2E for ; Sat, 4 Aug 2018 13:30:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FC0829C34; Sat, 4 Aug 2018 13:30:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CFE629C2E for ; Sat, 4 Aug 2018 13:30:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9B716B000D; Sat, 4 Aug 2018 09:30:15 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A21816B000E; Sat, 4 Aug 2018 09:30:15 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C2C86B0010; Sat, 4 Aug 2018 09:30:15 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 44D4A6B000D for ; Sat, 4 Aug 2018 09:30:15 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id 132-v6so3743171pga.18 for ; Sat, 04 Aug 2018 06:30:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=6Q6MJCkn0qaKi0kQwwfDppqn1K3XrIvUs7xwrrEeua4=; b=QXWgEH+FqCB9EVozY52rfWCEOdopSHzUfNDKXMRMrzgaP/qko9ZNWYmabqvlc+BHHp h0XKyKJ/sZ1iIuJ5UltPODWHLs6vIhvYmecbUIHD4rECYLDUCh9Zt9nvfSXuvJZsM9vT bt3A9QEgoVp5MpjzsqEePtqttlGK5AU7f75I3FccJg3X8gmsS5+lUHaa3PHH4TuxZLEf +44F7fbQEmc8aIYT6uyH9mp+w9QXcWOKVG1ribA/itb2FkLpojHUQvTV4hFYsAwS3m5d dFfwF5Br9kkIG5PNZc10HBE3HR2qCmV+j5KZxjstjeegxtYYK1/VSdk8WHLlnSEaZV44 oODg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp X-Gm-Message-State: AOUpUlHURapJ3QVv/0AKufngbGw6jgTKbKQQY+hnx+qcQgA8AxTNlDcm GCHr8lWjSqqW1RJnyezjJqKKTtOPiHkyAQyjHx1PF7q2bfA97V5VS4TUJBa8MJdg4DckLWPxXLG SyOg8u8MHdcUxaDH32AWgKpGhfNeFEcPsh8oCANHI372nIeKHA4fXSRVVKeCjakj6qg== X-Received: by 2002:a17:902:6907:: with SMTP id j7-v6mr7319077plk.323.1533389414927; Sat, 04 Aug 2018 06:30:14 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfmRUvY3xixJhly52R2Me1q2gC+lzkqxC1+MBsYtyWOkVhQUEQR8XNKglbsKDgyqGvpk2K8 X-Received: by 2002:a17:902:6907:: with SMTP id j7-v6mr7318952plk.323.1533389412231; Sat, 04 Aug 2018 06:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533389412; cv=none; d=google.com; s=arc-20160816; b=iEA5ZF4fJYhO1VgaJ4dR2sN2o7vyNB9hH6wFNOfWXLi8fsqqnG40oFLGf2gwbfSvUi r0RvatpzNV1JHgboRCUhbRlImxO/seaOwjS0MmW3PXl9gN1GA4oXKHDBP7VtyKioCXPb Sk7h3BKBm8NhaLTR9boicKf8iXpFLwaN4q1a1551vU2wBakjU7EtIT3jlLxI6NJL0qhB SJQJh0JycgjcB0UtZZAf9+CNu1Hq/uY2yGjk/+MgF0n8bbSZYkfuHAvgS5ihYzOLSdFj 7cUi78XOl6dUNEw89d0Njpx/ofUZZRNmLLGPv0w8cMEcf9WiqlJXRHjk9mrwQ+xXE+U7 VDNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=6Q6MJCkn0qaKi0kQwwfDppqn1K3XrIvUs7xwrrEeua4=; b=n7d0xhL+GgQ0BhmMmniAjdYp6PpoWa8yPjIhAdLB2F3cxJ1V2cibFZeh4MXe0qu+6D NViCq0GaaLsZqS06L1xg+pWh4dBQHpnlr95Ny41BKuKrYEst7DbLp9JTL7kNgq2eSQlV /A2bGqptgjOyEW7laylpPjIB2UBVRz5tlwXjeWYIi5jj3lOWpIqgtyW/AG0Jwma9so3c ZlNuFQ3+ARy365zFILVPvKpVIAM3AvN0zgbnkNpUMQj1fknqMRwL4UsQKrxuzPbdEFCX KCfta5HnWzojdPlAytAfkAC/G36W1lr9H9TaS5PFYh8ivIDZgsJUI84K2mFagoNWsqQW yCnQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [202.181.97.72]) by mx.google.com with ESMTPS id 2-v6si7850000pgq.479.2018.08.04.06.30.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Aug 2018 06:30:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) client-ip=202.181.97.72; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w74DTn7p005268; Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Sat, 04 Aug 2018 22:29:49 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w74DTiDJ005246 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: linux-mm@kvack.org Cc: Tetsuo Handa , David Rientjes , Michal Hocko , Roman Gushchin Subject: [PATCH 2/4] mm, oom: Check pending victims earlier in out_of_memory(). Date: Sat, 4 Aug 2018 22:29:44 +0900 Message-Id: <1533389386-3501-2-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Regarding CONFIG_MMU=y case, we have a list of inflight OOM victim threads which are chained to oom_reaper_list. Therefore, by doing the same thing for CONFIG_MMU=n case, we can check whether there are inflight OOM victims before starting process/memcg list traversal. Since it is likely that only few threads are chained to oom_reaper_list, checking all victims' OOM domain will not matter. Thus, check whether there are inflight OOM victims before starting process/memcg list traversal. To do so, we need to chain OOM victims until MMF_OOM_SKIP is set. Thus, this patch changes the OOM reaper to wait for an request from the OOM killer using oom_reap_target variable. This change allows the OOM reaper to preferentially reclaim from mm which the OOM killer is waiting for the OOM reaper to reclaim. Signed-off-by: Tetsuo Handa Cc: Michal Hocko Cc: David Rientjes Cc: Roman Gushchin --- include/linux/oom.h | 1 + include/linux/sched.h | 4 +-- kernel/fork.c | 2 ++ mm/oom_kill.c | 97 +++++++++++++++++++++++++++++---------------------- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/include/linux/oom.h b/include/linux/oom.h index 69864a5..4a147871 100644 --- a/include/linux/oom.h +++ b/include/linux/oom.h @@ -104,6 +104,7 @@ extern unsigned long oom_badness(struct task_struct *p, extern bool out_of_memory(struct oom_control *oc); extern void exit_oom_victim(void); +extern void exit_oom_mm(struct mm_struct *mm); extern int register_oom_notifier(struct notifier_block *nb); extern int unregister_oom_notifier(struct notifier_block *nb); diff --git a/include/linux/sched.h b/include/linux/sched.h index 9e686dc..589fe78 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1173,9 +1173,7 @@ struct task_struct { unsigned long task_state_change; #endif int pagefault_disabled; -#ifdef CONFIG_MMU - struct task_struct *oom_reaper_list; -#endif + struct list_head oom_victim_list; #ifdef CONFIG_VMAP_STACK struct vm_struct *stack_vm_area; #endif diff --git a/kernel/fork.c b/kernel/fork.c index 276fdc6..ba1260d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1010,6 +1010,8 @@ static inline void __mmput(struct mm_struct *mm) } if (mm->binfmt) module_put(mm->binfmt->module); + if (unlikely(mm_is_oom_victim(mm))) + exit_oom_mm(mm); mmdrop(mm); } diff --git a/mm/oom_kill.c b/mm/oom_kill.c index dad0409..a743a8e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -321,18 +321,6 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) goto next; /* - * This task already has access to memory reserves and is being killed. - * Don't allow any other task to have access to the reserves unless - * the task has MMF_OOM_SKIP because chances that it would release - * any memory is quite low. - */ - if (!is_sysrq_oom(oc) && tsk_is_oom_victim(task)) { - if (test_bit(MMF_OOM_SKIP, &task->signal->oom_mm->flags)) - goto next; - goto abort; - } - - /* * If task is allocating a lot of memory and has been marked to be * killed first if it triggers an oom, then select it. */ @@ -356,11 +344,6 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) oc->chosen_points = points; next: return 0; -abort: - if (oc->chosen) - put_task_struct(oc->chosen); - oc->chosen = (void *)-1UL; - return 1; } /* @@ -478,6 +461,8 @@ bool process_shares_mm(struct task_struct *p, struct mm_struct *mm) return false; } +static LIST_HEAD(oom_victim_list); + #ifdef CONFIG_MMU /* * OOM Reaper kernel thread which tries to reap the memory used by the OOM @@ -485,7 +470,7 @@ bool process_shares_mm(struct task_struct *p, struct mm_struct *mm) */ static struct task_struct *oom_reaper_th; static DECLARE_WAIT_QUEUE_HEAD(oom_reaper_wait); -static struct task_struct *oom_reaper_list; +static struct task_struct *oom_reap_target; bool __oom_reap_task_mm(struct mm_struct *mm) { @@ -598,33 +583,21 @@ static void oom_reap_task(struct task_struct *tsk) debug_show_all_locks(); done: - tsk->oom_reaper_list = NULL; - /* * Hide this mm from OOM killer because it has been either reaped or * somebody can't call up_write(mmap_sem). */ set_bit(MMF_OOM_SKIP, &mm->flags); - - /* Drop a reference taken by mark_oom_victim(). */ - put_task_struct(tsk); } static int oom_reaper(void *unused) { while (true) { - struct task_struct *tsk = NULL; - - wait_event_freezable(oom_reaper_wait, oom_reaper_list != NULL); - mutex_lock(&oom_lock); - if (oom_reaper_list != NULL) { - tsk = oom_reaper_list; - oom_reaper_list = tsk->oom_reaper_list; - } - mutex_unlock(&oom_lock); - - if (tsk) - oom_reap_task(tsk); + wait_event_freezable(oom_reaper_wait, oom_reap_target != NULL); + oom_reap_task(oom_reap_target); + /* Drop a reference taken by oom_has_pending_victims(). */ + put_task_struct(oom_reap_target); + oom_reap_target = NULL; } return 0; @@ -661,13 +634,8 @@ static void mark_oom_victim(struct task_struct *tsk) if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) { mmgrab(tsk->signal->oom_mm); set_bit(MMF_OOM_VICTIM, &mm->flags); -#ifdef CONFIG_MMU get_task_struct(tsk); - tsk->oom_reaper_list = oom_reaper_list; - oom_reaper_list = tsk; - trace_wake_reaper(tsk->pid); - wake_up(&oom_reaper_wait); -#endif + list_add(&tsk->oom_victim_list, &oom_victim_list); } /* @@ -681,6 +649,21 @@ static void mark_oom_victim(struct task_struct *tsk) trace_mark_victim(tsk->pid); } +void exit_oom_mm(struct mm_struct *mm) +{ + struct task_struct *p, *tmp; + + mutex_lock(&oom_lock); + list_for_each_entry_safe(p, tmp, &oom_victim_list, oom_victim_list) { + if (mm != p->signal->oom_mm) + continue; + list_del(&p->oom_victim_list); + /* Drop a reference taken by mark_oom_victim(). */ + put_task_struct(p); + } + mutex_unlock(&oom_lock); +} + /** * exit_oom_victim - note the exit of an OOM victim */ @@ -1020,6 +1003,35 @@ int unregister_oom_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(unregister_oom_notifier); +static bool oom_has_pending_victims(struct oom_control *oc) +{ + struct task_struct *p; + + if (is_sysrq_oom(oc)) + return false; + /* + * Since oom_reap_task()/exit_mmap() will set MMF_OOM_SKIP, let's + * wait for pending victims until MMF_OOM_SKIP is set or __mmput() + * completes. + */ + list_for_each_entry(p, &oom_victim_list, oom_victim_list) { + if (oom_unkillable_task(p, oc->memcg, oc->nodemask)) + continue; + if (!test_bit(MMF_OOM_SKIP, &p->signal->oom_mm->flags)) { +#ifdef CONFIG_MMU + if (!oom_reap_target) { + get_task_struct(p); + oom_reap_target = p; + trace_wake_reaper(p->pid); + wake_up(&oom_reaper_wait); + } +#endif + return true; + } + } + return false; +} + /** * out_of_memory - kill the "best" process when we run out of memory * @oc: pointer to struct oom_control @@ -1072,6 +1084,9 @@ bool out_of_memory(struct oom_control *oc) oc->nodemask = NULL; check_panic_on_oom(oc, constraint); + if (oom_has_pending_victims(oc)) + return true; + if (!is_memcg_oom(oc) && sysctl_oom_kill_allocating_task && current->mm && !oom_unkillable_task(current, NULL, oc->nodemask) && current->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) { From patchwork Sat Aug 4 13:29:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10555769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6443613AC for ; Sat, 4 Aug 2018 13:30:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5305429C2E for ; Sat, 4 Aug 2018 13:30:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4717529C34; Sat, 4 Aug 2018 13:30:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A300A29C2E for ; Sat, 4 Aug 2018 13:30:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7678F6B0008; Sat, 4 Aug 2018 09:30:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 69FF46B000A; Sat, 4 Aug 2018 09:30:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51FFB6B000C; Sat, 4 Aug 2018 09:30:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 004196B0008 for ; Sat, 4 Aug 2018 09:30:08 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id 90-v6so4883524pla.18 for ; Sat, 04 Aug 2018 06:30:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=IdtoHuo8UB7zKAK4hZYgZeI7adHAHLpPxjSBsB8Iy2s=; b=lP+5ATUV43I86TsBzRz/xUupcrJbL/r/VqJ4xfHHEi74I8aeA6jSPth0QwfIv+oSVN sCeNXjgKwNZA34neWkyFVOEElC/fu6lzZ2Y8PW1vOn9b/dzFBdWVJT/9WgorMrMBJPjy Pg35DAFLDXNzWs4AQAPxg+LgBQd+hcpVX9DGEJoCS67SMrQB5OsOssNk46ax59wwDIj0 XcHTNlpicw8fbPCtAiLTAGrgGBDHkA3xNV6ph1GVRnXYxU8E5NJZu07QMhmXagj7PhcK suTf+G6GOMZuIeM9vkerLGgRS0cNIIOEVdu+o68wHtKa8KYKjclUD2qGN5CyPZUxpJa7 Q+cw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp X-Gm-Message-State: AOUpUlGmONnbuGNvPy6VRqEde3vkau2ogg8RsIX/qfkoRl2Jb0y0ckiK EUUX8I8wEaVtKns0hCkNsWhVbnTyxPsdYaICsgiGfkFkHG6mup337qYQGPJ+fAWAmtXaldmARWY oG3fFZv7BjVkiZU1TnJ1s1Xk+fgZ3egJajRKj/ZZII0Fm5K1jkYGoNdS7nX+8aWpq5w== X-Received: by 2002:a63:5542:: with SMTP id f2-v6mr7811343pgm.37.1533389407643; Sat, 04 Aug 2018 06:30:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc6TiIkNMpPJ7zsUbZn+BLgv/AvKac1tGKiMGGaoWeBg76SSbOUV+WDV5UovVjUh8Irz8Kw X-Received: by 2002:a63:5542:: with SMTP id f2-v6mr7811265pgm.37.1533389406398; Sat, 04 Aug 2018 06:30:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533389406; cv=none; d=google.com; s=arc-20160816; b=WyiBy3ZEySwdtx9Jmo66pBRkf+HfqIMHAo9okZ3RENMd1BAj2PFMGgtzik5nD6QdI0 qtN7jWHGhPNX2c5UMYhO9jyyxX2QOIcF+La45pY3eMywC40owpf/QK4BgqohACVN2ylc 2R/SfX2zGgq6K+JhqsTAFQIcKQ6CdHIWCmIw9q2oy3dCYEcGXnqKULBR/6aJxwnTWSVe bbReqenVLm/9DJxtQNPR0l5C3DcCpoF0caYqUz88MjS+DqYIy0dFkvxUGHP8M5W2zNHZ E27X9wt+IzcNlmHBHiL14d+k5DgQjtZOvpw+CXW0m43T9dH6yOKJjqgcPz06mdoK0uCK q3JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=IdtoHuo8UB7zKAK4hZYgZeI7adHAHLpPxjSBsB8Iy2s=; b=jrKXHQm+Ioi0BUja1/pkd9dpEwc2dtQjolgkRx8aSrZ10CyA8maTE8vl+HiiknATWl qGeuCi0OVO1ZE4K6u9v0LZ1d6CaMBm3ErPrbCBTObYUwWUhy6jeNNfAK3aIYy1j/xdRx ggMHDD1ziJq1qMzuxmFdk02aqvFgfnGqcNeEYOAik92zSjQ4novJkRT25utPcN/h5hCO b2tSJesdRksj4Z6ttZjPRspi8XIWSobtTiOdwkQYuV4c6s8K889+gB0jWpxwDSbaeetj ywvNe/+oNt73c/fv+V3BfzQkEGOKYyViSDJjnvDcdo7WBBdfyxopS4Yqfr49w5goLqQy UiMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [202.181.97.72]) by mx.google.com with ESMTPS id x4-v6si7158650pga.320.2018.08.04.06.30.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Aug 2018 06:30:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) client-ip=202.181.97.72; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w74DTnml005271; Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Sat, 04 Aug 2018 22:29:49 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w74DTiDK005246 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: linux-mm@kvack.org Cc: Tetsuo Handa , David Rientjes , Michal Hocko , Roman Gushchin Subject: [PATCH 3/4] mm, oom: Remove unused "abort" path. Date: Sat, 4 Aug 2018 22:29:45 +0900 Message-Id: <1533389386-3501-3-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Since oom_evaluate_task() no longer aborts, we can remove no longer used "abort" path in the callers. Signed-off-by: Tetsuo Handa Cc: Michal Hocko Cc: David Rientjes Cc: Roman Gushchin --- include/linux/memcontrol.h | 9 ++++----- mm/memcontrol.c | 18 +++++------------- mm/oom_kill.c | 34 ++++++++++++++++------------------ 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 652f602..396b01d 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -417,8 +417,8 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *, struct mem_cgroup *, struct mem_cgroup_reclaim_cookie *); void mem_cgroup_iter_break(struct mem_cgroup *, struct mem_cgroup *); -int mem_cgroup_scan_tasks(struct mem_cgroup *, - int (*)(struct task_struct *, void *), void *); +void mem_cgroup_scan_tasks(struct mem_cgroup *memcg, + void (*fn)(struct task_struct *, void *), void *arg); static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) { @@ -917,10 +917,9 @@ static inline void mem_cgroup_iter_break(struct mem_cgroup *root, { } -static inline int mem_cgroup_scan_tasks(struct mem_cgroup *memcg, - int (*fn)(struct task_struct *, void *), void *arg) +static inline void mem_cgroup_scan_tasks(struct mem_cgroup *memcg, + void (*fn)(struct task_struct *, void *), void *arg) { - return 0; } static inline unsigned short mem_cgroup_id(struct mem_cgroup *memcg) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 4e3c131..f743778 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1058,17 +1058,14 @@ static void invalidate_reclaim_iterators(struct mem_cgroup *dead_memcg) * @arg: argument passed to @fn * * This function iterates over tasks attached to @memcg or to any of its - * descendants and calls @fn for each task. If @fn returns a non-zero - * value, the function breaks the iteration loop and returns the value. - * Otherwise, it will iterate over all tasks and return 0. + * descendants and calls @fn for each task. * * This function must not be called for the root memory cgroup. */ -int mem_cgroup_scan_tasks(struct mem_cgroup *memcg, - int (*fn)(struct task_struct *, void *), void *arg) +void mem_cgroup_scan_tasks(struct mem_cgroup *memcg, + void (*fn)(struct task_struct *, void *), void *arg) { struct mem_cgroup *iter; - int ret = 0; BUG_ON(memcg == root_mem_cgroup); @@ -1077,15 +1074,10 @@ int mem_cgroup_scan_tasks(struct mem_cgroup *memcg, struct task_struct *task; css_task_iter_start(&iter->css, 0, &it); - while (!ret && (task = css_task_iter_next(&it))) - ret = fn(task, arg); + while ((task = css_task_iter_next(&it))) + fn(task, arg); css_task_iter_end(&it); - if (ret) { - mem_cgroup_iter_break(memcg, iter); - break; - } } - return ret; } /** diff --git a/mm/oom_kill.c b/mm/oom_kill.c index a743a8e..783f04d 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -312,13 +312,13 @@ static enum oom_constraint constrained_alloc(struct oom_control *oc) return CONSTRAINT_NONE; } -static int oom_evaluate_task(struct task_struct *task, void *arg) +static void oom_evaluate_task(struct task_struct *task, void *arg) { struct oom_control *oc = arg; unsigned long points; if (oom_unkillable_task(task, NULL, oc->nodemask)) - goto next; + return; /* * If task is allocating a lot of memory and has been marked to be @@ -331,24 +331,22 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) points = oom_badness(task, NULL, oc->nodemask, oc->totalpages); if (!points || points < oc->chosen_points) - goto next; + return; /* Prefer thread group leaders for display purposes */ if (points == oc->chosen_points && thread_group_leader(oc->chosen)) - goto next; + return; select: if (oc->chosen) put_task_struct(oc->chosen); get_task_struct(task); oc->chosen = task; oc->chosen_points = points; -next: - return 0; } /* * Simple selection loop. We choose the process with the highest number of - * 'points'. In case scan was aborted, oc->chosen is set to -1. + * 'points'. */ static void select_bad_process(struct oom_control *oc) { @@ -359,8 +357,7 @@ static void select_bad_process(struct oom_control *oc) rcu_read_lock(); for_each_process(p) - if (oom_evaluate_task(p, oc)) - break; + oom_evaluate_task(p, oc); rcu_read_unlock(); } @@ -876,13 +873,12 @@ static void __oom_kill_process(struct task_struct *victim) * Kill provided task unless it's secured by setting * oom_score_adj to OOM_SCORE_ADJ_MIN. */ -static int oom_kill_memcg_member(struct task_struct *task, void *unused) +static void oom_kill_memcg_member(struct task_struct *task, void *unused) { if (task->signal->oom_score_adj != OOM_SCORE_ADJ_MIN) { get_task_struct(task); __oom_kill_process(task); } - return 0; } static void oom_kill_process(struct oom_control *oc, const char *message) @@ -1098,14 +1094,16 @@ bool out_of_memory(struct oom_control *oc) select_bad_process(oc); /* Found nothing?!?! Either we hang forever, or we panic. */ - if (!oc->chosen && !is_sysrq_oom(oc) && !is_memcg_oom(oc)) { - dump_header(oc, NULL); - panic("Out of memory and no killable processes...\n"); + if (!oc->chosen) { + if (!is_sysrq_oom(oc) && !is_memcg_oom(oc)) { + dump_header(oc, NULL); + panic("Out of memory and no killable processes...\n"); + } + return false; } - if (oc->chosen && oc->chosen != (void *)-1UL) - oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" : - "Memory cgroup out of memory"); - return !!oc->chosen; + oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" : + "Memory cgroup out of memory"); + return true; } /* From patchwork Sat Aug 4 13:29:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10555765 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03D2013AC for ; Sat, 4 Aug 2018 13:30:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6F7629C2E for ; Sat, 4 Aug 2018 13:30:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA59D29C34; Sat, 4 Aug 2018 13:30:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CCE429C2E for ; Sat, 4 Aug 2018 13:30:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7654D6B0005; Sat, 4 Aug 2018 09:30:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6EC6E6B0006; Sat, 4 Aug 2018 09:30:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 590016B0007; Sat, 4 Aug 2018 09:30:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f69.google.com (mail-pl0-f69.google.com [209.85.160.69]) by kanga.kvack.org (Postfix) with ESMTP id 1377F6B0005 for ; Sat, 4 Aug 2018 09:30:05 -0400 (EDT) Received: by mail-pl0-f69.google.com with SMTP id o12-v6so4916761pls.20 for ; Sat, 04 Aug 2018 06:30:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ivjvAeLWUzWkZMvjgj344DysM7ydd6Z4SniFwwhudRM=; b=XyozsqQl7qYz0sMNUjGIiPX04L6J57ov7RiuaVv5gdR5Gwv0pfx0y+zSjH+zrLyLt2 eUv6kBDXLgZ0iqzRTogkRMf8t0MC/cYKyiWBj1mcPMkHCrrRmNkfsrm1J9EuoagE43+s 5VZYcIAj350GJP6CwCVnr96bCe6P/ZtNNsRHQiUO9Wwmx2+qlc3H5demeoo3taKeS+li vs4ywrsFxabzsA+RKRZZU678yil9D3wN59hU9RnDSiwo9rIrwPuCwkwNSsygs6Qmgy4G H7z6RPP+lCQFqgpdVxgvNNeMx0vx/XppRvRP5k0MiVDh79Ls6RbmmhaOII19qsjl/dIc Atew== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp X-Gm-Message-State: AOUpUlG6zrDjKdmNssTqP2P4nYIquln3OEdgtPgjlyXCktqmWE1ASD/p 7sa73AgdOFHPmoL9c75r25wL5NXFzVGIOKQcRP3JvWEI4IwqVTpSBINV6hjIZ9uAeOVZFul3wOQ GDMwSrHe4Xc1uVeX8tMBi1c3ZyN71S/HSvOXwrbe8eTr3ojhoEx3iUBluWWDdBC9ARA== X-Received: by 2002:a63:dc17:: with SMTP id s23-v6mr7886161pgg.40.1533389404734; Sat, 04 Aug 2018 06:30:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeECNQFnah8nbzLFNyXD2EcFJRYXwhi0ywlJsbUi5ifX8Tnz9qd6lJsiw08nO95Fsmqb3nZ X-Received: by 2002:a63:dc17:: with SMTP id s23-v6mr7886068pgg.40.1533389403267; Sat, 04 Aug 2018 06:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533389403; cv=none; d=google.com; s=arc-20160816; b=yOYcXbLbw7tWHMc/0R3/r9ZfyDPBlYB5IgQRLwMjWDZiXQ58GuXI2M4T8knxY+2ehg flS0z2L1RBA29ZQHmvJWnsrVRmVrX6YF2f7+cffTw6/IAdiQsTsrgJF7jAZduCDt+Feh lWIGXJeDZ6smjfjhw5f6PYf3wkMDeRLigXYZf1O2Yhi/3i0PWMjIhkXwoWOBvD3PX0Dc g3izPdwKe/LjlcJMVijXeeWrN2+hh6gXvDX7kRIYIWxaLTwyVG/zr/fEYUBYjOdbp2v8 kk0PAUqQZkFFTVuiMTU1midtPlSlrRWmY37AMeEMep4qxEdWDF0JhuCUmY5uyI0/wXC8 MUNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ivjvAeLWUzWkZMvjgj344DysM7ydd6Z4SniFwwhudRM=; b=sj83SRdO8OgJdp3lwrIlu5Iq86yg7mQaGcHZ1gQZcYljDAfsYg2I3gsueKExW1lRKP kaLOe7TfTO3Dp6D8m4QxJEOLYhhNtHPicywk4laFJKS1u/8vFWbYhO3O45MfLETV1VEM 4rU5omhyYSXdXxtn1iPfmgjKN2jsEPfsQ8P1GZLAWl2Fpd3lN9LL3Mrb+nG0Xmfiri6n J4zjukZT9Z9zbDH3PO5XUTi2h69wRoPpghO7bppXXPl8G0hyAzZ2QOXeH//Bq7mmR29d m5vfg3QzljYrZTyYiGKubGcCP/YCLkatBzt3efC1i+Mx4e5do3Y1IAc2t4FbGCD4hb0P isOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from www262.sakura.ne.jp (www262.sakura.ne.jp. [202.181.97.72]) by mx.google.com with ESMTPS id p21-v6si5648555plq.94.2018.08.04.06.30.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Aug 2018 06:30:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) client-ip=202.181.97.72; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of penguin-kernel@i-love.sakura.ne.jp designates 202.181.97.72 as permitted sender) smtp.mailfrom=penguin-kernel@i-love.sakura.ne.jp Received: from fsav105.sakura.ne.jp (fsav105.sakura.ne.jp [27.133.134.232]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w74DTnog005280; Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav105.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp); Sat, 04 Aug 2018 22:29:49 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav105.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126074194044.bbtec.net [126.74.194.44]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w74DTiDL005246 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 4 Aug 2018 22:29:49 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: linux-mm@kvack.org Cc: Tetsuo Handa , David Rientjes , Michal Hocko , Roman Gushchin Subject: [PATCH 4/4] mm, oom: Fix unnecessary killing of additional processes. Date: Sat, 4 Aug 2018 22:29:46 +0900 Message-Id: <1533389386-3501-4-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1533389386-3501-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP David Rientjes is complaining about current behavior that the OOM killer selects next OOM victim as soon as MMF_OOM_SKIP is set even if __oom_reap_task_mm() returned without any progress. To address this problem, this patch adds a timeout with whether the OOM score of an OOM victim's memory is decreasing over time as a feedback, after MMF_OOM_SKIP is set by the OOM reaper or exit_mmap(). Signed-off-by: Tetsuo Handa Cc: Michal Hocko Cc: David Rientjes Cc: Roman Gushchin --- include/linux/sched.h | 3 ++ mm/oom_kill.c | 81 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 589fe78..70c7dfd 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1174,6 +1174,9 @@ struct task_struct { #endif int pagefault_disabled; struct list_head oom_victim_list; + unsigned long last_oom_compared; + unsigned long last_oom_score; + unsigned char oom_reap_stall_count; #ifdef CONFIG_VMAP_STACK struct vm_struct *stack_vm_area; #endif diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 783f04d..7cad886 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -49,6 +49,12 @@ #define CREATE_TRACE_POINTS #include +static inline unsigned long oom_victim_mm_score(struct mm_struct *mm) +{ + return get_mm_rss(mm) + get_mm_counter(mm, MM_SWAPENTS) + + mm_pgtables_bytes(mm) / PAGE_SIZE; +} + int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks = 1; @@ -230,8 +236,7 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, * The baseline for the badness score is the proportion of RAM that each * task's rss, pagetable and swap space use. */ - points = get_mm_rss(p->mm) + get_mm_counter(p->mm, MM_SWAPENTS) + - mm_pgtables_bytes(p->mm) / PAGE_SIZE; + points = oom_victim_mm_score(p->mm); task_unlock(p); /* Normalize to oom_score_adj units */ @@ -571,15 +576,6 @@ static void oom_reap_task(struct task_struct *tsk) while (attempts++ < MAX_OOM_REAP_RETRIES && !oom_reap_task_mm(tsk, mm)) schedule_timeout_idle(HZ/10); - if (attempts <= MAX_OOM_REAP_RETRIES || - test_bit(MMF_OOM_SKIP, &mm->flags)) - goto done; - - pr_info("oom_reaper: unable to reap pid:%d (%s)\n", - task_pid_nr(tsk), tsk->comm); - debug_show_all_locks(); - -done: /* * Hide this mm from OOM killer because it has been either reaped or * somebody can't call up_write(mmap_sem). @@ -631,6 +627,9 @@ static void mark_oom_victim(struct task_struct *tsk) if (!cmpxchg(&tsk->signal->oom_mm, NULL, mm)) { mmgrab(tsk->signal->oom_mm); set_bit(MMF_OOM_VICTIM, &mm->flags); + tsk->last_oom_compared = jiffies; + tsk->last_oom_score = oom_victim_mm_score(mm); + tsk->oom_reap_stall_count = 0; get_task_struct(tsk); list_add(&tsk->oom_victim_list, &oom_victim_list); } @@ -867,7 +866,6 @@ static void __oom_kill_process(struct task_struct *victim) mmdrop(mm); put_task_struct(victim); } -#undef K /* * Kill provided task unless it's secured by setting @@ -999,33 +997,74 @@ int unregister_oom_notifier(struct notifier_block *nb) } EXPORT_SYMBOL_GPL(unregister_oom_notifier); +static bool victim_mm_stalling(struct task_struct *p, struct mm_struct *mm) +{ + unsigned long score; + + if (time_before(jiffies, p->last_oom_compared + HZ / 10)) + return false; + score = oom_victim_mm_score(mm); + if (score < p->last_oom_score) + p->oom_reap_stall_count = 0; + else + p->oom_reap_stall_count++; + p->last_oom_score = oom_victim_mm_score(mm); + p->last_oom_compared = jiffies; + if (p->oom_reap_stall_count < 30) + return false; + pr_info("Gave up waiting for process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB\n", + task_pid_nr(p), p->comm, K(mm->total_vm), + K(get_mm_counter(mm, MM_ANONPAGES)), + K(get_mm_counter(mm, MM_FILEPAGES)), + K(get_mm_counter(mm, MM_SHMEMPAGES))); + return true; +} + static bool oom_has_pending_victims(struct oom_control *oc) { - struct task_struct *p; + struct task_struct *p, *tmp; + bool ret = false; + bool gaveup = false; if (is_sysrq_oom(oc)) return false; /* - * Since oom_reap_task()/exit_mmap() will set MMF_OOM_SKIP, let's - * wait for pending victims until MMF_OOM_SKIP is set or __mmput() - * completes. + * Wait for pending victims until __mmput() completes or stalled + * too long. */ - list_for_each_entry(p, &oom_victim_list, oom_victim_list) { + list_for_each_entry_safe(p, tmp, &oom_victim_list, oom_victim_list) { + struct mm_struct *mm = p->signal->oom_mm; + if (oom_unkillable_task(p, oc->memcg, oc->nodemask)) continue; - if (!test_bit(MMF_OOM_SKIP, &p->signal->oom_mm->flags)) { + ret = true; #ifdef CONFIG_MMU + /* + * Since the OOM reaper exists, we can safely wait until + * MMF_OOM_SKIP is set. + */ + if (!test_bit(MMF_OOM_SKIP, &mm->flags)) { if (!oom_reap_target) { get_task_struct(p); oom_reap_target = p; trace_wake_reaper(p->pid); wake_up(&oom_reaper_wait); } -#endif - return true; + continue; } +#endif + /* We can wait as long as OOM score is decreasing over time. */ + if (!victim_mm_stalling(p, mm)) + continue; + gaveup = true; + list_del(&p->oom_victim_list); + /* Drop a reference taken by mark_oom_victim(). */ + put_task_struct(p); } - return false; + if (gaveup) + debug_show_all_locks(); + + return ret; } /**