From patchwork Tue Feb 27 19:23:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13574327 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 BB15FC54798 for ; Tue, 27 Feb 2024 19:23:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 455276B00E9; Tue, 27 Feb 2024 14:23:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D2716B00ED; Tue, 27 Feb 2024 14:23:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 224E66B00E9; Tue, 27 Feb 2024 14:23:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E530E6B00E3 for ; Tue, 27 Feb 2024 14:23:42 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id A83A180E10 for ; Tue, 27 Feb 2024 19:23:42 +0000 (UTC) X-FDA: 81838558284.19.D69D5E4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id 109A41A0014 for ; Tue, 27 Feb 2024 19:23:40 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=t53W7VHf; spf=none (imf19.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=1709061821; 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=FNPPeN942hbxsvA9N1gIHpI3nX27EjanohFk4jw9UuY=; b=poik5o6/AJAO5Mf8EEKCmthbuZjCaNBFqW/4FxkLchoQ264IYNbWIsWy3+owoX6gcZhe7f eryd7+gacLMCDiRjBcoN50kscsqZceUXobIkedM/ameEIocmm/CUw7zsY3MjdQLC5AoJAx r4lu3Xt446sPIVIqL//NNN1fAxyKpIM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709061821; a=rsa-sha256; cv=none; b=8nTt5VrR8CUcScqCllVKNfn2sVpnlLD1QiPt3NggoI4geTValEu6H0mNf5FrfUUgS0LAM/ EmWAAVtzqcH5luRfI+6cFXohjyxzwtDAGOAhzOnRhNIDuoiKXtrwkpxC7FTdE7HmI04HiR ehM5caWp9cvpZw1M+EJnRJ12YsDx2T4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=t53W7VHf; spf=none (imf19.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=FNPPeN942hbxsvA9N1gIHpI3nX27EjanohFk4jw9UuY=; b=t53W7VHffJpWuj199u0KM7wK8K GTlQoJXNyeyLLOo1jIXtIS8+5YxGpSK63kHEiBc4LNMEoUccn4OGVgclMkE6U8DxDbnhPfk8v143R xQYOFCYazgEF21NEI3p4LAOW00ExUXLNiBwfqJT/U1nNv6JajukW7UgtZgbzyeMERlQdSknaHVKin DgtPFfyeSBLW8tiiNznDu9Dk11N9NUkeu8wlPcastQTa4Fz+AkYDJM5/D/iwAC4nSQC5hwN/BfzZp YSjrQ5wBg381NLXkXWoI+JxXxVkvkbio3MkD9M9PR9sRfcYds+HEx80Aprgoi0hV+qC5oiCeVfkgh WZLk4l0Q==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rf33D-00000003B1S-1uUA; Tue, 27 Feb 2024 19:23:39 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org Subject: [PATCH 6/8] mm: Constify testing page/folio flags Date: Tue, 27 Feb 2024 19:23:33 +0000 Message-ID: <20240227192337.757313-7-willy@infradead.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240227192337.757313-1-willy@infradead.org> References: <20240227192337.757313-1-willy@infradead.org> MIME-Version: 1.0 X-Stat-Signature: ugb6hqm5phugozmrsu9jnk4eioow5bh8 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 109A41A0014 X-Rspam-User: X-HE-Tag: 1709061820-679269 X-HE-Meta: U2FsdGVkX19vyxu9Po1B6c0aCs7AMzWtLDNHfsqvNcAFMmbahpjW8EAnGDJ4ycbPI/sM4HFCPRFLQXnOTDUz5qWU/8BLoUXulTL73ntIa+U2MtYN+fMZt37sKzM1NVbf5T2oNG86dtwA605Epa3UvJcOBOQQvutGjPQst+9+EldMRzEHPUaTtRHdMGekEVmlh0UL60NWEmTj7BuOiYKpoHrQcURzp3WZ5VbNi/2PDFiwIGsI9Nf5QITbdPolMLzrsK7Kyxzs+6z5tZUcjbuEm6tuzimxI4kUBIc37AP7es+/PfOXk0sFrvPYis/Db2Q4o5mBOQRmaCX+34875fQXe0wbbXTMbxrvUK+gp8z6yJ8cwJbZLnKh6bGdMESYj9Wmo4dyiRcNk3d6P6sXMC7NlfmcU9IAsXtfIj+502BVfn0ex9n1xTkk4mrLoH2fLOZan1ebU534/OKTXTaMCzHMCnCIkl4Z74WSW28lA+flIatTpo+nCPZ6aIC6g2VHwv/WQW2bOIWGP8vilNeAOO1L44Ux3r0P7uNA3MqFOfl+lur8MjN5wXL9cxX4pu0tCWSbOo6fBiaW85AC+n/MDnhoHEmYoEHq3hBNTvC5e31lxKJuh0XA8+v8jB8BlvX9cZe+L53X2vrsrNaEfWWhZgY1ZkQBdL75kaUEEw1a+mSseRSdEXGbHbmkGIqs0ECIVk00STcaCZFW9WwfzHkq4uFlCiE1+j1Ow5cNfIt6y/tz7ukCtSRYKTkwU9irgIa3VHaxb6Py8VVcMRaWvSXV7/as76Xit3IbZKe8Q0PkcJjAAXdIO78sLbGj6uSsA9mphmgYYEo4cw8OyI/CPi0qOqoLfhjsUnQLdeRd8XEBcV/sS4bagwmhsgSvCCx3o0giuy+3wrUQkF40jbQR8rX5t22VqRnUJVbdRAbrjvc+E4f9qnL90vwd2R998Mqq+F+mN8+S6uH0mPc7TAdgYFPZsiH 7lT9bl1z 9DUXs8y44DxMwOqudOL+DRRzjakT+oFlx2/kyvGk3eQC1aAYeL3OM5Gfge458xvX3zwhiVj9KDKs+xgS/KDsOIQgOgqOpkx3Ab5A0UiJCjaaesOfw0/o/j2dd8eYb9qNIFqKSMxJeP0xFhjUgav4OKvF3ajWRIS56jt10ugjSrJR/tvq0UEh3zc2oqQ== 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: Now that dump_page() takes a const argument, we can constify all the page flag tests. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand --- include/linux/page-flags.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 582ca7400eca..3463cd1baebf 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -237,7 +237,7 @@ static inline const struct page *page_fixed_fake_head(const struct page *page) } #endif -static __always_inline int page_is_fake_head(struct page *page) +static __always_inline int page_is_fake_head(const struct page *page) { return page_fixed_fake_head(page) != page; } @@ -281,12 +281,12 @@ static inline unsigned long _compound_head(const struct page *page) */ #define folio_page(folio, n) nth_page(&(folio)->page, n) -static __always_inline int PageTail(struct page *page) +static __always_inline int PageTail(const struct page *page) { return READ_ONCE(page->compound_head) & 1 || page_is_fake_head(page); } -static __always_inline int PageCompound(struct page *page) +static __always_inline int PageCompound(const struct page *page) { return test_bit(PG_head, &page->flags) || READ_ONCE(page->compound_head) & 1; @@ -306,6 +306,16 @@ static inline void page_init_poison(struct page *page, size_t size) } #endif +static const unsigned long *const_folio_flags(const struct folio *folio, + unsigned n) +{ + const struct page *page = &folio->page; + + VM_BUG_ON_PGFLAGS(PageTail(page), page); + VM_BUG_ON_PGFLAGS(n > 0 && !test_bit(PG_head, &page->flags), page); + return &page[n].flags; +} + static unsigned long *folio_flags(struct folio *folio, unsigned n) { struct page *page = &folio->page; @@ -367,8 +377,8 @@ static unsigned long *folio_flags(struct folio *folio, unsigned n) * Macros to create function definitions for page flags */ #define FOLIO_TEST_FLAG(name, page) \ -static __always_inline bool folio_test_##name(struct folio *folio) \ -{ return test_bit(PG_##name, folio_flags(folio, page)); } +static __always_inline bool folio_test_##name(const struct folio *folio) \ +{ return test_bit(PG_##name, const_folio_flags(folio, page)); } #define FOLIO_SET_FLAG(name, page) \ static __always_inline void folio_set_##name(struct folio *folio) \ @@ -401,7 +411,7 @@ FOLIO_CLEAR_FLAG(name, page) #define TESTPAGEFLAG(uname, lname, policy) \ FOLIO_TEST_FLAG(lname, FOLIO_##policy) \ -static __always_inline int Page##uname(struct page *page) \ +static __always_inline int Page##uname(const struct page *page) \ { return test_bit(PG_##lname, &policy(page, 0)->flags); } #define SETPAGEFLAG(uname, lname, policy) \ @@ -801,7 +811,7 @@ static __always_inline bool folio_test_head(struct folio *folio) return test_bit(PG_head, folio_flags(folio, FOLIO_PF_ANY)); } -static __always_inline int PageHead(struct page *page) +static __always_inline int PageHead(const struct page *page) { PF_POISONED_CHECK(page); return test_bit(PG_head, &page->flags) && !page_is_fake_head(page);