From patchwork Wed Nov 27 01:28:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11263205 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 C3AD7138C for ; Wed, 27 Nov 2019 01:29:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 84FDE2071E for ; Wed, 27 Nov 2019 01:29:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JEwC+q4t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 84FDE2071E 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 A8DD06B0344; Tue, 26 Nov 2019 20:29:24 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A17206B0345; Tue, 26 Nov 2019 20:29:24 -0500 (EST) 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 8B9F76B0346; Tue, 26 Nov 2019 20:29:24 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id 6FB646B0344 for ; Tue, 26 Nov 2019 20:29:24 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with SMTP id 2EDDB4DD4 for ; Wed, 27 Nov 2019 01:29:24 +0000 (UTC) X-FDA: 76200324648.16.fruit99_17d6cf0567102 X-Spam-Summary: 2,0,0,ad9d4a2a0d781eee,d41d8cd98f00b204,laoar.shao@gmail.com,:mhocko@kernel.org:hannes@cmpxchg.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org::laoar.shao@gmail.com:mhocko@suse.com,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1437:1535:1542:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2898:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:5007:6119:6261:6653:7514:7903:9413:10004:11026:11658:11914:12043:12048:12295:12297:12438:12517:12519:12555:12679:12895:13161:13229:14093:14096:14181:14394:14687:14721:21080:21444:21451:21627:21666:30054:30070:30090,0,RBL:209.85.214.194:@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:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: fruit99_17d6cf0567102 X-Filterd-Recvd-Size: 5267 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Nov 2019 01:29:23 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id o8so4631852pls.5 for ; Tue, 26 Nov 2019 17:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=glaN9QxxklXXKv06RuBB94JPFxGeikm81JOcQdkWuOA=; b=JEwC+q4tAJWuNQ8mgwcauDhs44erZhgEAnPmKOy2HhiWbWrdhxUrlKv8tneHqf7YLg UaEiNulmVZ7Ngm1zVaBfTxtlHCxMJylk9kmQxpdUyZDSaD+riw88lCLPRfBHBd3hkctb KSnYVJHzxv/tIWzEvTfL3KdssrEsS10UujfhizNczHt8NBW5tFX6iSxhwPxJBlLrohSw Lyx6ZexDpHQYZLqXwGpwHCg72Y6ee/mNMT6PXFGPZK3YIn8NEwwwkFU2+wsQfYOP12tG sDcfWFBCPhk0sIiHW7gc5MY2sXWdRSA6Z3t/4CVLtTTnvppeTvF9mxcRj7G1WOb7Bigd DrYw== 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; bh=glaN9QxxklXXKv06RuBB94JPFxGeikm81JOcQdkWuOA=; b=X5ZhXZa1J0lRwnJbZj7npOSVh2aD+pDsFETeliBsMvAFQPuR09Z7IVhCeJRQbtkBNT WPqtkJtNO6csvKMxD85MlIoUTmP0eNA2VMjKNaRJvKXCDnZiiv2XUxcdnmF5HE/Pe4ut m2/gcJYywXaCTGYjaHHnT/A5wE7aaf/zU4wTiV8/KUOvhC4mJvXG9mFWvAiwxAS3CZ0v aXXgjqNWmW5FyPAl9pTJXeQDOT7OQruCpjcn4uJ9NYX+ssDlsFVZnltbGhCjF2VeGbEG tLVEvt6qam1APAgtlc/XwuENgjVrfp1/07TqovSO7B3ZgkaBtPO440NpsCxo+ontiwJr X71Q== X-Gm-Message-State: APjAAAWvbGoE3uxQJEAeruxGOYoTF/SA+8NY5hGNRpc+9jJrCeBzaEjc nynvGvsr14Ie2AJNJNS0B7U= X-Google-Smtp-Source: APXvYqzASwO2MR227wW6kdlTgfmAN4m72eL/weYtARuIq8ibKp3g15oVkxMD1QrB7GXDrziulDMuOw== X-Received: by 2002:a17:90a:5d0f:: with SMTP id s15mr2681525pji.63.1574818162448; Tue, 26 Nov 2019 17:29:22 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id c17sm13848752pfo.42.2019.11.26.17.29.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2019 17:29:21 -0800 (PST) From: Yafang Shao To: mhocko@kernel.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao , Michal Hocko Subject: [PATCH v2] mm, memcg: avoid oom if cgroup is not populated Date: Tue, 26 Nov 2019 20:28:37 -0500 Message-Id: <1574818117-2885-1-git-send-email-laoar.shao@gmail.com> 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: There's one case that the processes in a memcg are all exit (due to OOM group or some other reasons), but the file page caches are still exist. These file page caches may be protected by memory.min so can't be reclaimed. If we can't success to restart the processes in this memcg or don't want to make this memcg offline, then we want to drop the file page caches. The advantage of droping this file caches is it can avoid the reclaimer (either kswapd or direct) scanning and reclaiming pages from all memcgs exist in this system, because currently the reclaimer will fairly reclaim pages from all memcgs if the system is under memory pressure. The possible method to drop these file page caches is setting the hard limit of this memcg to 0. Unfortunately this may invoke the OOM killer and generates lots of outputs, that should not happen. The OOM output is not expected by the admin if he or she wants to drop the cahes and knows there're no processes in this memcg. If memcg is not populated, we should not invoke the OOM killer because there's nothing to kill. Next time when you start a new process and if the max is still bellow usage, the OOM killer will be invoked and your new process is killed, so we can cosider it as lazy OOM, that is we have been always doing in the kernel. Fixes: b6e6edcf ("mm: memcontrol: reclaim and OOM kill when shrinking memory.max below usage") Signed-off-by: Yafang Shao Cc: Johannes Weiner Cc: Michal Hocko Nacked-by: Michal Hocko --- mm/memcontrol.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1c4c08b..e936f1b 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6139,9 +6139,20 @@ static ssize_t memory_max_write(struct kernfs_open_file *of, continue; } - memcg_memory_event(memcg, MEMCG_OOM); - if (!mem_cgroup_out_of_memory(memcg, GFP_KERNEL, 0)) + /* If there's no procesess, we don't need to invoke the OOM + * killer. Then next time when you try to start a process + * in this memcg, the max may still bellow usage, and then + * this OOM killer will be invoked. This can be considered + * as lazy OOM, that is we have been always doing in the + * kernel. Pls. Michal, that is really consistency. + */ + if (cgroup_is_populated(memcg->css.cgroup)) { + memcg_memory_event(memcg, MEMCG_OOM); + if (!mem_cgroup_out_of_memory(memcg, GFP_KERNEL, 0)) + break; + } else { break; + } } memcg_wb_domain_size_changed(memcg);