From patchwork Thu Mar 14 01:25:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13592035 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 E4881C54E66 for ; Thu, 14 Mar 2024 01:25:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DC9A80075; Wed, 13 Mar 2024 21:25:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7639D80073; Wed, 13 Mar 2024 21:25:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DD7D80075; Wed, 13 Mar 2024 21:25:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 47C0F80073 for ; Wed, 13 Mar 2024 21:25:17 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 15FD0140653 for ; Thu, 14 Mar 2024 01:25:17 +0000 (UTC) X-FDA: 81893901474.05.687038D Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf30.hostedemail.com (Postfix) with ESMTP id 7E3AB8000F for ; Thu, 14 Mar 2024 01:25:15 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Vm3bXi7t; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710379515; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5qkac8gh5bHWc8b9kT2jiwjARNpzHIohgfqosxU2L10=; b=W6SCTBI8/X3zbWXyhnRfhMbzmdxMuJDWVOmURDJmAKuEZls4/47pDlDKpDziD4eo8bF5OW 0rkTb4+Zt1I8wag5pt5WtByaGVLsrH9BCPG/LH203A5mXU2tOHt3RMZyrEPshnHaoTWh3f cX8Qi/DWlsooA0D8CVuV6rfaSGogD/g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710379515; a=rsa-sha256; cv=none; b=3rZ7cDcBybhu8VUvzoQtQ7T3KP2bzVs0bluDwUdh3YHDid1zd2o9KAnxQN0paSCnFVj318 7S2fnK+WjKTHYaVPeyrQj5g5hz48L0446Kz5wRxf011lY3lpJWXXp8cEqh/vNQpmqqSTEB G+WkFE47uIWF+DU0sTLyVRMKFMbmiWw= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Vm3bXi7t; spf=none (imf30.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=5qkac8gh5bHWc8b9kT2jiwjARNpzHIohgfqosxU2L10=; b=Vm3bXi7tT7fiAQCAckQm3fgEbl b6FcZcOhOBmqxHue3yfpaiKSL4mZ6yPMnsCoxAKBy9gBUbSBwHCGlY9N/lUQzjjeO+xv5MhBr0FZf VoLvt56oKln3ge/YnNu/aCgbLhawP4uIdNGmrsg+p/14exNaHQJsh1rADmb2tl/KZKJkW8zGTQDy0 d/vJqyvvytQRufORN/KSpf4L5x7Gr4mreuaU7dW31ub8uD+iGC+tV4/JbI0dfWI+eYw6yRb3EOQ7x ZFpdLKAyeY50S2L9xGfVHOvhn04AjmgoxVf+q1/xLtqZQdkwBFOPUq5t2sBrrl0Fb10+y8itvTGog 4cxBxccQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkZqG-00000006iKv-2uhQ; Thu, 14 Mar 2024 01:25:08 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand , Oscar Salvador , Miaohe Lin Subject: [PATCH 1/2] mm: Turn folio_test_hugetlb into a PageType Date: Thu, 14 Mar 2024 01:25:01 +0000 Message-ID: <20240314012506.1600378-2-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240314012506.1600378-1-willy@infradead.org> References: <20240314012506.1600378-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7E3AB8000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: fsgondm57xt8kpctzokhx6zq1hwyeu9y X-HE-Tag: 1710379515-16052 X-HE-Meta: U2FsdGVkX1+H8MgULuIFATbqJEnvXzDWTql2Bt0s52mvd1b3qSgBbYzz3X+udTv7hxIt/jKXvMzeHV0aRWUViu+Hg9EQMenw6AK1yKGHy/Cxp22e1f65QHEw1kRgh8YPvssGXaq9+DQ709EijA1cVonrKObjapBft0mmgx2xELMNdzz877YcIXfc/iSAP8jb4JfnLzZIZ0gEeVr9AnZMskeJNgJvxIzk61ed7UW5CKgREvym8PoAzGC+sNAf3vkBctcMkDuWFUeuwLKQ3yJ6gKyEWNPkeqYLWvAOXRGF5n4a/GrMCmAKEOOzFEjbWY4W0OTIA/VO/ImkuT6PvfoFo1iszKOoVm3I9SwzMCoozWCdWCyw8v2XlB+BwdlCULEYt4hhFtqL6C5kB7O/WaXHf50qBSz5CacBZ4vtdnUJSzAT8ftEGXJU6L3jk4XRCU9Q5U3BHd4eqAO/8Wxa1KgulTJ0o4jPBG0IQz/VLSkETu3jLyb1aq4cjd02NoqhqBk+RB9NVrbCczQezOLRY6Gqf2GWDrjhMHZtzwkldCpB6fHJLM6NLXiSNJS7VWLs7hYOODboKEiHb/O/t4E2wNjaCJWfhra7P2R82bbWv8Bt4+7yoZR9lmIHwPSmczlJ53qkuflT9/kAwuJd4F2TKetk492qshASiooEC6XLrSmxKYND3JOwYgg1NY5vxW9N56VafuRMk+EQv4alK8bDcA62kP2Lwj7w+ch6QuTYkk9Q0pbH6taoHbixn9L2XmGfOjPUe7q+BZ7xERy2ufFuwBnoOX5JxLZ5Mmg5uN74LGGDT5o1tB4Vhak7k9upgo0e/Ut+CaZtwYsTcFE5e42Z8vq1PCiTr3JFlhAIFpDHNBIB22l+in/FMzKfVMhQsSdBqG/SE9xssFnU4/aNp6igZzXsJ8YdEp/0rAOZ 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: List-Subscribe: List-Unsubscribe: The current folio_test_hugetlb() can be fooled by a concurrent folio split into returning true for a folio which has never belonged to hugetlbfs. This can't happen if the caller holds a refcount on it, but we have a few places (memory-failure, compaction, procfs) which do not and should not take a speculative reference. Since hugetlb pages do not use individual page mapcounts (they are always fully mapped and use the entire_mapcount field to record the number of mappings), the PageType field is available for use with only a minor modification to page_mapcount() to ignore the value in this field for hugetlb pages. Other parts of the kernel which examine page->_mapcount directly already know about page_has_type() (eg procfs, dump_page()). Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand --- include/linux/mm.h | 3 ++ include/linux/page-flags.h | 70 ++++++++++++++++++-------------------- mm/hugetlb.c | 22 ++---------- 3 files changed, 39 insertions(+), 56 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index f5a97dec5169..32281097f07e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1212,6 +1212,9 @@ static inline int page_mapcount(struct page *page) { int mapcount = atomic_read(&page->_mapcount) + 1; + /* Head page repurposes mapcount; tail page leaves at -1 */ + if (PageHeadHuge(page)) + mapcount = 0; if (unlikely(PageCompound(page))) mapcount += folio_entire_mapcount(page_folio(page)); diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 735cddc13d20..6ebb573c7195 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -190,7 +190,6 @@ enum pageflags { /* At least one page in this folio has the hwpoison flag set */ PG_has_hwpoisoned = PG_error, - PG_hugetlb = PG_active, PG_large_rmappable = PG_workingset, /* anon or file-backed */ }; @@ -829,29 +828,6 @@ TESTPAGEFLAG_FALSE(LargeRmappable, large_rmappable) #define PG_head_mask ((1UL << PG_head)) -#ifdef CONFIG_HUGETLB_PAGE -int PageHuge(struct page *page); -SETPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) -CLEARPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) - -/** - * folio_test_hugetlb - Determine if the folio belongs to hugetlbfs - * @folio: The folio to test. - * - * Context: Any context. Caller should have a reference on the folio to - * prevent it from being turned into a tail page. - * Return: True for hugetlbfs folios, false for anon folios or folios - * belonging to other filesystems. - */ -static inline bool folio_test_hugetlb(struct folio *folio) -{ - return folio_test_large(folio) && - test_bit(PG_hugetlb, folio_flags(folio, 1)); -} -#else -TESTPAGEFLAG_FALSE(Huge, hugetlb) -#endif - #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* * PageHuge() only returns true for hugetlbfs pages, but not for @@ -907,18 +883,6 @@ PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) #endif -/* - * Check if a page is currently marked HWPoisoned. Note that this check is - * best effort only and inherently racy: there is no way to synchronize with - * failing hardware. - */ -static inline bool is_page_hwpoison(struct page *page) -{ - if (PageHWPoison(page)) - return true; - return PageHuge(page) && PageHWPoison(compound_head(page)); -} - /* * For pages that are never mapped to userspace (and aren't PageSlab), * page_type may be used. Because it is initialised to -1, we invert the @@ -935,6 +899,7 @@ static inline bool is_page_hwpoison(struct page *page) #define PG_offline 0x00000100 #define PG_table 0x00000200 #define PG_guard 0x00000400 +#define PG_hugetlb 0x00000800 #define PageType(page, flag) \ ((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) @@ -1026,6 +991,37 @@ PAGE_TYPE_OPS(Table, table, pgtable) */ PAGE_TYPE_OPS(Guard, guard, guard) +#ifdef CONFIG_HUGETLB_PAGE +PAGE_TYPE_OPS(HeadHuge, hugetlb, hugetlb) +#else +TESTPAGEFLAG_FALSE(HeadHuge, hugetlb) +#endif + +/** + * PageHuge - Determine if the page belongs to hugetlbfs + * @page: The page to test. + * + * Context: Any context. + * Return: True for hugetlbfs pages, false for anon pages or pages + * belonging to other filesystems. + */ +static inline bool PageHuge(struct page *page) +{ + return folio_test_hugetlb(page_folio(page)); +} + +/* + * Check if a page is currently marked HWPoisoned. Note that this check is + * best effort only and inherently racy: there is no way to synchronize with + * failing hardware. + */ +static inline bool is_page_hwpoison(struct page *page) +{ + if (PageHWPoison(page)) + return true; + return PageHuge(page) && PageHWPoison(compound_head(page)); +} + extern bool is_free_buddy_page(struct page *page); PAGEFLAG(Isolated, isolated, PF_ANY); @@ -1092,7 +1088,7 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page) */ #define PAGE_FLAGS_SECOND \ (0xffUL /* order */ | 1UL << PG_has_hwpoisoned | \ - 1UL << PG_hugetlb | 1UL << PG_large_rmappable) + 1UL << PG_large_rmappable) #define PAGE_FLAGS_PRIVATE \ (1UL << PG_private | 1UL << PG_private_2) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ed1581b670d4..23b62df21971 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -1623,7 +1623,7 @@ static inline void __clear_hugetlb_destructor(struct hstate *h, { lockdep_assert_held(&hugetlb_lock); - folio_clear_hugetlb(folio); + __folio_clear_hugetlb(folio); } /* @@ -1710,7 +1710,7 @@ static void add_hugetlb_folio(struct hstate *h, struct folio *folio, h->surplus_huge_pages_node[nid]++; } - folio_set_hugetlb(folio); + __folio_set_hugetlb(folio); folio_change_private(folio, NULL); /* * We have to set hugetlb_vmemmap_optimized again as above @@ -2048,7 +2048,7 @@ static void __prep_account_new_huge_page(struct hstate *h, int nid) static void init_new_hugetlb_folio(struct hstate *h, struct folio *folio) { - folio_set_hugetlb(folio); + __folio_set_hugetlb(folio); INIT_LIST_HEAD(&folio->lru); hugetlb_set_folio_subpool(folio, NULL); set_hugetlb_cgroup(folio, NULL); @@ -2158,22 +2158,6 @@ static bool prep_compound_gigantic_folio_for_demote(struct folio *folio, return __prep_compound_gigantic_folio(folio, order, true); } -/* - * PageHuge() only returns true for hugetlbfs pages, but not for normal or - * transparent huge pages. See the PageTransHuge() documentation for more - * details. - */ -int PageHuge(struct page *page) -{ - struct folio *folio; - - if (!PageCompound(page)) - return 0; - folio = page_folio(page); - return folio_test_hugetlb(folio); -} -EXPORT_SYMBOL_GPL(PageHuge); - /* * Find and lock address space (mapping) in write mode. * From patchwork Thu Mar 14 01:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13592034 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 4B5BEC54E58 for ; Thu, 14 Mar 2024 01:25:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B365280074; Wed, 13 Mar 2024 21:25:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE68280073; Wed, 13 Mar 2024 21:25:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95F9480074; Wed, 13 Mar 2024 21:25:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 83BCE80073 for ; Wed, 13 Mar 2024 21:25:15 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5BB59A0465 for ; Thu, 14 Mar 2024 01:25:15 +0000 (UTC) X-FDA: 81893901390.22.A39D645 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 56ABD40005 for ; Thu, 14 Mar 2024 01:25:12 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=q2xnfEzm; dmarc=none; spf=none (imf07.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710379513; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MTjJLTgp9t/J7Xrz7I6NWz7OnbeiFk3Tm1f5OI4VsyQ=; b=3NhI/2rIAyojOifw4MrsXvnLPz5cUwRUCfXK6qHq/pRDY1MBsGqbfcB2k01xfiBpIBYcx2 WwhYkPbOGgwc8z1AI2WF0Ll/iIpIWZQ1SP2jyBl7okZR5vzRkQ119YeyqV1l7azdBexzQf BjYMidgLYCmPTVko+9pyI8KXkMxigsk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=q2xnfEzm; dmarc=none; spf=none (imf07.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710379513; a=rsa-sha256; cv=none; b=EdTpIFhhB0RCEH75XSXcA3RV5VKhUMXSEkMZy3DWQlkfAFL+rRkVihhJ6PzK56EBg3juMp WUSHFhWLekBiYEqRtRIqWSc4xM9q8BCF2LELR83ZaGE/KayIxnMA9HSNiT1FcObNWKfjgH pdJyeQBwUcbzEEsd+FO6AdpFkfqOvjY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=MTjJLTgp9t/J7Xrz7I6NWz7OnbeiFk3Tm1f5OI4VsyQ=; b=q2xnfEzmUZFSittA8MmRh0LyYk fLGlbpjGY5gPQvHrKmaON9icJCK5beSEf2Sq/eiWR2K6WV9ynAqPhYSiTFzTRnDWcdE6Kq7KpxIhq vv2cGwsRfoocxaId8cvudKXJvHUpWUHLpopf+U70O7qUjzA0G2dnje70PYzQ93jMXoNVNiDuDtlOg nusxcEoyvSfMj0PmFkYRBW6fJIbQEmPcdkwRp/66ygk3FZ07bZwkUhwhxUZoqZcIHlrjXFPa6aHbP NPyObctT9k6yXdGDl1mBJmL/g/fRU0P0e/fpcoomSna1BbEQnyabu4qpoiWVS+on/7Am2ZZzc91JC CxLhNwUg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rkZqG-00000006iKx-3EUg; Thu, 14 Mar 2024 01:25:08 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, David Hildenbrand , Oscar Salvador , Miaohe Lin Subject: [PATCH 2/2] mm: Remove a call to compound_head() from is_page_hwpoison() Date: Thu, 14 Mar 2024 01:25:02 +0000 Message-ID: <20240314012506.1600378-3-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240314012506.1600378-1-willy@infradead.org> References: <20240314012506.1600378-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 56ABD40005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: cpaoi4jq8n4xtf16t7zbijg59jfy3u19 X-HE-Tag: 1710379512-143825 X-HE-Meta: U2FsdGVkX19g3JyAt0BBpnZA0BbPx10eu+25gXf8ntCEKGDxwITdGxJIhRm1vDrTlHvc23yLMU7Z2kEnJDRODGUs+JZWLJ1E1QPQVlWLSvNYj+2OLkbQNFMeMbEf/Spc4SiDCo0K4/xGIBj5c210u9gbyE5W/IYtTPH5aloG2MaOvbUgiaziLmhJ/lg7NGM1jR32F8rGrly542JEPayKlyoFUMucWENifDjjru08wHXgLfAqX2nKuJ0Dc0BN8tADzQu93vp8SaIADJ5Zs4qDlDKqDUlKwEMlLpA8tbPoJK423WGC1z8uAb7+r1WZwW1Afd2sJQVxN/nREtR/NvfoLWmGba/i9JkDh+uwhmsyRoKygf90sS7V+C/vRr1XhkFF2NRtvFiV4r4CZ9uqL0XmHbJUl8EqbKLL2t/MiEsZxjp3bOg+cmu/nSSbmb/vwTq4QvxwD9Ox9iVYR/e3EU/0UabaqU6fQwlsqOMiwbbuXi4QeXXwBw/z9eEfHGfIjDTHBovINTazaewCIBeMqTThaGGxFmiARZVkfMogU6N+08zL5EITEH22VIPVZ1/N5G3JWK069BRX5ruCNis7xCnB9hrqCQhTC/p8pqC2toOC8MqQeDgNRPMhS4LQl9PRWiYpxiPGlM+hnaZbyDotaxzYjtlfmG2oP/S28PpiIi5mw1rVK4E1UtrgAmzzSwhSMb3jMnNc+gDQ6ggF8u475Aatz/c3MINEKwuZV7Aefyh9+IGtaOxKifyH6ST+wDKfKJsel8Dad0N8ultGq9cDllWmVe0JZ70y806gxQwyc8YSNntqbdcNex/XJBW5mFOOSgO9y2XnMFWSJt8V2PKTaWXnC4KW1paVCx7MvmgA4h1BZHAGNwMZZGQgG6u0hrSw8upH+BcMBUTABIDAqlSGs3CohIfNbFTfJtaf 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: List-Subscribe: List-Unsubscribe: We can call it only once instead of twice. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand Reviewed-by: Miaohe Lin --- include/linux/page-flags.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 6ebb573c7195..f1d65a72b378 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -1017,9 +1017,12 @@ static inline bool PageHuge(struct page *page) */ static inline bool is_page_hwpoison(struct page *page) { + struct folio *folio; + if (PageHWPoison(page)) return true; - return PageHuge(page) && PageHWPoison(compound_head(page)); + folio = page_folio(page); + return folio_test_hugetlb(folio) && PageHWPoison(&folio->page); } extern bool is_free_buddy_page(struct page *page);