From patchwork Sun Feb 16 14:52:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11384453 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 8B4F2138D for ; Sun, 16 Feb 2020 14:53:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4D8CD2086A for ; Sun, 16 Feb 2020 14:53:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Oll20V6l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D8CD2086A 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 4EBF96B0003; Sun, 16 Feb 2020 09:53:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 49B9B6B0006; Sun, 16 Feb 2020 09:53:04 -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 3642E6B0007; Sun, 16 Feb 2020 09:53:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id 1DB0C6B0003 for ; Sun, 16 Feb 2020 09:53:04 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C8EE68248047 for ; Sun, 16 Feb 2020 14:53:03 +0000 (UTC) X-FDA: 76496282646.24.page10_7203933bbac02 X-Spam-Summary: 2,0,0,5a14a78f1e0b6f76,d41d8cd98f00b204,laoar.shao@gmail.com,:guro@fb.com:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org:chris@chrisdown.name::laoar.shao@gmail.com:stable@vger.kernel.org,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:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:4605:5007:6119:6261:6653:7514:7903:8784:9413:10004:10249:11026:11473:11658:11914:12043:12048:12296:12297:12438:12517:12519:12555:12679:12895:12986:13161:13229:14096:14181:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054:30064: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:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: page10_7203933bbac02 X-Filterd-Recvd-Size: 4792 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Sun, 16 Feb 2020 14:53:03 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id b22so5679459pls.12 for ; Sun, 16 Feb 2020 06:53:03 -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=uTrfCCTzwmDGorzNe6SDOvqoePQqHhkw4MOPZZ+3oow=; b=Oll20V6ldVBPGVrKV3WkA5Tqj1qlmz4EaNLvHBZdUwjwKAgzsHYy/OLmp9/p0rMXuV tLhBzl5x9DvL2HeVLPWV8OWN/ORwuSZBcITQ/n1jKOw634lHaWx0zlBR7KsCAfx1Gx2n nKV/Favxc52Qj7tNHa4kEue/UcbRRctl5D3CNe3hpYaPVDUhKeJRqQBCj42cq/WtGh41 C103WrkvOk77Vvvntb08QNeu2LQFbXoeoNfLzxIX7x/51mRO6RIOPCgbgM8Mgu/Ib2Ya evoazV2qi/Sne/mlqQtwa4PmoMVUhEZ+Q99jdzvYpS+cqSYDO6dt448yJVsUQyZSGLUO wbNA== 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=uTrfCCTzwmDGorzNe6SDOvqoePQqHhkw4MOPZZ+3oow=; b=PmzhIC8MzGFCoT6oGPOOxU8zmgnAMBD3oAJEDdLEjtl4PYdbVTCJ09GB2TwzhWry0Q iAw6qQptK23k83bLy0ozBF8E0PnEmer1beLMfLKnYye/2gGhLNJdWFDlzjbsEQwJzl5O +oCRnUgISkuZ4ri8QE4V3lXaLUvQnvpPe5PuuDPm4hyXUPdBd6ioRKPyTTKBKT21VqiG 9KKzTt8Xdx587xwchkyZlCL0/Eg0wbd51HrCBPrbDtIAowgCdXzMrK/wvI7jDNP/fCKT fN6gWGE8oIFycNsJIaD29ZUZae3+vnusyPN6mH8H/Esjrp0Myds3JMguLsxu+VyD6HM1 uqvQ== X-Gm-Message-State: APjAAAWlyDj0ekdX+mWlveC5ztRvkhvsQhiHYkkWRgiPr3TxIROiSmvy ObJicENh6QMvn0R2X1C3Blw= X-Google-Smtp-Source: APXvYqw+5h9pi+c9mHEM/Eva36Sgq5EJjrRx1Qg0lPWybD+CfFuEWt2rcDr2OR591D4J+5bPwu6+eg== X-Received: by 2002:a17:90a:bf81:: with SMTP id d1mr14651583pjs.21.1581864782138; Sun, 16 Feb 2020 06:53:02 -0800 (PST) Received: from snappy-silo-1.localdomain (107.182.183.158.16clouds.com. [107.182.183.158]) by smtp.gmail.com with ESMTPSA id x25sm13471428pfp.30.2020.02.16.06.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Feb 2020 06:53:01 -0800 (PST) From: Yafang Shao To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, chris@chrisdown.name Cc: linux-mm@kvack.org, Yafang Shao , stable@vger.kernel.org Subject: [PATCH resend] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself Date: Sun, 16 Feb 2020 09:52:49 -0500 Message-Id: <20200216145249.6900-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.2 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: memory.{emin, elow} are set in mem_cgroup_protected(), and the values of them won't be changed until next recalculation in this function. After either or both of them are set, the next reclaimer to relcaim this memcg may be a different reclaimer, e.g. this memcg is also the root memcg of the new reclaimer, and then in mem_cgroup_protection() in get_scan_count() the old values of them will be used to calculate scan count, that is not proper. We should reset them to zero in this case. Here's an example of this issue. root_mem_cgroup / A memory.max=1024M memory.min=512M memory.current=800M Once kswapd is waked up, it will try to scan all MEMCGs, including this A, and it will assign memory.emin of A with 512M. After that, A may reach its hard limit(memory.max), and then it will do memcg reclaim. Because A is the root of this reclaimer, so it will not calculate its memory.emin. So the memory.emin is the old value 512M, and then this old value will be used in mem_cgroup_protection() in get_scan_count() to get the scan count. That is not proper. Fixes: 9783aa9917f8 ("mm, memcg: proportional memory.{low,min} reclaim") Signed-off-by: Yafang Shao Acked-by: Roman Gushchin Cc: Chris Down Cc: stable@vger.kernel.org --- mm/memcontrol.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 6f6dc8712e39..df7fedbfc211 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6250,8 +6250,17 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (!root) root = root_mem_cgroup; - if (memcg == root) + if (memcg == root) { + /* + * Reset memory.(emin, elow) for reclaiming the memcg + * itself. + */ + if (memcg != root_mem_cgroup) { + memcg->memory.emin = 0; + memcg->memory.elow = 0; + } return MEMCG_PROT_NONE; + } usage = page_counter_read(&memcg->memory); if (!usage)