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; }