From patchwork Mon May 4 04:26:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11524965 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 197DF1668 for ; Mon, 4 May 2020 04:26:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D919B20757 for ; Mon, 4 May 2020 04:26:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nlq6B0Ap" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D919B20757 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 17E6D8E0006; Mon, 4 May 2020 00:26:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 106178E0001; Mon, 4 May 2020 00:26:48 -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 01ACB8E0006; Mon, 4 May 2020 00:26:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0180.hostedemail.com [216.40.44.180]) by kanga.kvack.org (Postfix) with ESMTP id DEC128E0001 for ; Mon, 4 May 2020 00:26:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 95EC1181AEF30 for ; Mon, 4 May 2020 04:26:47 +0000 (UTC) X-FDA: 76777750854.05.help61_3b4583d2ad01c X-Spam-Summary: 2,0,0,b94106e0aebdf24b,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:30054:30064:30070,0,RBL:209.85.215.194:@gmail.com:.lbl8.mailshell.net-62.18.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: help61_3b4583d2ad01c X-Filterd-Recvd-Size: 5372 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 04:26:47 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id s18so7934268pgl.12 for ; Sun, 03 May 2020 21:26:47 -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=9lsThybE4FRTDd9m0A2GYoDH2L3an0/u0abVreqH5Bs=; b=nlq6B0ApnFTiQ0Nd1f02SEyt3vqAoHDPZzX1yYgqoumr7YgVtO5c+E3WtQg4yXpejY W6y1Wtiz0qlzuODzGPbvTCVsF9qDpd6hI7TTKeT+ByDjYdyW1Kxu7aFe7abBqJNcruAl jDv6UEKZlwedLMMGkFS8CK5rWHVBIlMHIvEJDzoxlf830eFz922nvY+8X/0YpMpxORB+ eRXan5FLj0yNa2B/KOpdCnExcHfv4kqcWr2Hdn4SYnPw0v2Uo9a4EWcFx3bMVt6Zja/K dWYanr1LYmZko2rZ8Ibl5U5gL38uKVS+2e7gHpLXK/dwbRaK1hzTx3SJ26pSciNrjJdL /ZAw== 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=9lsThybE4FRTDd9m0A2GYoDH2L3an0/u0abVreqH5Bs=; b=LCTXuWn0pioT2alh94dpdZH9WA7dBHUeTG7ArJ0UIKUi+5FWIyOQM97dJm7eOjTlnW je2Jx1Fuokf0vKXeWy0EY1h2M18PVQsg6a7fq+qWvL4GcRsR2oZStbYoSWiwWKwLZBe6 7C5crcZ7h3Ekv+OeNuT+suNpZ6sEq/hZlUjB+ADOF+wPMVibOiI4lCWfwe7kfN0QgKWv kibKazUUOdhEZuIobLmHpn40bMovUEECizkgcp+NkN+i4K7ceBCKfr3xy0XesjWCjhQR B3PAIK8Hdo8k7Bl2i0j/jBKxismGTkF6o0afbs/0ZIJPvgWYnflUmoCT3EM/7uBhn7g4 ZvfQ== X-Gm-Message-State: AGi0PuawUWx52KT9vWbUjrjIOF7uY1DGv15E5EIPD/CmrEuQRH6e+/2a zCz758SPZ4Kdc5h99z8RnlU= X-Google-Smtp-Source: APiQypK8hcT8r3pLPlZCLzA3wyR9bFA54Whmk0pVnC1k3MMj+hISdMVekqaYYyyrMQ0YSc906Jy79g== X-Received: by 2002:a63:d40a:: with SMTP id a10mr15117861pgh.71.1588566406411; Sun, 03 May 2020 21:26:46 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id y8sm8012878pfg.216.2020.05.03.21.26.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 21:26:45 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, shakeelb@google.com Cc: hannes@cmpxchg.org, mhocko@kernel.org, guro@fb.com, gthelen@google.com, linux-mm@kvack.org, Yafang Shao Subject: [PATCH v2 1/2] mm, memcg: rename mem_cgroup_out_of_memory() Date: Mon, 4 May 2020 00:26:20 -0400 Message-Id: <20200504042621.10334-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200504042621.10334-1-laoar.shao@gmail.com> References: <20200504042621.10334-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 Signed-off-by: Yafang Shao Reviewed-by: Shakeel Butt Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Greg Thelen --- 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 Mon May 4 04:26:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11524967 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 EF58C17E8 for ; Mon, 4 May 2020 04:26:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BC51620757 for ; Mon, 4 May 2020 04:26:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bicGSkaX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC51620757 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 F121A8E0007; Mon, 4 May 2020 00:26:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EC1858E0001; Mon, 4 May 2020 00:26:51 -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 DB0448E0007; Mon, 4 May 2020 00:26:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0249.hostedemail.com [216.40.44.249]) by kanga.kvack.org (Postfix) with ESMTP id C467C8E0001 for ; Mon, 4 May 2020 00:26:51 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 907818249980 for ; Mon, 4 May 2020 04:26:51 +0000 (UTC) X-FDA: 76777751022.30.tramp90_3bd97a5d75208 X-Spam-Summary: 2,0,0,80c90b0e187a95cd,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:2393:2559:2562:3138:3139:3140:3141:3142:3354: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:14181:14394:14687:14721:21080:21324:21444:21451:21611:21627:21666:21740: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: tramp90_3bd97a5d75208 X-Filterd-Recvd-Size: 5077 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf40.hostedemail.com (Postfix) with ESMTP for ; Mon, 4 May 2020 04:26:51 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id u22so6295980plq.12 for ; Sun, 03 May 2020 21:26:51 -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=fVWtUjOUApdXkRnNhxOexL1wsSeAV1kQtINnrlYuC98=; b=bicGSkaX3QEyGk2Gq/NpCiq0sQFgEWYieLT707Ymb02RMO8j2lqKZ+5CSoTJ1Msii6 11d5KhQxwcwoQ1FjTECxZqTKLKx2wNIgDxSkpqR9Pz+fB0946lF4mJnrEYUOnTtLSnAW hvRqpN2E/ovvT/2cVz+q0G5mQ1UOxrLieoKzmrxRDUZA9CT6eGNJoaTlY2PPEKxpfDaK NtiolAHhrkZ/nlaG3yNVyD+WMg8CPfBLgs8wmB1GnBDWG+scjVjEWLTj0lGXeyOQvTNE r4IX1wntC+Zcouqz+dBYz6FdZtU/1+hNmoVxEtcTYiDT/b8ic1BV/uZKIi+LEbWEYl95 EBOQ== 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=fVWtUjOUApdXkRnNhxOexL1wsSeAV1kQtINnrlYuC98=; b=XQpI1WQPGqaS2okyby2EUmOa/MR1pM/OyqAzmlHiEya/P2evwUTuE7By1xmgYvyizx xO+kJB+RZhpuKh/LwZziaJrzCMhrzJL9+6MDHjYvj67uNGhY6eTKvd1mUIvQFvsC0z+C gaE25UvwFguTo1Wa/q8mbeLclD39NpRprTa29J0FFoMd5Qg5khH29J7SvLNNWA+mfkb1 4JmIvn9L8ySEeh4oykU6NA/aITQn9hNXWFt1CoFcFy50XkPOfSn65z9yic/MCLU5SFyD C5qYG2PdGjj60vNud0HUs0yvwkkTSmomIh5EKTD35x6barfIaobxGwgnbew1akuLnsta cx4A== X-Gm-Message-State: AGi0PuY/vfyU1OfliUx2bp0KHzEQXT2wZacumfel93jH4hOo8XBk4r/v nmnOK6l3NJKkqn3bj/soo8Q= X-Google-Smtp-Source: APiQypJPxc3MEzM+mhfNsR7AOqVfopAxbB+xTulcBBuT1VQ7W3RjyaiH5mqXLTIZYl4ioCM2ChuTgQ== X-Received: by 2002:a17:902:8a81:: with SMTP id p1mr8670524plo.104.1588566410215; Sun, 03 May 2020 21:26:50 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id y8sm8012878pfg.216.2020.05.03.21.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 May 2020 21:26:49 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, shakeelb@google.com Cc: hannes@cmpxchg.org, mhocko@kernel.org, guro@fb.com, gthelen@google.com, linux-mm@kvack.org, Yafang Shao Subject: [PATCH v2 2/2] mm, memcg: don't try to kill a process if memcg is not populated Date: Mon, 4 May 2020 00:26:21 -0400 Message-Id: <20200504042621.10334-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200504042621.10334-1-laoar.shao@gmail.com> References: <20200504042621.10334-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 several 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 of un-needed warnings. So, ignore all such warnings from memory.max. 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 from 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 a try. Basically why setting memory.max to 0 is better than setting memory.high to 0 before deletion. The reason is remote charging. High reclaim does not work for remote memcg and the usage can go till max or global pressure. [shakeelb@google.com: improve commit log] Signed-off-by: Yafang Shao Reviewed-by: Shakeel Butt Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Greg Thelen --- 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; }