From patchwork Sun Nov 8 14:37:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hui Su X-Patchwork-Id: 11889669 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 11841139F for ; Sun, 8 Nov 2020 14:39:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A247620760 for ; Sun, 8 Nov 2020 14:39:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="LR99cRZn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A247620760 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B45856B0081; Sun, 8 Nov 2020 09:39:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF62D6B0082; Sun, 8 Nov 2020 09:39:02 -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 9E49F6B0083; Sun, 8 Nov 2020 09:39:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0103.hostedemail.com [216.40.44.103]) by kanga.kvack.org (Postfix) with ESMTP id 722026B0081 for ; Sun, 8 Nov 2020 09:39:02 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0B0C11EE6 for ; Sun, 8 Nov 2020 14:39:02 +0000 (UTC) X-FDA: 77461508124.02.thumb09_0a139d0272e4 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id D53D110097AA1 for ; Sun, 8 Nov 2020 14:39:01 +0000 (UTC) X-Spam-Summary: 1,0,0,91dec5f694629a9e,d41d8cd98f00b204,sh_def@163.com,,RULES_HIT:41:69:355:379:582:800:960:973:988:989:1152:1260:1277:1312:1313:1314:1345:1437:1516:1518:1519:1535:1543:1593:1594:1595:1596:1711:1730:1747:1777:1792:2194:2199:2393:2559:2562:2890:2901:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:4042:4250:4321:4605:5007:6261:6653:6737:7875:9010:9592:10004:10400:11026:11334:11658:11914:12043:12048:12114:12296:12297:12438:12555:12683:12895:12986:13439:13895:14096:14097:14181:14394:14721:21080:21433:21450:21451:21627:21966:21990:30001:30054,0,RBL:220.181.12.13:@163.com:.lbl8.mailshell.net-62.50.2.100 66.100.201.100;04yfbzamm4qkepegabnowydhanbijoc8d5ta7izo7584z95xtjj5mgcnsimbtut.qy1i4qcxn76sjozb4sd59xzbm3ifaxsusi8wit7qnw1i1k8wiziqzhptc1iy7ir.4-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:none,Custom_rules:0:0:0,LFtime:70,LUA_SUMMARY:none X-HE-Tag: thumb09_0a139d0272e4 X-Filterd-Recvd-Size: 5162 Received: from m12-13.163.com (m12-13.163.com [220.181.12.13]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Sun, 8 Nov 2020 14:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=vi3Bj fzpqssVUtirGQmg9J3S/o92w2Pdis4J9PzyuEA=; b=LR99cRZns097oGxzgUbGR 7KE9mcPJVTRCuG6VwZtTjH/ZxYSu8Ep5ls1k8VD6cVygCRVrZ20KDGC0ieAQ40DC SCrWZCc4DRWEpPzTLY4LMfkfXiWVtGYGDMcKfwFQp8C6VndvC0UDjtG4rCGEuJEe hFo380z8ezfUdAFqcT8MTE= Received: from localhost (unknown [101.86.208.122]) by smtp9 (Coremail) with SMTP id DcCowAAHZwOrAqhfgSskPg--.40498S2; Sun, 08 Nov 2020 22:37:31 +0800 (CST) Date: Sun, 8 Nov 2020 22:37:31 +0800 From: Hui Su To: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, shakeelb@google.com, guro@fb.com, laoar.shao@gmail.com, chris@chrisdown.name, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org Cc: sh_def@163.com Subject: [PATCH v2] mm/memcontrol:rewrite mem_cgroup_page_lruvec() Message-ID: <20201108143731.GA74138@rlk> MIME-Version: 1.0 Content-Disposition: inline X-CM-TRANSID: DcCowAAHZwOrAqhfgSskPg--.40498S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWF4UJr4DZr1UKrW7tr1kZrb_yoW5tF43pF ZxG3W3Z398JrWYqr4xta1q9a4fZa1xJw43Jr17Jw1IvF13K340q3W2kr1rXFWUuFySyrnr trZ0kr18G3yqvFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRRT5JUUUUU= X-Originating-IP: [101.86.208.122] X-CM-SenderInfo: xvkbvvri6rljoofrz/1tbifwvWX1r6mir7KwAAs9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.055429, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: mem_cgroup_page_lruvec() in memcontrol.c and mem_cgroup_lruvec() in memcontrol.h is very similar except for the param(page and memcg) which also can be convert to each other. So rewrite mem_cgroup_page_lruvec() with mem_cgroup_lruvec(). v1->v2: use page_memcg() instead of 'page->mem_cgroup'. Acked-by: Michal Hocko Acked-by: Johannes Weiner Reviewed-by: Shakeel Butt Signed-off-by: Hui Su Acked-by: Roman Gushchin --- include/linux/memcontrol.h | 16 +++++++++++++-- mm/memcontrol.c | 40 -------------------------------------- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index e391e3c56de5..727af7c74e91 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -457,9 +457,10 @@ mem_cgroup_nodeinfo(struct mem_cgroup *memcg, int nid) /** * mem_cgroup_lruvec - get the lru list vector for a memcg & node * @memcg: memcg of the wanted lruvec + * @pgdat: pglist_data * * Returns the lru list vector holding pages for a given @memcg & - * @node combination. This can be the node lruvec, if the memory + * @pgdat combination. This can be the node lruvec, if the memory * controller is disabled. */ static inline struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, @@ -489,7 +490,18 @@ 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_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. + */ +static inline struct lruvec *mem_cgroup_page_lruvec(struct page *page, + struct pglist_data *pgdat) +{ + return mem_cgroup_lruvec(page_memcg(page), pgdat); +} struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 3dcbf24d2227..9d4e1150b194 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1330,46 +1330,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