From patchwork Sat May 2 14:34:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11523941 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C43B281 for ; Sat, 2 May 2020 14:35:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 87BEA206A4 for ; Sat, 2 May 2020 14:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YQXECGzk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87BEA206A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BF36D8E0006; Sat, 2 May 2020 10:35:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BA48D8E0001; Sat, 2 May 2020 10:35: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 AE0358E0006; Sat, 2 May 2020 10:35:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 94E068E0001 for ; Sat, 2 May 2020 10:35:27 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 51AF282499A8 for ; Sat, 2 May 2020 14:35:27 +0000 (UTC) X-FDA: 76772027094.16.drop95_127b6e1e9833e X-Spam-Summary: 2,0,0,664e2432a833f193,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3871:3872:3874:4321:5007:6119:6261:6653:7514:7903:9413:10004:11026:11658:11914:12043:12114:12296:12297:12438:12517:12519:12555:12895:12986:14096:14181:14394:14687:14721:21080:21324:21444:21451:21611:21627:21666:21990:30029:30054:30064:30070,0,RBL:209.85.214.195:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: drop95_127b6e1e9833e X-Filterd-Recvd-Size: 5365 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Sat, 2 May 2020 14:35:26 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id b6so1525230plz.13 for ; Sat, 02 May 2020 07:35:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8kpZT85vHMPDfoRsJVsBli9cXP+dX02wUdHl/wOww2M=; b=YQXECGzklur8JPV/Im0glT4lEE0ExOP0qehaqsh8l2SgSyOPHVq81hT+VxxLafAmrU Ynsw4UFd0+RQMO0OHVBaV2PDhH0zJ+0jnyEpOZ3knlwfbdpTpBlr9CvcIU2Rgxd7gk+6 GtPNR3rjyNwRxMXtgvTNk8/lc0e9thJDjIC85s27zL1D4rvJ6bAYWc9MvuPVe6BTV7OQ W57eER7uxt7RlunEbgq6zULF/KEXTdIqgmv+15sGD8czRw0XPDooiWF1Q31zQlJBEbgV 2OYJC29eyHbF4liFZqVf4Xnd113vQDSIlQtG+8R6WX4lM3jrXcwoyDuT0d51SlyW5l1W /aZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8kpZT85vHMPDfoRsJVsBli9cXP+dX02wUdHl/wOww2M=; b=UMtY9rDtGnrWkaxMmSJwZHpo/ua6o2MSnupZVsc7IHQqsQwI7fea4aUEh1O+3h5ryw wuQS9srjkgeW94hnqEB/gs5A5NMEqbk3JOAtTyDx5qKILvJeUFyNYUAMzkgC7r571evM bCbCB43zI6UYbD7O9vTSxRFr5wkLOJ/t200H46ltpBjbHEOvr9/aXPpx1CaZm4mieLrn KRgTYMItnrvV1R5mt7mj5v/kfGbB9BT98sMtGavbP2C91MIDOhTXS9wdDRJ91fxoIT3b MiA58ALGeOvKiKvbUm7n3grGIvHwgVc+g0U3zsFVWnXMCkGj2G6+G3g1fKYDVwYGaYMp 3yqg== X-Gm-Message-State: AGi0PuZmVka4qoywy1Lowgv6g//a8lEJhEHmguy6bNYXPWqVO8uLHWX1 QX8aH3Ruk7xk6oCYN2oZ0Kk= X-Google-Smtp-Source: APiQypIP+ZQBo6IluNTEUDHzGx0mAeR2wBAwWLJDoIKVu5u0nJIcv9su88pyzsCs+l2IZZLP6gnlew== X-Received: by 2002:a17:90a:362f:: with SMTP id s44mr6055660pjb.156.1588430125996; Sat, 02 May 2020 07:35:25 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id o10sm4244867pgb.78.2020.05.02.07.35.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 07:35:25 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: shakeelb@google.com, hannes@cmpxchg.org, mhocko@kernel.org, guro@fb.com, gthelen@google.com, linux-mm@kvack.org, Yafang Shao Subject: [PATCH 1/2] mm, memcg: better name mem_cgroup_out_of_memory() Date: Sat, 2 May 2020 10:34:51 -0400 Message-Id: <20200502143452.7640-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200502143452.7640-1-laoar.shao@gmail.com> References: <20200502143452.7640-1-laoar.shao@gmail.com> 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: Rename mem_cgroup_out_of_memory() to mem_cgroup_oom_kill() to indicate that this function is used to try to kill a process. With this change it will cooperate better with the oom events. function memcg event mem_cgroup_oom() oom mem_cgroup_oom_kill() oom_kill Cc: Shakeel Butt Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Greg Thelen Signed-off-by: Yafang Shao Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5beea03dd58a..985edce98491 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1570,7 +1570,7 @@ unsigned long mem_cgroup_size(struct mem_cgroup *memcg) return page_counter_read(&memcg->memory); } -static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, +static bool mem_cgroup_oom_kill(struct mem_cgroup *memcg, gfp_t gfp_mask, int order) { struct oom_control oc = { @@ -1799,7 +1799,7 @@ static enum oom_status mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int * relying on the oom victim to make a forward progress and we can * invoke the oom killer here. * - * Please note that mem_cgroup_out_of_memory might fail to find a + * Please note that mem_cgroup_oom_kill might fail to find a * victim and then we have to bail out from the charge path. */ if (memcg->oom_kill_disable) { @@ -1821,7 +1821,7 @@ static enum oom_status mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int mem_cgroup_oom_notify(memcg); mem_cgroup_unmark_under_oom(memcg); - if (mem_cgroup_out_of_memory(memcg, mask, order)) + if (mem_cgroup_oom_kill(memcg, mask, order)) ret = OOM_SUCCESS; else ret = OOM_FAILED; @@ -1879,7 +1879,7 @@ bool mem_cgroup_oom_synchronize(bool handle) if (locked && !memcg->oom_kill_disable) { mem_cgroup_unmark_under_oom(memcg); finish_wait(&memcg_oom_waitq, &owait.wait); - mem_cgroup_out_of_memory(memcg, current->memcg_oom_gfp_mask, + mem_cgroup_oom_kill(memcg, current->memcg_oom_gfp_mask, current->memcg_oom_order); } else { schedule(); @@ -6102,7 +6102,7 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, } memcg_memory_event(memcg, MEMCG_OOM); - if (!mem_cgroup_out_of_memory(memcg, GFP_KERNEL, 0)) + if (!mem_cgroup_oom_kill(memcg, GFP_KERNEL, 0)) break; } From patchwork Sat May 2 14:34:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11523943 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 76B4A81 for ; Sat, 2 May 2020 14:35:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 39D1720661 for ; Sat, 2 May 2020 14:35:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="a1AC3nLS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39D1720661 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 69D908E0007; Sat, 2 May 2020 10:35:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 64D6E8E0001; Sat, 2 May 2020 10:35:31 -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 515468E0007; Sat, 2 May 2020 10:35:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0027.hostedemail.com [216.40.44.27]) by kanga.kvack.org (Postfix) with ESMTP id 38B428E0001 for ; Sat, 2 May 2020 10:35:31 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DFF42180AD806 for ; Sat, 2 May 2020 14:35:30 +0000 (UTC) X-FDA: 76772027220.01.cause07_1304310e8181f X-Spam-Summary: 2,0,0,3d54bc95520c565a,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6119:6120:6261:6653:7514:7901:7903:9413:10004:11026:11473:11658:11914:12043:12050:12296:12297:12517:12519:12555:12895:13180:13229:14096:14181:14394:14687:14721:21080:21324:21444:21451:21611:21627:21666:30046:30054:30064,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: cause07_1304310e8181f X-Filterd-Recvd-Size: 4845 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Sat, 2 May 2020 14:35:30 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id t7so4816536plr.0 for ; Sat, 02 May 2020 07:35:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xVaHHjYy0KbdaqxIhMw12L7E8tkCYxEQsjdY5ahzOZg=; b=a1AC3nLSjYwRNmWDcjtIIDEErDnR9rjucXgj3zqtGbeJkmsTmsJbcAIfLEi/661NZd rfDmogP/amS1xQjAV+51A7x06zcNzxhg1oZ4/8lK3UWOWUuAfn9+mMmj5dqMP8pzCU8B fFzi105kWHC9arSI+BrRp40s/pPuneMkEo9uAWf2q7SdIgMG3s8sTnnZcYMIScKT5bO2 dNxrC9+FxXQbdUxLiX12UdCETnXRydAnH5eR5n2Z90fBVhoSSk6DlDQVcDgRRLASDhkK S6KFdzzbLlMp9LDzARRXzyqOcdZl7+s+Ax0j6i7dl/yCKqdPKDTcT0jwhisuRJTmdZiF qurA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xVaHHjYy0KbdaqxIhMw12L7E8tkCYxEQsjdY5ahzOZg=; b=sbew+/R/1D0vX4v1WRDTojnvkDadsJfFNQeEqcx5mUso0DgZNKlr3wgxKdmjw04U1O zfeNXeSVD4+o6t1oX54BPh17VvZ7R9MkO6gF9W02sYyvlkoJ/Ixd6Ya2YmH3UPtgYl92 Zkp+hsbulhqSrIhzKtaVtoknlry8UIOo04vYqsHA+Rus3xnwMF5PvWqBGeGkbtqsixxt KXVjH/QCzUuaZI+DlgsBlmYQ8iAy05BBtmBBXsMXyw5rrstKkzqknyCXhMoYHSRC91fY uEt5z+pgRvsH/cd9jAf5+eICbhOlpLlTcSeaGYuu6m3lXXJzt+RaawJ9WHLFznO5yflJ Xtvw== X-Gm-Message-State: AGi0PuZYpnHJZap7KFdHFaPdwVgdr1gCiFhQEPF6L5vnk5iuYR2udhXe WRtjho78nGzr3HP4vc5ng5U= X-Google-Smtp-Source: APiQypJvxZnbHVZKrK1+/kmlZqEWO25l6KtzJQ7NnyTZATfqx7DdspReaMw23VXfUP5CESvwOWeAQA== X-Received: by 2002:a17:902:b609:: with SMTP id b9mr9525071pls.156.1588430129868; Sat, 02 May 2020 07:35:29 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id o10sm4244867pgb.78.2020.05.02.07.35.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 May 2020 07:35:29 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org Cc: shakeelb@google.com, hannes@cmpxchg.org, mhocko@kernel.org, guro@fb.com, gthelen@google.com, linux-mm@kvack.org, Yafang Shao Subject: [PATCH 2/2] mm, memcg: don't try to kill a process if memcg is not populated Date: Sat, 2 May 2020 10:34:52 -0400 Message-Id: <20200502143452.7640-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200502143452.7640-1-laoar.shao@gmail.com> References: <20200502143452.7640-1-laoar.shao@gmail.com> 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: Recently Shakeel reported a issue which also confused me serveral months earlier. Bellow is his report - Lowering memory.max can trigger an oom-kill if the reclaim does not succeed. However if oom-killer does not find a process for killing, it dumps a lot of warnings. Deleting a memcg does not reclaim memory from it and the memory can linger till there is a memory pressure. One normal way to proactively reclaim such memory is to set memory.max to 0 just before deleting the memcg. However if some of the memcg's memory is pinned by others, this operation can trigger an oom-kill without any process and thus can log a lot un-needed warnings. So, ignore all such warnings from memory.max. [shakeelb@google.com: commit log above] A better way to avoid this issue is to avoid trying to kill a process if memcg is not populated. Note that OOM is different with OOM kill. OOM is a status that the system or memcg is out of memory, while OOM kill is a result that a process inside this memcg is killed when this memcg is in OOM status. That is the same reason why there're both MEMCG_OOM event and MEMCG_OOM_KILL event. If we have already known that there's nothing to kill, i.e. the memcg is not populated, then we don't need to have a try. Cc: Shakeel Butt Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Greg Thelen Signed-off-by: Yafang Shao Reviewed-by: Shakeel Butt --- mm/memcontrol.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 985edce98491..29afe3df9d98 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6102,6 +6102,10 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, } memcg_memory_event(memcg, MEMCG_OOM); + + if (!cgroup_is_populated(memcg->css.cgroup)) + break; + if (!mem_cgroup_oom_kill(memcg, GFP_KERNEL, 0)) break; }