From patchwork Fri Aug 3 13:19:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10555107 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 2E1E7157D for ; Fri, 3 Aug 2018 13:19:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19F3E2C118 for ; Fri, 3 Aug 2018 13:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D93E2C12F; Fri, 3 Aug 2018 13:19:31 +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 456F32C118 for ; Fri, 3 Aug 2018 13:19:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 478186B0008; Fri, 3 Aug 2018 09:19:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 428766B0010; Fri, 3 Aug 2018 09:19:29 -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 33E2D6B0266; Fri, 3 Aug 2018 09:19:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id 08C1D6B0008 for ; Fri, 3 Aug 2018 09:19:29 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id p11-v6so4566846oih.17 for ; Fri, 03 Aug 2018 06:19:29 -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=ijZd5EnlVUzQGVIZxvvAwHRxUdg2yJrJvmxol+vFlzk=; b=qs2nkdnBqfJ5lCIkGHxZ3+19DzOszgA00Em1tebXZ4Y19496shJPZjYNkfFieo14oh S7Q9E9AeQ2LcPCS2cBjhnmsSN9Dp+578ekk0r1toStVSn3UURIX0iio41pqc/k8Icmb+ 8xG5NDd4NzIVcO9lMYgarcHeBRsyz60LcrkOjakphcLGPlFrt8foTtsvUkHacdMSmkWK u7Hyi6G+ODFr9w/hBMvIuK8Lp/haXIm9MdFV7xBR8wdQnHl5VIf1IR06dl5NbsOJP49S 7eFEqrZ/iNgi5SPnjPU7LTwSazgkGxiQqYH13nsam0bl9UIClFMPEzEJVmUxKgvurMpM 8A/A== 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: AOUpUlGEXpCLGLg83BQbKHgrTWVgEtrtTyFlAKlbLihxb1/W2YjT7lM/ ToEy0ARlsxwJ8qAPqd+itHAL4aCoSIU7mYCpQDAdgJjNgloVJimlyIaHNGe5mRBhAAw8JWBcIOH 3GfBZBcWmo4rFqhXJnxGAdVxmu2Z1m8Xl7CnD7G+36EM66WHmnOCnedR8sth2g4UIeA== X-Received: by 2002:a54:4f94:: with SMTP id g20-v6mr3340743oiy.130.1533302368731; Fri, 03 Aug 2018 06:19:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeSwAxkoIBdK0qZh4aqBL5FnManHep8b1IQoJv1QBJNKxQ4V4HMn4VIti2ZsR3RPb7QehE2 X-Received: by 2002:a54:4f94:: with SMTP id g20-v6mr3340647oiy.130.1533302367355; Fri, 03 Aug 2018 06:19:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533302367; cv=none; d=google.com; s=arc-20160816; b=lNjDVGpDbIJJnttCbC6h7RThfNiDju1sdbP5IBXV8XkH74eVkpFKyQHuYmAnDSF+Tr kpViztUm5XB+Vn2o0ihSPcOPWNGcH+J30i4qbMYAhTlKYrVJ0YhJQBwzx3V1m5ax5T3E PU44b8bYKPJEdJYHneo1Wgymxrcny1ydxGUBj5p6Hck/Ddt93Ci4Du7GEhkdSHfJnFVp Fw0MtAwi7CjsNXMxx868EwNqfcd8UzFLPnfSjtzRw7esn/mjbAr1i5SYTx83gKXQAtE/ tIkX8i+1Y6Hl4HphSZ9FPkLB5Rlj9udKx7AxH/pWMDpg+8etPdfjCSDjoCrT4Mb7C4Zw la8g== 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=ijZd5EnlVUzQGVIZxvvAwHRxUdg2yJrJvmxol+vFlzk=; b=MFigEWsG/Dv8wegwkLwh3bvbd7AREK7s+eEPJwpT2Q69BcjaOkU0xQBovBHG4uuMqs 9jkQdSCdIbUwJ1wRabDqIIrpSlyN9Zt/HxfLr0ylXu61PhH0cYU2r/SVEm6R3EqUM3pt aXNxgXqqhnOZLI+VW5TiTeS7/dZnbgMxVarILEZk+cbNrbA64k/IOeSaaz0aun/XFqqF qs6QS0rP17UvQWslZIe97WPFj66u3bcuBkcGv4ltYp3dbXw+J2tHb7ZFNdkTPRBbmVbI 1AxOPhGmCOEDmQgL7CwbryhM/avcvKk0yYo0T9BBeQLqg6oSIMewyFaCiC6J7mQt51xV 0hug== 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 d14-v6si3415162oig.71.2018.08.03.06.19.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 06:19:27 -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 fsav305.sakura.ne.jp (fsav305.sakura.ne.jp [153.120.85.136]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w73DJEnW026935; Fri, 3 Aug 2018 22:19:14 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav305.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav305.sakura.ne.jp); Fri, 03 Aug 2018 22:19:14 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav305.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 w73DJ9do026900 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 3 Aug 2018 22:19:14 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: akpm@linux-foundation.org, mhocko@kernel.org, rientjes@google.com Cc: linux-mm@kvack.org, Tetsuo Handa Subject: [PATCH] mm,oom: Remove wake_oom_reaper(). Date: Fri, 3 Aug 2018 22:19:10 +0900 Message-Id: <1533302350-3398-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 --- 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; }