From patchwork Tue Nov 26 13:02:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11262183 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 0F6546C1 for ; Tue, 26 Nov 2019 13:03:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D11042073F for ; Tue, 26 Nov 2019 13:03:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="le6fdnu9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D11042073F 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 DF5F96B030B; Tue, 26 Nov 2019 08:03:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA6916B030C; Tue, 26 Nov 2019 08:03:01 -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 CE3496B030D; Tue, 26 Nov 2019 08:03:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0201.hostedemail.com [216.40.44.201]) by kanga.kvack.org (Postfix) with ESMTP id B55076B030B for ; Tue, 26 Nov 2019 08:03:01 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 622B0180AD81A for ; Tue, 26 Nov 2019 13:03:01 +0000 (UTC) X-FDA: 76198443762.27.page69_375c7dee53713 X-Spam-Summary: 2,0,0,6a8b6145d8d566fd,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:1534:1542:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2898:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6261:6653:7514:7903:9413:10004:11026:11658:11914:12043:12048:12295:12297:12438:12517:12519:12555:12679:12895:12986:13161:13229:14093:14096:14181:14394:14687:14721:21080:21444:21451:21627:21666:30054:30070:30090,0,RBL:209.85.210.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:neutral,Custom_rules:0:0:0,LFtime:29,LUA_SUMMARY:none X-HE-Tag: page69_375c7dee53713 X-Filterd-Recvd-Size: 4786 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Nov 2019 13:03:00 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id q13so9170968pff.2 for ; Tue, 26 Nov 2019 05:03:00 -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=U7tAtOwoR8CRCw+WNT8vas5qFdi67LKYxUF4m/37Wro=; b=le6fdnu9bT2gIrp2HsXg/KujSXo3oPP4jkhjxYLV0BoP9dY+ihXgvrRrWIRZtj8phY akGRbNUetpyuu6qgqCVCovwoxYeOR9Y9sqOMB/h4PvURhagi8w9BGACgqrzPlXgG0dFH +dS1PEqlkZXousbOAj0rHAZe/6qpXQwiVoI11LmtxXj51W0nLJ1+1LkcX/VbaCb9Ltg0 yI2Ffy3sQY6bJvs4nwjJX7hQBgWV4LwXbj6y+9JSAL2b9BBX+JVJ56+i+e6r7QpOlo6x t1uNKgEY/reOV57iTTciKzFLnkeegC6JyWuq0vVFpXOjbD5wScoWHyNOrafCjcaCXP8T HRlg== 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=U7tAtOwoR8CRCw+WNT8vas5qFdi67LKYxUF4m/37Wro=; b=oZAr97/6vLHg42aN8C3SgT8dUEOjAvCHLJ+sTJN/bDWKEGmXFqqBuOlvJi0MxWVKRT z2vZ4Kr892HOe4uxL3mhsUbw5XCubroQAKbzyfscYTss0R2VOFlHGc13C64Dqi/Ze7qp rsIqHBxyKhNF7i/8+Du17jwpnu3cRdvjAsA4axJfxKIHBuuFt4HALktS9N6GZiPVcBBx d46F/b3D4qPZtuO5idgOdzTx5WJ119VdsqXhawQtirubXa8q/2p14TwL3cLGafBVvel/ bEEO06simgUU+NIgD6lKVXm9CNbcKVKWIh7CERFuRVudIw4eoJDo1qUmcjSDMMCsQYE/ HC+A== X-Gm-Message-State: APjAAAXqbOJflR1KUWrlf6yydn3WDp3KP7K+duyweHTV3cxT48vQXt3R EQyP9qHLosFoGVqlT+BZ79I= X-Google-Smtp-Source: APXvYqxlS77nRclSs8qU4Mex/9QWLnDogkLA3teujAedgeAXOb4voNN/o7YtSQ3YXzJxMQse6gpM3A== X-Received: by 2002:a62:545:: with SMTP id 66mr40416679pff.1.1574773379307; Tue, 26 Nov 2019 05:02:59 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id r16sm12681664pgl.77.2019.11.26.05.02.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Nov 2019 05:02:58 -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] mm, memcg: avoid oom if cgroup is not populated Date: Tue, 26 Nov 2019 08:02:49 -0500 Message-Id: <1574773369-1634-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 misleading outputs, that should not happen. One misleading output is "Out of memory and no killable processes...", while really there is no tasks rather than no killable tasks. Furthermore, the OOM output is not expected by the admin if he or she only wants to drop the cahes and knows there're no processes running in this memcg. If memcg is not populated, we should not invoke the OOM killer. 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 --- mm/memcontrol.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1c4c08b..4e08905 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6139,9 +6139,13 @@ 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 (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);