From patchwork Wed Oct 28 03:50:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 11862433 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 20AA914B7 for ; Wed, 28 Oct 2020 03:51:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C4E4D22456 for ; Wed, 28 Oct 2020 03:51:15 +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="t0Q+e2FB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4E4D22456 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 E97156B0068; Tue, 27 Oct 2020 23:51:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E47E36B006C; Tue, 27 Oct 2020 23:51:14 -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 D0EAA6B006E; Tue, 27 Oct 2020 23:51:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0165.hostedemail.com [216.40.44.165]) by kanga.kvack.org (Postfix) with ESMTP id A3B966B0068 for ; Tue, 27 Oct 2020 23:51:14 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3B2C21EE6 for ; Wed, 28 Oct 2020 03:51:14 +0000 (UTC) X-FDA: 77419958868.05.table02_1101a3c27281 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 1EA9718020B1B for ; Wed, 28 Oct 2020 03:51:14 +0000 (UTC) X-Spam-Summary: 1,0,0,6cdeac1604f52a88,d41d8cd98f00b204,songmuchun@bytedance.com,,RULES_HIT:2:41:69:355:379:541:800:960:973:988:989:1260:1311:1314:1345:1359:1437:1515:1535:1605:1606:1730:1747:1777:1792:2194:2199:2393:2559:2562:2890:2901:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4042:4119:4250:4321:4605:5007:6119: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:14394:21080:21444:21450:21451:21627:21966:21990:30001:30012:30054,0,RBL:209.85.215.195:@bytedance.com:.lbl8.mailshell.net-62.2.0.100 66.100.201.201;04yrrjddtbs4s8fnw49g5dd5nmp7kocudqoo6senk77qneiobwwkiwrb7hc67h1.43yfihdpeo8b9moruw67p6qptgssu493gqnsboxr9hymcstaq746wx9gto6jjk8.g-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:68,LUA_SUMMARY:none X-HE-Tag: table02_1101a3c27281 X-Filterd-Recvd-Size: 8577 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Wed, 28 Oct 2020 03:51:13 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id s22so1978544pga.9 for ; Tue, 27 Oct 2020 20:51:13 -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=rFOCR0z2k088YX66ZBfrxJZH18ogpQbHQLbfk8+8CYU=; b=t0Q+e2FBNi/gftNkFBdCTLi3hN6RhvPuqrjrAeVOgKjK0yetO6ZVmJ9PoviQAZiAav 2uQ4+Vj+6OJ2rDvCyt2uyBu3twAoqDxpPQ6HKCdcNsfQt3fKQ2VVySd+/O7ZhT+omSvS qZb5XlF2ct60QyTPLgt0a8Lieq3qhoMKPpQRDi4d7p/5pbyAiEwESnQWV9cwbVPkgwyk BAyL5QTuIq0WENXagPIbA0m6crAXFshFYRKBVua2yDvn4vjkUGv3eanVsknBQaVhtaiA ZmBGY8UiNIxoTPgMxz+0ofvcOYRNPR4a6i82osws4JKcgiLpHKTuugXL6LkqKE3r0k7B z0aQ== 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=rFOCR0z2k088YX66ZBfrxJZH18ogpQbHQLbfk8+8CYU=; b=Uv9wOvUjCfAAShaWVDjoNGx6eXQXAoPNpIVjoosssEfjNFUbBanVw0Oa3f6CqnfZ6q a8IQ+ojRJug2fKC5Sh+KuRwLPEKkAqy3+zQT76RstN7PdaqnUMLhVkybpuQ9wBfVcB8B N/89hmfPfImWdTdyRc8u7++WVneeJR+aGEiaJfLbvIyQUTAqEh+UmWnq2vRqgdhdv7Hx zxV82U3ZDbIni/PosbtdnObB/8/lzyHSecRhP7bmz82nVclid0Lewi8qo/UxaQB2yvHa ld7yynYDnxJAvtYQsKnnzX67uYlNLVNqxOc70TEa2K1iMxsiaGNiYMxSMGLazrOMYLQ6 /1Kg== X-Gm-Message-State: AOAM532ocC4oFAN+/Z4KM4Kp7GFnkC/eMuNzQSiZrpY4Vk7HnqD7er0P WIinRySMFqVM9XlELmCxCsqcAQ== X-Google-Smtp-Source: ABdhPJw85ywrViQDutYz7H0AcVWUMgaMzewvZdsi2bR6wV3akldT5YSxgNVzdtytLLB0N19+6b94gg== X-Received: by 2002:a63:4d45:: with SMTP id n5mr4488139pgl.389.1603857072734; Tue, 27 Oct 2020 20:51:12 -0700 (PDT) Received: from Smcdef-MBP.local.net ([103.136.220.89]) by smtp.gmail.com with ESMTPSA id s8sm3412273pjn.46.2020.10.27.20.51.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Oct 2020 20:51:12 -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 v2] mm: memcontrol: Simplify the mem_cgroup_page_lruvec Date: Wed, 28 Oct 2020 11:50:13 +0800 Message-Id: <20201028035013.99711-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20201028035013.99711-1-songmuchun@bytedance.com> References: <20201028035013.99711-1-songmuchun@bytedance.com> MIME-Version: 1.0 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: We can reuse the code of mem_cgroup_lruvec() to simplify the code of the mem_cgroup_page_lruvec(). Signed-off-by: Muchun Song --- changelog in v2: 1. Move mem_cgroup_node_lruvec to memcontrol.c to avoid abuse. include/linux/memcontrol.h | 41 ++++------------------------- mm/memcontrol.c | 53 ++++++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 95807bf6be64..bbdc694d26b1 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -445,48 +445,17 @@ void mem_cgroup_uncharge_list(struct list_head *page_list); void mem_cgroup_migrate(struct page *oldpage, struct page *newpage); -static struct mem_cgroup_per_node * +static inline struct mem_cgroup_per_node * 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) -{ - struct mem_cgroup_per_node *mz; - struct lruvec *lruvec; - - if (mem_cgroup_disabled()) { - lruvec = &pgdat->__lruvec; - goto out; - } - - if (!memcg) - memcg = root_mem_cgroup; - - mz = mem_cgroup_nodeinfo(memcg, pgdat->node_id); - lruvec = &mz->lruvec; -out: - /* - * Since a node can be onlined after the mem_cgroup was created, - * we have to be prepared to initialize lruvec->pgdat here; - * and if offlined then reonlined, we need to reinitialize it. - */ - if (unlikely(lruvec->pgdat != pgdat)) - lruvec->pgdat = pgdat; - return lruvec; -} +struct lruvec *mem_cgroup_lruvec(struct mem_cgroup *memcg, + struct pglist_data *pgdat); -struct lruvec *mem_cgroup_page_lruvec(struct page *, struct pglist_data *); +struct lruvec *mem_cgroup_page_lruvec(struct page *page, + struct pglist_data *pgdat); struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p); diff --git a/mm/memcontrol.c b/mm/memcontrol.c index bbd40c5af61e..28095a1711aa 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1332,18 +1332,15 @@ 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(). +/* + * Note: Do not use this function directly. Please use mem_cgroup_lruvec() + * or mem_cgroup_page_lruvec() instead. */ -struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgdat) +static struct lruvec * +__mem_cgroup_node_lruvec(struct mem_cgroup *memcg, struct pglist_data *pgdat, + int nid) { struct mem_cgroup_per_node *mz; - struct mem_cgroup *memcg; struct lruvec *lruvec; if (mem_cgroup_disabled()) { @@ -1351,20 +1348,15 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgd 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); + mz = mem_cgroup_nodeinfo(memcg, nid); 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; + * we have to be prepared to initialize lruvec->pgdat here; * and if offlined then reonlined, we need to reinitialize it. */ if (unlikely(lruvec->pgdat != pgdat)) @@ -1372,6 +1364,35 @@ struct lruvec *mem_cgroup_page_lruvec(struct page *page, struct pglist_data *pgd return lruvec; } +/** + * 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. + */ +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(). + */ +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)); +} + /** * mem_cgroup_update_lru_size - account for adding or removing an lru page * @lruvec: mem_cgroup per zone lru vector