From patchwork Wed May 22 10:08:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10955551 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 CA79D6C5 for ; Wed, 22 May 2019 10:08:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCCAF28A0A for ; Wed, 22 May 2019 10:08:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B072B28AF5; Wed, 22 May 2019 10:08:30 +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 5565B28A91 for ; Wed, 22 May 2019 10:08:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32A6B6B000E; Wed, 22 May 2019 06:08:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2DE796B0010; Wed, 22 May 2019 06:08:27 -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 1A63D6B0266; Wed, 22 May 2019 06:08:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id EF62B6B000E for ; Wed, 22 May 2019 06:08:26 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id 68so949616otu.18 for ; Wed, 22 May 2019 03:08:26 -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=R2PWREw74tSe9/R17jGNrTFGBbP2fe2DvENyY7ygjHk=; b=M8CfkCAXg7CdxUpMVDmUFloFsae+w0r+vj2KsfG4RcVzmusuCBmEkxI/WiVxtmRXE1 WPeixOSUOG+vGDWCOKbeZw7+XwPor7FbHNI67ZmS8FWR5HiCeqAf9rQ1IVCibURqcgQ/ yAly1CJzetIX9BsbXIqD6ix0Izvm41k5aW2xemLGqmGM1yKgbM4ppHST5Y0syi06d++H zh3SHD3DrxdVNlN3/nPYvfi1oozIUCoz62bEQha2EtcHPVusCg2Ap6e6E/K/Rpq/xHB8 Mba84WeGfqLlATZArePCIrZM6b41AsQn0dRHCS4IxVAUgb9URHDxHAL1/aizkwynYx2B Lapw== 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: APjAAAV3+ccJUYd4JuSX5lbYQOUkgIUCwODSQxuwe3bQDFQP7LvSQ1tt 4x/5aVE+qsO4uYw+jjGjupmKlXQn6T79ZiakeyuBRZ3sbNEio9BN/vS/cBEC1NwxaWbhWc9DcsL 5fHar5S+n//hSBdK2SKkaSxcvdZcrYXm+cCnxdweYWZcAznPJTBYM2RgZTQDxlZDf1A== X-Received: by 2002:a9d:71d1:: with SMTP id z17mr26406243otj.22.1558519706604; Wed, 22 May 2019 03:08:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8dsOVzc+HBw/ADTcWeNAiJLkzaOlNv/GrZbAVsxBm34xKSyi9YyzEs73mqQltpTgHacvI X-Received: by 2002:a9d:71d1:: with SMTP id z17mr26406187otj.22.1558519705765; Wed, 22 May 2019 03:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558519705; cv=none; d=google.com; s=arc-20160816; b=OPxTUcjtUBmZUYEhlMNI4gFgnpwIRVYdkRa7RVmrYF3rHqiWGEYWzltpQ4nqn7G4g5 ohUsn0muJJF1xTwyTJB0+f/gKKmAMQeL8TKa92h+ok9xwP/fIeycQ/NdSZrSnDz88lXL UUZRVwqYvK72WShcIXf8jZf7Ra+mpQlq6I3FbMOKw/cAYnICahy22DUfhYBHM2C6gUui Pwvwgt3wdzovXDGGlUWr8Dr8BKtHWWWUiGA7Oou9YB5zwrWlN2GjfhkMVS4QIMb7G8Cz ffBZXrQf4CY2wwmUcH7+CvMLR7vzADZuc5MzdYuHSoC5caknWDlnS5x86BPk9PMFXagW c3+g== 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; bh=R2PWREw74tSe9/R17jGNrTFGBbP2fe2DvENyY7ygjHk=; b=RH+rgTyK+FTidHpSOqv8jTvrN9JEy1OQffh79YRBXiuuY3B/VfiYHKJ2tea63h9W0v 9KtWQ4X2RayYixPYgDq8gYZqqMN2bK+cmWaAIMJlKnabSippvYnmseVYSL2HeKpGlk8H mZ6VAufonVCNmfT52A7mEvECQNk0E9DoldRxkBazWI4N29l36Fv/uxx6Jf3xnDG8LvzH FuAS7E1gMuDScwHURMEqzmd2gz0sfyCyNjbd9WcyBca/hOomc+WH9t3YNG1w3bRpyvNZ Sn+cN2XD/RMppbDUdrmpmT4qsibkKWoxwdtcxJWtvCIjuwO+e3HgoFNz0sPkFOWgxIvB P0Aw== 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 j13si13264020otn.142.2019.05.22.03.08.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 03:08:25 -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 fsav404.sakura.ne.jp (fsav404.sakura.ne.jp [133.242.250.103]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x4MA8J0k039248; Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav404.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp); Wed, 22 May 2019 19:08:19 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126012062002.bbtec.net [126.12.62.2]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x4MA8Fdm039015 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Andrew Morton Cc: linux-mm@kvack.org, Michal Hocko , Tetsuo Handa Subject: [PATCH 1/4] mm, oom: Remove redundant OOM score normalization at select_bad_process(). Date: Wed, 22 May 2019 19:08:03 +0900 Message-Id: <1558519686-16057-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 Since commit bbbe48029720d2c6 ("mm, oom: remove 'prefer children over parent' heuristic") removed "%s: Kill process %d (%s) score %u or sacrifice child\n" line, oc->chosen_points is no longer used after select_bad_process(). Signed-off-by: Tetsuo Handa --- mm/oom_kill.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 5a58778..7534046 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -381,8 +381,6 @@ static void select_bad_process(struct oom_control *oc) break; rcu_read_unlock(); } - - oc->chosen_points = oc->chosen_points * 1000 / oc->totalpages; } /** From patchwork Wed May 22 10:08:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10955647 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 53E80912 for ; Wed, 22 May 2019 10:46:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 435E21FFB1 for ; Wed, 22 May 2019 10:46:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3788628733; Wed, 22 May 2019 10:46:45 +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 4653B1FFB1 for ; Wed, 22 May 2019 10:46:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1AC126B0003; Wed, 22 May 2019 06:46:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 15E8B6B0006; Wed, 22 May 2019 06:46:43 -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 026B96B0007; Wed, 22 May 2019 06:46:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id B99E56B0003 for ; Wed, 22 May 2019 06:46:42 -0400 (EDT) Received: by mail-pf1-f197.google.com with SMTP id t1so1512413pfa.10 for ; Wed, 22 May 2019 03:46:42 -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=mXB+S4M+P8XzrJ6i/1ecfgvGIikSNdfbe764del+NnQ=; b=tZCToKx6EiSfUu5BKPUyWUJnGvoDGfUSpaB97dl707ueY5sgxtbai7Zl+l+PchBrvO NGMf1srO7QeBrRB3SiU70NxR/vyWzoawsSn4zFcKS/rqnBOyTxFk2u6rKeC9wDG7Akxx JdveJ46pU59WMYtshfCbulJHkw9U4ol3uG7peIhggrU2uI5AZ6PTax6GOiCUteyufKl/ JzFzLSZb9bc1cDaTauy3aJxALWM9MmWg11+8tWjEtQ/GIMVQurpjUrT7vSVGcuFEB/4n vtE1DEGoSzyIGNzeZL1JuTOzdLHATrB9AlRLiXD7WiCKTwJcSEK2fZEvszJksKE0Af6x TpOA== 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: APjAAAUj/SGySYdA6fcc0hF4ZOM8ZxomVZtQag3V3mZSOUesGxaH6vvy DXZnWtdiMCe8SBcfDXqBfbzFbac+jfW4gy7FExHjO1++2FM36FI1aEWiSC5U4+RH7v8TbKTTipd +SQAy+i/kG8GW762EC/L7dy4Ct4QADT+cm0f8ORzZ+sQQVpeQwT91S+qvBbHBqN3lFg== X-Received: by 2002:a62:470e:: with SMTP id u14mr95710946pfa.31.1558522002292; Wed, 22 May 2019 03:46:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBuwPRKhvaTTehlb1dddJloHfAjwoGSSjXkuvNuO8ML7/mTbxDEwLiT2/MTY9WE9dWn5sZ X-Received: by 2002:a62:470e:: with SMTP id u14mr95710788pfa.31.1558522000821; Wed, 22 May 2019 03:46:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558522000; cv=none; d=google.com; s=arc-20160816; b=uxo2zNxM+ufMe6zx4TIOAi1pS/k/N0r6DMFXIOyduej0CoKTg23NU9heDQyqZ2SGMx TyOjdCi1a3912hofjcAK8elm36kFzdeuOmFm+0c4NJwQxXuj7l2+QYv2JFRZutu6kxsv shl9sK3ITkWUXxWzvAvPRsTVlPyURG1NSooWqbnFeezTt7nnco1ICfz63fvejGcp+ZJt g43D4aUrC4yZ5JpGXkRqwS88kiG9L8dfM6svkGtOpybuXQUZH6enMt/MCyRjWr4d+4jP 5iwSVIDFlNo7K2dPPtnoDha/iPY2vbuNIW0eWhJG3IHBkljhYexxWelS/4NANXAjuaEL P5sQ== 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; bh=mXB+S4M+P8XzrJ6i/1ecfgvGIikSNdfbe764del+NnQ=; b=WYVQ5DXF5NTiqJ38AFzGZoZjWmB1fu1vo0DGYO3MoGEb513NwvtBpRqytZCJkS+144 sMYffYsNtAeLhG59SdGhO8oVvUmWTzXg5COpf2Bzum5gqiHQWHaC5ufMG8w72mJb1VUF EEbrIrVI0FPh5tNAB+rMjbtP8IWbCBbvuLNV7OrPMmQ7mfwQ/UJH+Xj1vslt6wQvSJ2Q V6wTYKjdWoALv4ymA5wSwyizdg0hhcOVq1e1XFTxkb0Rhb6wfUON8Dk06aBN1I047paz qcCedjAuHgmUbvx1TesTFiYaOGZcflOZn7uevpVE4B0NFE6fUMN552uffw97iLYXp03r w/jQ== 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 b9si26242926plk.333.2019.05.22.03.46.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 03:46:40 -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 fsav404.sakura.ne.jp (fsav404.sakura.ne.jp [133.242.250.103]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x4MA8Jl9039254; Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav404.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp); Wed, 22 May 2019 19:08:19 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126012062002.bbtec.net [126.12.62.2]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x4MA8Fdn039015 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Andrew Morton Cc: linux-mm@kvack.org, Michal Hocko , Tetsuo Handa , Dmitry Vyukov , Petr Mladek , Sergey Senozhatsky , Steven Rostedt Subject: [PATCH 2/4] mm, oom: Avoid potential RCU stall at dump_tasks(). Date: Wed, 22 May 2019 19:08:04 +0900 Message-Id: <1558519686-16057-2-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1558519686-16057-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1558519686-16057-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 dump_tasks() calls printk() on each userspace process under RCU which might result in RCU stall warning. I proposed introducing timeout for dump_tasks() operation, but Michal Hocko expects that dump_tasks() is either print all or suppress all [1]. Therefore, this patch changes to cache all candidates at oom_evaluate_task() and then print the cached candidates at dump_tasks(). With this patch, dump_tasks() no longer need to call printk() under RCU. Also, dump_tasks() no longer need to check oom_unkillable_task() by traversing all userspace processes, for select_bad_process() already traversed all possible candidates. Also, the OOM killer no longer need to call put_task_struct() from atomic context, and we can simplify refcount handling for __oom_kill_process(). This patch has a user-visible side effect that oom_kill_allocating_task path implies oom_dump_tasks == 0, for oom_evaluate_task() is not called via select_bad_process(). But since the purpose of enabling oom_kill_allocating_task is to kill as quick as possible (i.e. tolerate killing more than needed) whereas the purpose of dump_tasks() which might take minutes is to understand how the OOM killer selected an OOM victim, not printing candidates should be acceptable when the administrator asked the OOM killer to kill current thread. [1] https://lore.kernel.org/linux-mm/20180906115320.GS14951@dhcp22.suse.cz/ Signed-off-by: Tetsuo Handa Cc: Dmitry Vyukov Cc: Petr Mladek Cc: Sergey Senozhatsky Cc: Steven Rostedt --- include/linux/sched.h | 1 + mm/oom_kill.c | 44 +++++++++++++++++++------------------------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 1183741..f1736bf 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1180,6 +1180,7 @@ struct task_struct { #ifdef CONFIG_MMU struct task_struct *oom_reaper_list; #endif + struct list_head oom_candidate_list; #ifdef CONFIG_VMAP_STACK struct vm_struct *stack_vm_area; #endif diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 7534046..00b594c 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -63,6 +63,7 @@ * and mark_oom_victim */ DEFINE_MUTEX(oom_lock); +static LIST_HEAD(oom_candidate_list); #ifdef CONFIG_NUMA /** @@ -333,6 +334,9 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) goto abort; } + get_task_struct(task); + list_add_tail(&task->oom_candidate_list, &oom_candidate_list); + /* * If task is allocating a lot of memory and has been marked to be * killed first if it triggers an oom, then select it. @@ -350,16 +354,11 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) if (points == oc->chosen_points && thread_group_leader(oc->chosen)) goto next; select: - if (oc->chosen) - put_task_struct(oc->chosen); - get_task_struct(task); oc->chosen = task; oc->chosen_points = points; next: return 0; abort: - if (oc->chosen) - put_task_struct(oc->chosen); oc->chosen = (void *)-1UL; return 1; } @@ -401,11 +400,8 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask) pr_info("Tasks state (memory values in pages):\n"); pr_info("[ pid ] uid tgid total_vm rss pgtables_bytes swapents oom_score_adj name\n"); - rcu_read_lock(); - for_each_process(p) { - if (oom_unkillable_task(p, memcg, nodemask)) - continue; - + list_for_each_entry(p, &oom_candidate_list, oom_candidate_list) { + cond_resched(); task = find_lock_task_mm(p); if (!task) { /* @@ -424,7 +420,6 @@ static void dump_tasks(struct mem_cgroup *memcg, const nodemask_t *nodemask) task->signal->oom_score_adj, task->comm); task_unlock(task); } - rcu_read_unlock(); } static void dump_oom_summary(struct oom_control *oc, struct task_struct *victim) @@ -455,7 +450,7 @@ static void dump_header(struct oom_control *oc, struct task_struct *p) if (is_dump_unreclaim_slabs()) dump_unreclaimable_slab(); } - if (sysctl_oom_dump_tasks) + if (sysctl_oom_dump_tasks && !list_empty(&oom_candidate_list)) dump_tasks(oc->memcg, oc->nodemask); if (p) dump_oom_summary(oc, p); @@ -849,17 +844,11 @@ static void __oom_kill_process(struct task_struct *victim, const char *message) struct mm_struct *mm; bool can_oom_reap = true; - p = find_lock_task_mm(victim); - if (!p) { - put_task_struct(victim); - return; - } else if (victim != p) { - get_task_struct(p); - put_task_struct(victim); - victim = p; - } - /* Get a reference to safely compare mm after task_unlock(victim) */ + victim = find_lock_task_mm(victim); + if (!victim) + return; + get_task_struct(victim); mm = victim->mm; mmgrab(mm); @@ -931,7 +920,6 @@ static int oom_kill_memcg_member(struct task_struct *task, void *message) { if (task->signal->oom_score_adj != OOM_SCORE_ADJ_MIN && !is_global_init(task)) { - get_task_struct(task); __oom_kill_process(task, message); } return 0; @@ -954,7 +942,6 @@ static void oom_kill_process(struct oom_control *oc, const char *message) mark_oom_victim(victim); wake_oom_reaper(victim); task_unlock(victim); - put_task_struct(victim); return; } task_unlock(victim); @@ -1077,7 +1064,6 @@ bool out_of_memory(struct oom_control *oc) 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) { - get_task_struct(current); oc->chosen = current; oom_kill_process(oc, "Out of memory (oom_kill_allocating_task)"); return true; @@ -1099,6 +1085,14 @@ bool out_of_memory(struct oom_control *oc) if (oc->chosen && oc->chosen != (void *)-1UL) oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" : "Memory cgroup out of memory"); + while (!list_empty(&oom_candidate_list)) { + struct task_struct *p = list_first_entry(&oom_candidate_list, + struct task_struct, + oom_candidate_list); + + list_del(&p->oom_candidate_list); + put_task_struct(p); + } return !!oc->chosen; } From patchwork Wed May 22 10:08:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10955553 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 383AF6C5 for ; Wed, 22 May 2019 10:08:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A37128AF5 for ; Wed, 22 May 2019 10:08:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1ED2228AFB; Wed, 22 May 2019 10:08:44 +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 9366328B21 for ; Wed, 22 May 2019 10:08:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CDB96B0010; Wed, 22 May 2019 06:08:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 87F6A6B0266; Wed, 22 May 2019 06:08:42 -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 76EB36B0269; Wed, 22 May 2019 06:08:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 4D6496B0010 for ; Wed, 22 May 2019 06:08:42 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id e88so951630ote.14 for ; Wed, 22 May 2019 03:08:42 -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=rs4UdQDICU/o5iwjI5TTWqhrv+pRH7CNKbCoDL5CNSw=; b=ONR0UKKMK7csi5WsX2I/eDJrE9/B3i76QJ+Q1KZpYbdg4MxmRFAOL7gxO1HvhPnnP9 zQEUjmODixv3zrLy5da0CaWUPqR1U5b9J3Y9ht0dkFed3Vhq2PQ/yvzPP9rwyBnl56xE QIEC1XFSiOWo36j1DfG/BkL1BLcJbMpf6cfGXKMSx5B4mT5SgXd9TgjDAo4Dzwbt5IXm nMLPjTBuMjIIbSSFczibZ36xK29moVTwelLEHOhJ9WV1X3tJWUuZLJvwi3IT1GdFXuOb irB3xlHwq9lMdT5rkpSl4AAbbxfrohkSMA+fmldhnQ92FTeRfbhDzJxA9weqv6YbtFg+ 0Pww== 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: APjAAAXVBBNgA2yUMcMyiYjBlPTwpDYpbr8j5t/qHbtTwoAx1QIi3kVY 0e9m2UkMetBcx39e2goBv9ifMRFCKkaS8UgH7DE5iJ3fVjI8dTdwm7sigSmWY9HP+Jz8BGA2qLf wP+RbezvOIyXcf3EOx5+Rm9XZfnXhBXQqnG1V08JMa40ExbwB48BfhLgEzABsKFIw9A== X-Received: by 2002:aca:b1d4:: with SMTP id a203mr6624877oif.67.1558519721946; Wed, 22 May 2019 03:08:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwI/RfoLfW9uIdw2qETKAO3znX88XG1zZSIrdnkUp6qC+TjG6QWyvSCpRL6GgQ8SQtjWDfB X-Received: by 2002:aca:b1d4:: with SMTP id a203mr6624815oif.67.1558519720676; Wed, 22 May 2019 03:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558519720; cv=none; d=google.com; s=arc-20160816; b=vLkl0SVTuiLbX03Qsa8k3Zx7OkmX2FgQyGRobhovBfEcSJLuSAvHvzss7Ay3LnFIBs tCGfwccZPhMihmWdw9ggdEjZKoiCTBbkaS2qLkJaETq11a9Jbfr7MPZpV4w7DHBjt/Ea rAGzpZR8n/znSxWkKDESFTHBYqGjpRy6W2jMxozd7mkzxKJcS9TmD3PUtIB3CMwZjvCF /hriUvVJTaOLGe3NmWn8i2dUhURQBFkwNxTx/oJtha0vGIGoQPk6qu1JigyC0VOJJMGO p7xR6bp0JwfZ16HVrAp5G6gWh7kuQGlYigWL1HfuetRCazIynrXchurbUe4fav70RFlC RZ6w== 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; bh=rs4UdQDICU/o5iwjI5TTWqhrv+pRH7CNKbCoDL5CNSw=; b=h31XnzFb4N5LY2CWzHbgmcmjuwd1z70XsRO6NLbhxpeoe64hvpdShcb9n2TKi0tAF9 Cqs3g8Iw49wKilzU0yqUqHUrK4z2vP/S1VjmyzBVh8uCTARE3kyoi6CbR9XxP7EjsRUb s26AH3EonBEtz844BF80ikoyBZVx7S51SWB2XXJD4aSebmNsmfwFGjgnBj0HJm02IB+d TBeJug+aeZJvKzd1cwfsHO22+LfHSzZ4sPbIdqHHTM9pkqcvcBFfLjw1SVjh0hwQB1kx PXykb78czGbDO6+OimMjrt+CGdZ17EAPzvEl1qeD6bwkVrEZn+2f+YS4lRAm1II2Kcj2 QuMA== 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 l9si13003218otf.273.2019.05.22.03.08.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 03:08:40 -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 fsav404.sakura.ne.jp (fsav404.sakura.ne.jp [133.242.250.103]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x4MA8JdW039257; Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav404.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp); Wed, 22 May 2019 19:08:19 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126012062002.bbtec.net [126.12.62.2]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x4MA8Fdo039015 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Andrew Morton Cc: linux-mm@kvack.org, Michal Hocko , Tetsuo Handa Subject: [PATCH 3/4] mm, oom: Wait for OOM victims even if oom_kill_allocating_task case. Date: Wed, 22 May 2019 19:08:05 +0900 Message-Id: <1558519686-16057-3-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1558519686-16057-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1558519686-16057-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 "mm, oom: Avoid potential RCU stall at dump_tasks()." changed to imply oom_dump_tasks == 0 if oom_kill_allocating_task != 0. But since we can expect the OOM reaper to reclaim memory quickly, and majority of latency is not for_each_process() from select_bad_process() but printk() from dump_header(), waiting for in-flight OOM victims until the OOM reaper completes should generate preferable results (i.e. minimal number of OOM victims). As side effects of this patch, oom_kill_allocating_task != 0 no longer implies oom_dump_tasks == 0, complicated conditions for whether to enter oom_kill_allocating_task path are simplified, and a theoretical bug that the OOM killer forever retries oom_kill_allocating_task path even after the OOM reaper set MMF_OOM_SKIP is fixed. Signed-off-by: Tetsuo Handa --- mm/oom_kill.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 00b594c..64e582e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -367,19 +367,29 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) * Simple selection loop. We choose the process with the highest number of * 'points'. In case scan was aborted, oc->chosen is set to -1. */ -static void select_bad_process(struct oom_control *oc) +static const char *select_bad_process(struct oom_control *oc) { - if (is_memcg_oom(oc)) - mem_cgroup_scan_tasks(oc->memcg, oom_evaluate_task, oc); - else { - struct task_struct *p; + struct task_struct *p; - rcu_read_lock(); - for_each_process(p) - if (oom_evaluate_task(p, oc)) - break; - rcu_read_unlock(); + if (is_memcg_oom(oc)) { + mem_cgroup_scan_tasks(oc->memcg, oom_evaluate_task, oc); + return "Memory cgroup out of memory"; } + rcu_read_lock(); + for_each_process(p) + if (oom_evaluate_task(p, oc)) + break; + rcu_read_unlock(); + if (sysctl_oom_kill_allocating_task && oc->chosen != (void *)-1UL) { + list_for_each_entry(p, &oom_candidate_list, + oom_candidate_list) { + if (!same_thread_group(p, current)) + continue; + oc->chosen = current; + return "Out of memory (oom_kill_allocating_task)"; + } + } + return "Out of memory"; } /** @@ -1021,6 +1031,7 @@ bool out_of_memory(struct oom_control *oc) { unsigned long freed = 0; enum oom_constraint constraint = CONSTRAINT_NONE; + const char *message; if (oom_killer_disabled) return false; @@ -1061,15 +1072,7 @@ bool out_of_memory(struct oom_control *oc) oc->nodemask = NULL; check_panic_on_oom(oc, constraint); - 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) { - oc->chosen = current; - oom_kill_process(oc, "Out of memory (oom_kill_allocating_task)"); - return true; - } - - select_bad_process(oc); + message = select_bad_process(oc); /* Found nothing?!?! */ if (!oc->chosen) { dump_header(oc, NULL); @@ -1083,8 +1086,7 @@ bool out_of_memory(struct oom_control *oc) panic("System is deadlocked on memory\n"); } if (oc->chosen && oc->chosen != (void *)-1UL) - oom_kill_process(oc, !is_memcg_oom(oc) ? "Out of memory" : - "Memory cgroup out of memory"); + oom_kill_process(oc, message); while (!list_empty(&oom_candidate_list)) { struct task_struct *p = list_first_entry(&oom_candidate_list, struct task_struct, From patchwork Wed May 22 10:08:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10955549 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 73C96112C for ; Wed, 22 May 2019 10:08:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 661D128B68 for ; Wed, 22 May 2019 10:08:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5959428B75; Wed, 22 May 2019 10:08:28 +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 CA91C28B72 for ; Wed, 22 May 2019 10:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEC856B000D; Wed, 22 May 2019 06:08:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C9D986B000E; Wed, 22 May 2019 06:08:26 -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 B8BE26B0010; Wed, 22 May 2019 06:08:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-it1-f198.google.com (mail-it1-f198.google.com [209.85.166.198]) by kanga.kvack.org (Postfix) with ESMTP id 996DF6B000D for ; Wed, 22 May 2019 06:08:26 -0400 (EDT) Received: by mail-it1-f198.google.com with SMTP id 15so1781790ita.0 for ; Wed, 22 May 2019 03:08:26 -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=JTkPKcZoqc0umMTYWVjyrIIccX3EbqijR3USJmAGcrM=; b=rX8RO23xWi3jIbcLffq5glGUmg+FZ1uV8ACtbXJZftyN91OniCTCuQEkmdMPqJCLFv sM0Fgsoj1AV9Tf9opSM8rosKG4+Se+SeKKnysRDXbM7H490AmqmorQQzOk0WC9z64xAI vaC9bopKMLV5oKNNpy083g01wv/66E9fpy6vnMDVK/cAQocN58jBHtUpsxmEcU0sFIZn fPN9Jo6EScmCfcFJjBCtAk7gCksO9srnWkK3uUnr9DFBtJtwEqluW+cZ/yQ/fC9Y2lld fmS5YlhHJJApJYjRrBsCjN4np4/4AM4REUSIKnDYfh47OjEoz9w6qwawa8ok/nuUM57G Lqmg== 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: APjAAAX0aGXPEMyW/rP5LlCwbWphuP94hYMCOnv68cIcmzQBt7CVK944 +MVKeaPJ7eyxacUvcKhRyJt1bjZudCH7cso/NYqrVoSfqhyCuNAP8b7LG5b2gcqBU/298n8IgeA Lr5HateAWsTyXhFasoedrACjY0ISR0CZrLFoYBArevY+CA+uux9NDhceyKzfdXqQ2wA== X-Received: by 2002:a24:47cc:: with SMTP id t195mr7408809itb.117.1558519706377; Wed, 22 May 2019 03:08:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFHpG3YFwoecpgPfp+HtjHM5iD3UIcUMGaVC+QqiVVISCi7DG3XMAl0915sX7fEt8Or6Ox X-Received: by 2002:a24:47cc:: with SMTP id t195mr7408764itb.117.1558519705627; Wed, 22 May 2019 03:08:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558519705; cv=none; d=google.com; s=arc-20160816; b=FQDSdebj80ObHMAj3BqagCI9xdIS76iwuEv9/kIhQls8A52zhfAAmNXuTeHxH/R3vJ u6HiqDV79HAuSLE5hMF7w6Z6uBO9u1Q9kP67XmhMu8a+d7AjX9a8d4FN0Lv1xzVB22vS oqM+VDnN75iWYw/tNYll0WW/6qUDLzhYYGQ75xCWZPVG//oeQkutZgXRetqUPwPgZs9r uFFhZeUjO65TUkGc0rssm3yfx55DpQVqZaztNLHUgdcWvm5D1lwNlzsmfgPxZPSHM/l2 irzY1pqN+NYjJ4PWWQPza3tZRFAgol+cAh2xqGNtL6hdH1F3zplOsHiH4W7j5hv7efVI ed1A== 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; bh=JTkPKcZoqc0umMTYWVjyrIIccX3EbqijR3USJmAGcrM=; b=HJbxZnT8/B3ac05GWtWxldhbzAfwL5+efodiLENjANn9MYCacO3SISgwnhxcOcPjuC rBhXx9XnkS312Wg7dKLa+nWAqmUZ8o1gr+8+mAjN9MYA7Z1UPiEeaR1eCgjjLzZURlXY 4QOWHFnAOAVHGxnlvLZfBKg1nYCmI32jZ6w9jpz0jBsbIqTb1SnMiP1C6zZqM7+6HD8h ydukQuQzTKLiliSKXu4KxSDfKwaEfzuJ7p5b0ff0VceN4QOWzhzzubnwb/kTbnMBBL0c ghjNElWqUTV9SWEJxf3tI8bpcHOZflx8sHI7byjtrnFN5p1xpMYKh9sVY0m4zMD4HpMD lBWw== 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 129si3623361ity.38.2019.05.22.03.08.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 03:08:25 -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 fsav404.sakura.ne.jp (fsav404.sakura.ne.jp [133.242.250.103]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x4MA8JZe039260; Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav404.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp); Wed, 22 May 2019 19:08:19 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav404.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126012062002.bbtec.net [126.12.62.2]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x4MA8Fdp039015 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 22 May 2019 19:08:19 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Andrew Morton Cc: linux-mm@kvack.org, Michal Hocko , Tetsuo Handa Subject: [PATCH 4/4] mm, oom: Respect oom_task_origin() even if oom_kill_allocating_task case. Date: Wed, 22 May 2019 19:08:06 +0900 Message-Id: <1558519686-16057-4-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1558519686-16057-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> References: <1558519686-16057-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 Currently oom_kill_allocating_task path ignores oom_task_origin() tasks. But since oom_task_origin() is used for "notify me first using SIGKILL (because I'm likely the culprit for this situation)", respect it. Signed-off-by: Tetsuo Handa --- mm/oom_kill.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 64e582e..bdd90b5 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -380,7 +380,8 @@ static const char *select_bad_process(struct oom_control *oc) if (oom_evaluate_task(p, oc)) break; rcu_read_unlock(); - if (sysctl_oom_kill_allocating_task && oc->chosen != (void *)-1UL) { + if (sysctl_oom_kill_allocating_task && oc->chosen != (void *)-1UL && + oc->chosen_points != ULONG_MAX) { list_for_each_entry(p, &oom_candidate_list, oom_candidate_list) { if (!same_thread_group(p, current)) From patchwork Thu May 23 22:04:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 10958845 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 2D5E6112C for ; Thu, 23 May 2019 22:04:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1163528660 for ; Thu, 23 May 2019 22:04:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 054A028789; Thu, 23 May 2019 22:04:46 +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 1E0F928660 for ; Thu, 23 May 2019 22:04:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95A116B0003; Thu, 23 May 2019 18:04:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 93A876B0005; Thu, 23 May 2019 18:04:42 -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 7F8B56B0006; Thu, 23 May 2019 18:04:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by kanga.kvack.org (Postfix) with ESMTP id 52F506B0003 for ; Thu, 23 May 2019 18:04:42 -0400 (EDT) Received: by mail-io1-f72.google.com with SMTP id z2so5804190iog.12 for ; Thu, 23 May 2019 15:04:42 -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:subject:to:cc :references:from:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=9nKU8NqRvqZx3WzNNGvgxe1LwRuzLp0wxpy3QaCqsnE=; b=VfY6Ihccmwi4rW9SnvmJkuvvNayXc+N2/IDIWQN2zA+3oIIwsgA0mQqHJuFwbiSDap ZmMSgrdw9VBgasfqEzIjqVQEv/plLzcLopFdexGMDM6su3brkiGZO5mPhyrpAMGNW0ZV xf7Xja3/GP/NJDsPhQGz/VqDTj5yY6jUJkTHzgR/7GgQo6c0quPy10pU421jUqwPzLxX Vq4t9DqCs2OPtb6kRAJcKLbcGiCmuDjG68sHtXFmZ+uWZUSZVhpT+Wc6hQflprHDlkm9 xx+saGDZAQRCbrO1a4Xo8aS3wzm8sZLNMUUyX89DPXLgdYuwChfo68BUiY6Kir7qr+XI Y4ew== 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: APjAAAWKcJWD1ln9xgztsT0DDV2bQ+QSHZznSA27jHz+TS711fIJ4mws SiAOxdAZdNVoxQaPp7D3TEaI+JkiWSOrU4MzdxbcSIvcX0S6a6C2YbeXsHn/g+QGT9Ayc8vjA7z sr2doUQIlihF7er4IcpnvVIGj3xjs5AADvIRq9SE0nbGqomafv14A+z5KgvsCKoYpYA== X-Received: by 2002:a5e:9505:: with SMTP id r5mr54644489ioj.285.1558649081935; Thu, 23 May 2019 15:04:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQt24df9e5CFtcI1VU56ED8PHyh5Z/tD5LE50wzZR++DgDaHYzN6cSo0Vh+rEm5cdbJ3pc X-Received: by 2002:a5e:9505:: with SMTP id r5mr54644414ioj.285.1558649080686; Thu, 23 May 2019 15:04:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558649080; cv=none; d=google.com; s=arc-20160816; b=vppl3hKxHe3lrHa/vmMXgs0smnWopV4V1k/sHdEjhu959Ss0iUkt6bPqj8CdnnlGL9 bloCeCKaU2t5dUuwK9IwOwxBLX/FPZEfBRIHN+YjhxQkk71+vQq0RwJzKQOJCdWahu3e 801UxVgx1FURMi3o5trp55Txh7gpExc3okeCM6vDiM7kk5k1oNN1uYPxr/KIv5WkWlaY fUxBy7bmZ0MBHi7d8CB0eGr5pEHlNk+ZbmAsBsmHe5UxspEv4Fvpxuouxg0eovfuHTkz gmYD5hEXnxYwDnjyZpLL4gsi1SuUBABCHzeEQYR8gzvWCuyUYasKTlHWHARG20uq/kY8 OGzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=9nKU8NqRvqZx3WzNNGvgxe1LwRuzLp0wxpy3QaCqsnE=; b=Um70P1YokwDPkDGaYSW0NuZMnOre9BhT7QXZkiA5lzzNvXAiSFuFVwkpC8v3B3TVp0 7TIEhXlkAAyjerKM+JHnucARa6nGfCn/2w7+iSWs+COjzcrzFjTliS1zQhyCItzgS76q 3oZx0BlKMyRYd433j0w+VpXhSaeGnE8BIvJHFECOnMWCR/C/YjS/O5j3oRc+GvABoYXR M+8YUOwdgkmQnQLdpNjAOv0Qv3LPgGVx4UhRinT2T46P/X3A1Xw5uCut4ejAWzXIQJHz xmhWnpc15PcMq8HYX1BT4f0XY24IX0GhMSl/u8kU6ooAp8UR1dbA25/Ie+Eveztazq4P 2SMg== 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 s11si495234ioc.48.2019.05.23.15.04.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 15:04:40 -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 fsav402.sakura.ne.jp (fsav402.sakura.ne.jp [133.242.250.101]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id x4NM4acO052792; Fri, 24 May 2019 07:04:37 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav402.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp); Fri, 24 May 2019 07:04:36 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav402.sakura.ne.jp) Received: from [192.168.1.8] (softbank126012062002.bbtec.net [126.12.62.2]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id x4NM4atO052789 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NO); Fri, 24 May 2019 07:04:36 +0900 (JST) (envelope-from penguin-kernel@i-love.sakura.ne.jp) Subject: [PATCH 5/4] mm, oom: Deduplicate memcg candidates at select_bad_process(). To: Andrew Morton Cc: linux-mm@kvack.org, Michal Hocko References: <1558519686-16057-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> From: Tetsuo Handa Message-ID: <84c59c15-fb60-2421-3c75-cf704572f8d3@i-love.sakura.ne.jp> Date: Fri, 24 May 2019 07:04:37 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <1558519686-16057-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> Content-Language: en-US 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 "mm, oom: Avoid potential RCU stall at dump_tasks()." changed to cache all candidates at select_bad_process(), dump_tasks() started printing all threads upon memcg OOM event. Unfortunately, mem_cgroup_scan_tasks() can't traverse on only thread group leaders because CSS_TASK_ITER_PROCS does not work if the thread group leader already exit()ed. Signed-off-by: Tetsuo Handa --- mm/oom_kill.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/mm/oom_kill.c b/mm/oom_kill.c index bdd90b53bbd3..a92b2f70d15b 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -334,6 +334,20 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) goto abort; } + /* + * Since mem_cgroup_scan_tasks() calls this function on each thread + * whlie for_each_process() calls this function on each thread group, + * memcg OOM should evaluate only one thread from each thread group. + */ + if (is_memcg_oom(oc) && get_nr_threads(task) != 1) { + struct task_struct *p; + + list_for_each_entry_reverse(p, &oom_candidate_list, + oom_candidate_list) + if (same_thread_group(p, task)) + goto next; + } + get_task_struct(task); list_add_tail(&task->oom_candidate_list, &oom_candidate_list); @@ -350,9 +364,6 @@ static int oom_evaluate_task(struct task_struct *task, void *arg) if (!points || points < oc->chosen_points) goto next; - /* Prefer thread group leaders for display purposes */ - if (points == oc->chosen_points && thread_group_leader(oc->chosen)) - goto next; select: oc->chosen = task; oc->chosen_points = points;