From patchwork Tue May 29 09:55:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 10434695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3585B602BF for ; Tue, 29 May 2018 09:55:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26CF22866F for ; Tue, 29 May 2018 09:55:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B913286B8; Tue, 29 May 2018 09:55:57 +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=-5.2 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC335286B7 for ; Tue, 29 May 2018 09:55:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD83B6E3C7; Tue, 29 May 2018 09:55:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 927CD6E3C7 for ; Tue, 29 May 2018 09:55:52 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 11873723-1500050 for multiple; Tue, 29 May 2018 10:55:28 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Tue, 29 May 2018 10:55:29 +0100 From: Chris Wilson To: intel-gfx@lists.freedesktop.org Date: Tue, 29 May 2018 10:55:28 +0100 Message-Id: <20180529095528.30302-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.17.0 MIME-Version: 1.0 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Subject: [Intel-gfx] [PATCH] RFT mm/oomkill: Don't skip the reaper X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP If we find a task that has already been selected for reaping, consider that it may still free some memory. Currently, we skip such tasks believing that we've already extracted as memory free pages as possible from before hitting a livelock. In practice, at least on single user systems deliberating exercising oom, such processes have only begun to recover their pages and are still the worst hogs on the system. If we skip them, we just select yet more victims, and with sufficient enthusiasm may end up with all available processes marked for reaping, panicking in the process. Signed-off-by: Chris Wilson Cc: MichaƂ Winiarski --- mm/oom_kill.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 8ba6cb88cf58..2ca231202af9 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -49,6 +49,8 @@ #define CREATE_TRACE_POINTS #include +static bool task_will_free_mem(struct task_struct *task); + int sysctl_panic_on_oom; int sysctl_oom_kill_allocating_task; int sysctl_oom_dump_tasks = 1; @@ -201,19 +203,27 @@ unsigned long oom_badness(struct task_struct *p, struct mem_cgroup *memcg, if (oom_unkillable_task(p, memcg, nodemask)) return 0; + /* + * If we cannot lock the task's mm, it is in the process of being + * removed, so select it as the target of the repear and see if it + * recovers enough memory to continue. + */ p = find_lock_task_mm(p); if (!p) - return 0; + return ULONG_MAX; + + if (task_will_free_mem(p)) { + task_unlock(p); + return ULONG_MAX; + } /* * Do not even consider tasks which are explicitly marked oom - * unkillable or have been already oom reaped or the are in - * the middle of vfork + * unkillable or are in the middle of vfork (and so still share their + * parent's mm). */ adj = (long)p->signal->oom_score_adj; - if (adj == OOM_SCORE_ADJ_MIN || - test_bit(MMF_OOM_SKIP, &p->mm->flags) || - in_vfork(p)) { + if (adj == OOM_SCORE_ADJ_MIN || in_vfork(p)) { task_unlock(p); return 0; } @@ -806,11 +816,12 @@ static bool task_will_free_mem(struct task_struct *task) return false; /* - * This task has already been drained by the oom reaper so there are - * only small chances it will free some more + * This task has already been selected for the oom reaper, but + * the reaper is unable to make progress. Continue to dogpile + * on top until it succeeds. */ if (test_bit(MMF_OOM_SKIP, &mm->flags)) - return false; + return true; if (atomic_read(&mm->mm_users) <= 1) return true;