From patchwork Fri Dec 30 07:08:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13084134 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 798DCC4332F for ; Fri, 30 Dec 2022 06:53:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DCB98E0009; Fri, 30 Dec 2022 01:53:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 98E2E8E0008; Fri, 30 Dec 2022 01:53:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CD9C8E0009; Fri, 30 Dec 2022 01:53:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5457E8E0006 for ; Fri, 30 Dec 2022 01:53:11 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 369824030C for ; Fri, 30 Dec 2022 06:53:11 +0000 (UTC) X-FDA: 80298055782.11.2BA82A6 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf01.hostedemail.com (Postfix) with ESMTP id D818B40007 for ; Fri, 30 Dec 2022 06:53:08 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672383189; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2QOOhLzD1D8tWmRP04JBkjvhlCiFjNQeUQibqR215Gc=; b=afTaynRwwn4IwX88n2Dj1jEQDBQZn38MG888v6cGe9DVdlFGMbPEMEAg+hxW/NUrGBl76N UqN+SLu9QsJ+rTdH/yic3+2ZuIQQmk+0/dssF/sFhGOYIekxFMJK9VMDK0S1XQt1+P/1mR 3ZiGyJ0/Qsj3CE7zq3pQzlUc5ykyDQ0= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf01.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672383189; a=rsa-sha256; cv=none; b=I6aE8AJG80upGF1guBKe3L5nUFl/MAJmjE5yf3GpsK1/MMtBGPFwwUkc7JWiuIWNoUywSN CtTLxARJcja+bKqiLJPKAlCGio6rfwjhWh+n0z+qpGhGu1Vr8hRcZFfd90p+xyHVSJXsOu VARgsEXokPK/QPNI1j2r+nFSjnn7rQc= Received: from dggpemm500001.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NjwsX1WvMz16Lxn; Fri, 30 Dec 2022 14:51:44 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Fri, 30 Dec 2022 14:53:02 +0800 From: Kefeng Wang To: Andrew Morton , SeongJae Park CC: , , , , , Kefeng Wang Subject: [PATCH -next v4 1/8] mm: memcg: Add folio_memcg_check() Date: Fri, 30 Dec 2022 15:08:42 +0800 Message-ID: <20221230070849.63358-2-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20221230070849.63358-1-wangkefeng.wang@huawei.com> References: <20221230070849.63358-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D818B40007 X-Stat-Signature: e4467rwah3anrko1fwbnfx3wwur89oq6 X-HE-Tag: 1672383188-909729 X-HE-Meta: U2FsdGVkX19bVOcbB8hgyekacb6clrWMzJnXbK8JKDxdRQ17a7VoyCWI7tFPgS2QSijrOySGskc3ozoc3a11GfY9ndVJ4nw0qfpJ1+XtS7IwTfEICL37wEbS7vIubeTOuWROXaWM+9w6FLYF5dtggWt0EDQlh29+gqwZX/s/I1JgwT7Fb1pjcb6VOsGTUmPUtU3zOPFHop+Rv4ebaf0s4BZYGdZ9qAMV8Rcm2VIMfFUiTbqgOoMxe9VQNCkQV655oTYuI+NjK9H9m4CBfcpeIc3oPwiuooW99M4xyKA7Bale49kEtnX8OUFQUVGmX2pPioj+QYtRkuPyuSV88dYKAe3Gw8OA7xEXov6KjfsT7EcTMUkYk+BhygZiVedu8wElLWtPob7aOlTDMrQvrxrDcWW2xBywLjKT/1T+i/c3TziCxi9dXN3ex5aJ2Aic6XPv1elSCKuW6S9cp1sTokW046LYNP5fGj4uhDhQZ/N7yGHPrWVOeUg9fSG0R0Unuj1ps70H6PL/omW0yF1/xHZsDKOBFlyMt2CcCKVWOY3oPRwg5XjXN+L+0EVDkNWzMq7lV9p2YdQj1nmP4/ku/h20AGD2nAuHJBc5IvdX0riWj9nxiyQdqSQ1UYQpJp7yikIt54O/Ij5viYmpzrdITMHiptG5KON9vfRtWZtTcuxNxVlPDUalFbBvTyZyaVKprcM+XyJDqFUVOW8YG+wqgE5obUqmk4RpJD0z7ZkbYQTnYPbl8VS3H04FlblFfMi23eO7R3IY0Ex/WWRMPhjrms0e2v7MAFFUAR7gOjE+zQqZQsC6tXbPO/5+fb0FcCoqxhwopiBDCsmXkgEVP12lZNaC9vkQM+nd4x1Bft5mQhOE+3Z4B0iVdcmrEPe5RTMmI/DB+R8MQVNRvGx/t7I2gTYVIzGb7HkblPGTvRf1iQ4x2EAuZNSOgpgQh8Xab/9BI4e29BOd8sJjRT7LSSv8t2q m46gxeQQ zvfIX 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: From: Matthew Wilcox Convert page_memcg_check() into folio_memcg_check() and add a page_memcg_check() wrapper. The behaviour of page_memcg_check() is unchanged; tail pages always had a NULL ->memcg_data. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Kefeng Wang --- include/linux/memcontrol.h | 40 +++++++++++++++++++++++++------------- mm/memcontrol.c | 6 +++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index d3c8203cab6c..a2ebb4e2da63 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -466,34 +466,34 @@ static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) } /* - * page_memcg_check - get the memory cgroup associated with a page - * @page: a pointer to the page struct + * folio_memcg_check - Get the memory cgroup associated with a folio. + * @folio: Pointer to the folio. * - * Returns a pointer to the memory cgroup associated with the page, - * or NULL. This function unlike page_memcg() can take any page - * as an argument. It has to be used in cases when it's not known if a page + * Returns a pointer to the memory cgroup associated with the folio, + * or NULL. This function unlike folio_memcg() can take any folio + * as an argument. It has to be used in cases when it's not known if a folio * has an associated memory cgroup pointer or an object cgroups vector or * an object cgroup. * - * For a non-kmem page any of the following ensures page and memcg binding + * For a non-kmem folio any of the following ensures folio and memcg binding * stability: * - * - the page lock + * - the folio lock * - LRU isolation - * - lock_page_memcg() + * - lock_folio_memcg() * - exclusive reference * - mem_cgroup_trylock_pages() * - * For a kmem page a caller should hold an rcu read lock to protect memcg - * associated with a kmem page from being released. + * For a kmem folio a caller should hold an rcu read lock to protect memcg + * associated with a kmem folio from being released. */ -static inline struct mem_cgroup *page_memcg_check(struct page *page) +static inline struct mem_cgroup *folio_memcg_check(struct folio *folio) { /* - * Because page->memcg_data might be changed asynchronously - * for slab pages, READ_ONCE() should be used here. + * Because folio->memcg_data might be changed asynchronously + * for slabs, READ_ONCE() should be used here. */ - unsigned long memcg_data = READ_ONCE(page->memcg_data); + unsigned long memcg_data = READ_ONCE(folio->memcg_data); if (memcg_data & MEMCG_DATA_OBJCGS) return NULL; @@ -508,6 +508,13 @@ static inline struct mem_cgroup *page_memcg_check(struct page *page) return (struct mem_cgroup *)(memcg_data & ~MEMCG_DATA_FLAGS_MASK); } +static inline struct mem_cgroup *page_memcg_check(struct page *page) +{ + if (PageTail(page)) + return NULL; + return folio_memcg_check((struct folio *)page); +} + static inline struct mem_cgroup *get_mem_cgroup_from_objcg(struct obj_cgroup *objcg) { struct mem_cgroup *memcg; @@ -1165,6 +1172,11 @@ static inline struct mem_cgroup *folio_memcg_rcu(struct folio *folio) return NULL; } +static inline struct mem_cgroup *folio_memcg_check(struct folio *folio) +{ + return NULL; +} + static inline struct mem_cgroup *page_memcg_check(struct page *page) { return NULL; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 92f319ef6c99..259bc0a48d16 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2939,13 +2939,13 @@ struct mem_cgroup *mem_cgroup_from_obj_folio(struct folio *folio, void *p) } /* - * page_memcg_check() is used here, because in theory we can encounter + * folio_memcg_check() is used here, because in theory we can encounter * a folio where the slab flag has been cleared already, but * slab->memcg_data has not been freed yet - * page_memcg_check(page) will guarantee that a proper memory + * folio_memcg_check() will guarantee that a proper memory * cgroup pointer or NULL will be returned. */ - return page_memcg_check(folio_page(folio, 0)); + return folio_memcg_check(folio); } /*