From patchwork Sat Apr 25 15:24:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11509929 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 AA39392C for ; Sat, 25 Apr 2020 15:24:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6E0432071C for ; Sat, 25 Apr 2020 15:24:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ftH0fmku" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E0432071C 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 8D5A88E0007; Sat, 25 Apr 2020 11:24:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 860858E0003; Sat, 25 Apr 2020 11:24: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 728418E0007; Sat, 25 Apr 2020 11:24:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 5B3B88E0003 for ; Sat, 25 Apr 2020 11:24:51 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 20E5A52DA for ; Sat, 25 Apr 2020 15:24:51 +0000 (UTC) X-FDA: 76746749982.10.frog12_2a511e8117702 X-Spam-Summary: 2,0,0,9b46a8408205612d,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1543:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:2897:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:4117:4321:4605:5007:6261:6653:7514:7875:9040:9413:9592:10004:11026:11473:11658:11914:12043:12048:12114:12296:12297:12438:12517:12519:12555:12895:12986:13161:13229:13255:14096:14181:14394:14687:14721:21080:21433:21444:21451:21611:21627:21666:21966:21990:30029:30054:30064:30070,0,RBL:209.85.214.196:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.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: frog12_2a511e8117702 X-Filterd-Recvd-Size: 6805 Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Sat, 25 Apr 2020 15:24:50 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id c21so4096356plz.4 for ; Sat, 25 Apr 2020 08:24:50 -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=pIIMDjhMLcRChaSUZYCTVP34wxWwK/Ju/NQeogQ/s/E=; b=ftH0fmkumfxZJKFUC6+xH5qIRCn/TtGt57uhOFF/suuBQ6S1xdY3z6whaTjro569q9 jFIIx4LQHMGKBKpHDj+s7L2jmrT5nmZBtEPwPiij6hL6Kv5zKJADtdazklNhXr/lWIjn WhcJITZoIUZ0cYxY1E11Etsl9mXT2aRk3+BajRx1OobN6tdVyzAMoDg7S34xmlxYudpt uo/1L6HUTW6cdjEhosahtiwo+IWk+yHWn2evn3OXOjeAfcN86G6utVhGaNhoU/sGGeFG qy7fRYl5ByF9ZbpRFB7poQT2GMOyhLANn5ypedfBLBdjNYYIQi6KNjTMM6Z2IemkCHEJ dkRA== 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=pIIMDjhMLcRChaSUZYCTVP34wxWwK/Ju/NQeogQ/s/E=; b=FTBETvwmeUlFnL4MgrfD2jYbFYxmGoHNPhwrB8mwILANnAp0i2ZukQURKvErSjHWrC iwM7oCFmCizTOwls5flk4Vl2yyNqJQ+FupjDRRRFOSzag1mYtuy+mjubM+15ikJ6xlJh 9cWmTyAzRwkCEHCZNz/VZ/712x+/QlE5c+io4irFR0//ISM1bw6licnbvFpiyGVgCS7W ETxQEH6Xmlvg8Va6nJcSeEGeBO23a/UimWqhImdIxDtyi2q4eHqEYcr1BRGivMtWNE3g PaioV9DIfMJBFcfyilOj/eqF54WqLI1hlRscAW9KeJkNmxx3PWvpcel9e2Uvoy/kiFNP aXCg== X-Gm-Message-State: AGi0Pubxt13WCR3Uf530xzSLgbMHeSjr7CG8JVHJoT+8mtowEdhsw3bC KtaoBmOmVGAq9I2iE6mG5QzvaaPJrOo= X-Google-Smtp-Source: APiQypLw5g0pHVFiUELltrrKJOaYauTS2JOvCRQWnr5nRMq8iQ1Gf7/wUXmHD0AV7jWl5uzhh7vpvQ== X-Received: by 2002:a17:90a:e608:: with SMTP id j8mr13434951pjy.44.1587828289952; Sat, 25 Apr 2020 08:24:49 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id w11sm7319838pgj.4.2020.04.25.08.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Apr 2020 08:24:49 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, guro@fb.com, chris@chrisdown.name Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH 2/3] mm: add reclaim context as a new parameter in mem_cgroup_protected() Date: Sat, 25 Apr 2020 11:24:17 -0400 Message-Id: <20200425152418.28388-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200425152418.28388-1-laoar.shao@gmail.com> References: <20200425152418.28388-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: Add the reclaim context 'struct scan_control *sc' as a new parameter in the function mem_cgroup_protected(), which will be used later. Change the name of 'root' to 'target' for better understanding as this is a targeted reclaim. Also move the declaration and definition of the changed function into mm/internal.h. Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Chris Down Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 9 --------- mm/memcontrol.c | 14 ++++++++------ mm/vmscan.c | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d275c72c4f8e..b327857a1e7e 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -357,9 +357,6 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg, READ_ONCE(memcg->memory.elow)); } -enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg); - int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, bool compound); @@ -841,12 +838,6 @@ static inline unsigned long mem_cgroup_protection(struct mem_cgroup *memcg, return 0; } -static inline enum mem_cgroup_protection mem_cgroup_protected( - struct mem_cgroup *root, struct mem_cgroup *memcg) -{ - return MEMCG_PROT_NONE; -} - static inline int mem_cgroup_try_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask, struct mem_cgroup **memcgp, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5beea03dd58a..51dab7f2e714 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -6367,6 +6367,7 @@ static unsigned long effective_protection(unsigned long usage, * mem_cgroup_protected - check if memory consumption is in the normal range * @root: the top ancestor of the sub-tree being checked * @memcg: the memory cgroup to check + * @sc: the reclaim context * * WARNING: This function is not stateless! It can only be used as part * of a top-down tree iteration, not for isolated queries. @@ -6377,8 +6378,9 @@ static unsigned long effective_protection(unsigned long usage, * an unprotected supply of reclaimable memory from other cgroups. * MEMCG_PROT_MIN: cgroup memory is protected */ -enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, - struct mem_cgroup *memcg) +enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *target, + struct mem_cgroup *memcg, + struct scan_control *sc) { unsigned long usage, parent_usage; struct mem_cgroup *parent; @@ -6386,9 +6388,9 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (mem_cgroup_disabled()) return MEMCG_PROT_NONE; - if (!root) - root = root_mem_cgroup; - if (memcg == root) + if (!target) + target = root_mem_cgroup; + if (memcg == target) return MEMCG_PROT_NONE; usage = page_counter_read(&memcg->memory); @@ -6400,7 +6402,7 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root, if (!parent) return MEMCG_PROT_NONE; - if (parent == root) { + if (parent == target) { memcg->memory.emin = READ_ONCE(memcg->memory.min); memcg->memory.elow = memcg->memory.low; goto out; diff --git a/mm/vmscan.c b/mm/vmscan.c index 4c98512e2c9f..61c944e7f587 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2551,7 +2551,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) unsigned long reclaimed; unsigned long scanned; - switch (mem_cgroup_protected(target_memcg, memcg)) { + switch (mem_cgroup_protected(target_memcg, memcg, sc)) { case MEMCG_PROT_MIN: /* * Hard protection.