From patchwork Fri Dec 27 12:43:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11311145 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 221D06C1 for ; Fri, 27 Dec 2019 12:44:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E1B04208C4 for ; Fri, 27 Dec 2019 12:44:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MClM5SS7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1B04208C4 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 1F2C88E0006; Fri, 27 Dec 2019 07:44:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 17E388E0001; Fri, 27 Dec 2019 07:44:18 -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 01D948E0006; Fri, 27 Dec 2019 07:44:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0004.hostedemail.com [216.40.44.4]) by kanga.kvack.org (Postfix) with ESMTP id DE3168E0001 for ; Fri, 27 Dec 2019 07:44:17 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 775D88249980 for ; Fri, 27 Dec 2019 12:44:17 +0000 (UTC) X-FDA: 76310889354.21.blood12_5f9de1abb2a45 X-Spam-Summary: 2,0,0,779b2fc820efe5e1,d41d8cd98f00b204,laoar.shao@gmail.com,:guro@fb.com:hannes@cmpxchg.org:mhocko@kernel.org:vdavydov.dev@gmail.com:akpm@linux-foundation.org::laoar.shao@gmail.com:chris@chrisdown.name:stable@vger.kernel.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359: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: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:13161:13229:14096:14181:14394:14687:14721:21080:21444:21451:21627:21666:21990:30054:30064:30070:30090,0,RBL:209.85.216.68:@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:27,LUA_SUMMARY:none X-HE-Tag: blood12_5f9de1abb2a45 X-Filterd-Recvd-Size: 4949 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Dec 2019 12:44:16 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id kx11so4696157pjb.4 for ; Fri, 27 Dec 2019 04:44:17 -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:in-reply-to:references; bh=n+mXUnSBdUmpj+rPxKhgXq+NePAWLTnS1N3EeApr+XU=; b=MClM5SS7oF7CHekECq80qPRhE7p20RkNMF9ENF0twOArz78T0bPiy1T+Wad1Pe57yV dVtWTNHYbEqKmd2k31Okt4zhDIvhG6rIKBexkC4+bbnFIpGgsuFgMffbDT88omSusPNk myDvOHwO+d8TuGbY+A7gBYVha8NY1PRYpiGJ3taTTn+ibKucAerEIfct+2JdY2OVDefj rJhOxatKXAfy9mb8wuyETiK9hZTvSrYzInH7Lbpqt9H3iu8ea1klZI9WdemZHuXdwzyG RGXWPggybOWr65DwbqFv65FlY2oKyzPQbDnKcM4SICDzvb8JGVKU9k1kyMmigRL3UnQR 7a5g== 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=n+mXUnSBdUmpj+rPxKhgXq+NePAWLTnS1N3EeApr+XU=; b=mztSLNI+frYmwroOYZR1mqDKhq5hiafTVxw7cb6+r0BWYeTvkduVSliWtYzk/PUd4U o2nv1ENUa2lo3rhIOTBW9KBbv+VdasBPHUJrG9Bd/91A20sVizh/IijS1ExxJd+vivQ2 UetXMZQvnAGpcNT9UTzeda7GDltjZLBuXTbzxNP/+h5obvpK15AGOwRqGkpZmqb0RsSa gVzjpJ4QXqiT8LDa64EkPb618xv4WWQlJAx3tEU5uH/3lrXy3sJ2q249QuugTuAz/8TC MEk4VPYrVbgcYBk3/i9Vjze9MhFy16iHJQjABiLmlROgfOy3HL6brgVFUURgBhxkxyXI 9WyQ== X-Gm-Message-State: APjAAAUfmVDvBPaFnNjpcVtNvk5l65xHL/mCfi5J7l2rIo3x5BM9Znux cqgQjby4CB19Kb4lhWZ6Fco= X-Google-Smtp-Source: APXvYqwgKLBTx3Hcbrh/WHlWE/LXA4+A1BPxsuTm/PkYpjc0qumV0yS72w7efbXfZQ5HQDicNLxrAQ== X-Received: by 2002:a17:902:241:: with SMTP id 59mr17878300plc.36.1577450655997; Fri, 27 Dec 2019 04:44:15 -0800 (PST) Received: from dev.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id c2sm14125591pjq.27.2019.12.27.04.44.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Dec 2019 04:44:15 -0800 (PST) From: Yafang Shao To: guro@fb.com, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao , Chris Down , stable@vger.kernel.org Subject: [PATCH] mm, memcg: reset memcg's memory.{min, low} for reclaiming itself Date: Fri, 27 Dec 2019 07:43:53 -0500 Message-Id: <1577450633-2098-2-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1577450633-2098-1-git-send-email-laoar.shao@gmail.com> References: <1577450633-2098-1-git-send-email-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: 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 Cc: Chris Down Cc: Roman Gushchin Cc: stable@vger.kernel.org Acked-by: Roman Gushchin --- mm/memcontrol.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 601405b..bb3925d 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6287,8 +6287,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)