From patchwork Tue Oct 27 08:02:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11859637 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 352356A2 for ; Tue, 27 Oct 2020 08:03:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D6F81207BB for ; Tue, 27 Oct 2020 08:03:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="P+Nz2tG9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D6F81207BB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0AC336B0071; Tue, 27 Oct 2020 04:03:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 05B4C6B0072; Tue, 27 Oct 2020 04:03:57 -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 E8C0A6B0073; Tue, 27 Oct 2020 04:03:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0161.hostedemail.com [216.40.44.161]) by kanga.kvack.org (Postfix) with ESMTP id BE8586B0071 for ; Tue, 27 Oct 2020 04:03:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 59BBE1EE6 for ; Tue, 27 Oct 2020 08:03:56 +0000 (UTC) X-FDA: 77416966872.18.neck64_0c030f02727a Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 4A98E100ED0FC for ; Tue, 27 Oct 2020 08:03:56 +0000 (UTC) X-Spam-Summary: 1,0,0,2fa91a600cd4714e,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1544:1605:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2890:2901:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4042:4118:4250:4321:4605:5007:6261:6653:6737:7875:9010:9592:10004:11026:11658:11914:12043:12048:12114:12291:12296:12297:12438:12517:12519:12555:12683:12895:13894:14096:14110:14181:14394:14721:21080:21444:21450:21451:21627:21966:21990:30001:30012:30054,0,RBL:209.85.215.193:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04y8skxze44tibewxjfxpsjf5aiyjycmoeafw17uhd6q5wmu95hskmsnyt7x6wo.h8swa5urbf9twb84kpgbogbyyqbec51yxqhhemms6jw67afjqyr3uyf1urfzf1o.a-lbl8.mailshell.net-223.238.255.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:23,LUA_SUMMARY:none X-HE-Tag: neck64_0c030f02727a X-Filterd-Recvd-Size: 7666 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 27 Oct 2020 08:03:55 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id g12so317224pgm.8 for ; Tue, 27 Oct 2020 01:03:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uiglRpBNWkrLFEUzSubzu7HQqvI3OKCdlqP2Lx2y8is=; b=P+Nz2tG9WB/qhj+FCO+gcFTyNF1I6MsxBKRw9kmsx8p6kTqOEUDww4WezfUMzA7ids ac0Zw4GET/vXhxCf8QG68dkLY5mwIlJRUt9Gm+jLihmcX0NoOz+Cp5twgR8DGsYW67qd PZLKcV4nEUGWtiN0RpyT1yxo4Vpm4Vkn4poFL4T2cKC8G6zrJxeA05Boleywdh/UF3ZC mRUnhoac0MFVouztQxbXWFTjsi/iFZUkv7BWXoxoXhK2tMu9Ey2RFTz7zACV5EhVfAwX vnFuZ5csx1UlaEVc6ELswrsJ5ZO+KZAEF/R9wChhpmuL/z63EgKtfFu5WfRU6MxRFo7g u0PA== 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:mime-version:content-transfer-encoding; bh=uiglRpBNWkrLFEUzSubzu7HQqvI3OKCdlqP2Lx2y8is=; b=lwbj9xGc5JMJVHyoYx3VZQaogFTrMgX9jYEh3jjGBx511LddAVxONsiILN6NjVNZib QOj6Wb2+Geum3w6k/M2xYkzB0Odgib1ZObPwokC+15XxRfJmXK2U0g37AzfaJJNJ4ATb 2wAqpD69MjYOlK88duIeT7OHfcjC91M4ZdsLTJlAx/6zVFG3IDEsEs7ao9vrR7uRC5tO VrjHwU2JaI11xcU/sW5ZQBwbgrf8G9L9ls0s5AkF3UNZ30Ia7pCI6hOfNlqlUBaEQUQW 0AjWsb43Uy6on0Pvxm3hMe0n5YtDYwYjz36s7RWsAvGuE3iB2kReUcNY2qiP6jF6szga +6Mw== X-Gm-Message-State: AOAM532uXtVhnDIcA3fE8OV9liZc65Ucxp+GVtfssvLRtQ1j2+sLViTT JJ7xEs7W1OwddW0jD3tz9/HB7Q== X-Google-Smtp-Source: ABdhPJxqNnFSCS9aSZpbv6+4QVNMOZB8yeIGk564y0BvOrg9NvzTp9pcjm2oymtvYwf9KBriDCrUgQ== X-Received: by 2002:aa7:91c8:0:b029:155:c7c1:3fae with SMTP id z8-20020aa791c80000b0290155c7c13faemr1060014pfa.74.1603785834731; Tue, 27 Oct 2020 01:03:54 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.89]) by smtp.gmail.com with ESMTPSA id p8sm1039580pgs.34.2020.10.27.01.03.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Oct 2020 01:03:54 -0700 (PDT) From: Muchun Song To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, shakeelb@google.com, guro@fb.com, iamjoonsoo.kim@lge.com, laoar.shao@gmail.com, chris@chrisdown.name, christian.brauner@ubuntu.com, peterz@infradead.org, mingo@kernel.org, keescook@chromium.org, tglx@linutronix.de, esyr@redhat.com, surenb@google.com, areber@redhat.com, elver@google.com Cc: linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Muchun Song Subject: [PATCH 5/5] mm: memcontrol: Simplify the mem_cgroup_page_lruvec Date: Tue, 27 Oct 2020 16:02:56 +0800 Message-Id: <20201027080256.76497-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201027080256.76497-1-songmuchun@bytedance.com> References: <20201027080256.76497-1-songmuchun@bytedance.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We can reuse the code of mem_cgroup_lruvec() to simplify the code of the mem_cgroup_page_lruvec(). Signed-off-by: Muchun Song --- include/linux/memcontrol.h | 44 +++++++++++++++++++++++++++----------- mm/memcontrol.c | 40 ---------------------------------- 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 95807bf6be64..5e8480e54cd8 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -451,16 +451,9 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) return memcg->nodeinfo[nid]; } -/** - * mem_cgroup_lruvec - get the lru list vector for a memcg & node - * @memcg: memcg of the wanted lruvec - * - * Returns the lru list vector holding pages for a given @memcg & - * @node combination. This can be the node lruvec, if the memory - * controller is disabled. - */ -static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, - struct pglist_data *pgdat) +static inline struct lruvec *mem_cgroup_node_lruvec(struct mem_cgroup *memcg, + struct pglist_data *pgdat, + int nid) { struct mem_cgroup_per_node *mz; struct lruvec *lruvec; @@ -473,7 +466,7 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, if (!memcg) memcg = root_mem_cgroup; - mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id); + mz = mem_cgroup_nodeinfo(memcg, nid); lruvec = &mz->lruvec; out: /* @@ -486,7 +479,34 @@ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, return lruvec; } -struct lruvec *mem_cgroup_page_lruvec(struct page *, struct pglist_data *); +/** + * mem_cgroup_lruvec - get the lru list vector for a memcg & node + * @memcg: memcg of the wanted lruvec + * + * Returns the lru list vector holding pages for a given @memcg & + * @node combination. This can be the node lruvec, if the memory + * controller is disabled. + */ +static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, + struct pglist_data *pgdat) +{ + return mem_cgroup_node_lruvec(memcg, pgdat, pgdat->node_id); +} + +/** + * mem_cgroup_page_lruvec - return lruvec for isolating/putting an LRU page + * @page: the page + * @pgdat: pgdat of the page + * + * This function relies on page->mem_cgroup being stable - see the + * access rules in commit_charge(). + */ +static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page, + struct pglist_data *pgdat) +{ + return mem_cgroup_node_lruvec(page->mem_cgroup, pgdat, + page_to_nid(page)); +} struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 70345b15b150..7097f3fc4dee 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1332,46 +1332,6 @@ int mem_cgroup_scan_tasks(struct mem_cgroup *memcg, return ret; } -/** - * mem_cgroup_page_lruvec - return lruvec for isolating/putting an LRU page - * @page: the page - * @pgdat: pgdat of the page - * - * This function relies on page->mem_cgroup being stable - see the - * access rules in commit_charge(). - */ -struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgdat) -{ - struct mem_cgroup_per_node *mz; - struct mem_cgroup *memcg; - struct lruvec *lruvec; - - if (mem_cgroup_disabled()) { - lruvec = &pgdat->__lruvec; - goto out; - } - - memcg = page->mem_cgroup; - /* - * Swapcache readahead pages are added to the LRU - and - * possibly migrated - before they are charged. - */ - if (!memcg) - memcg = root_mem_cgroup; - - mz = mem_cgroup_page_nodeinfo(memcg, page); - lruvec = &mz->lruvec; -out: - /* - * Since a node can be onlined after the mem_cgroup was created, - * we have to be prepared to initialize lruvec->zone here; - * and if offlined then reonlined, we need to reinitialize it. - */ - if (unlikely(lruvec->pgdat != pgdat)) - lruvec->pgdat = pgdat; - return lruvec; -} - /** * mem_cgroup_update_lru_size - account for adding or removing an lru page * @lruvec: mem_cgroup per zone lru vector