From patchwork Tue Feb 27 19:23:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13574332 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 1A9CAC5478C for ; Tue, 27 Feb 2024 19:23:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C132F6B00F6; Tue, 27 Feb 2024 14:23:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B73896B0103; Tue, 27 Feb 2024 14:23:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 930D228000B; Tue, 27 Feb 2024 14:23:44 -0500 (EST) 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 618326B00F6 for ; Tue, 27 Feb 2024 14:23:44 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3BE18A132C for ; Tue, 27 Feb 2024 19:23:44 +0000 (UTC) X-FDA: 81838558368.03.0F4CF92 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf26.hostedemail.com (Postfix) with ESMTP id AC837140008 for ; Tue, 27 Feb 2024 19:23:42 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=bCmLRwfe; spf=none (imf26.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=1709061822; 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=a3ZTH8nL1tyaewAJnOApG6Iuk7ZCfPQQszhrvLxioIY=; b=f3D9Zv33EvNXJFZTvrotSJFT7J9vlyii0aqiEFNnE4wwGcfiD40ZUz3yYIB1HbkeJ4+L5+ lbrdXDf1Ax2SZvYcBgyzvMOZ026D7LH2BFiKYkk3Wu6c+6Vm0MXnyQeI/8potI8Cj4QS6c dEyXkYZbdx6zoI7H710ZBEV3nhJekSU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709061822; a=rsa-sha256; cv=none; b=Ir9RYXuxJ7kBnoww0jPZTrxVwjPeUgj9XGyu3W44Ds6MWM8FXS68xrPhGjWB4MVaf34/o4 K7iY+OxACKokTIdSZedhOwMHpAmZbwLjvA2P0KDVG/qSGnAuMFF21zR5r6/21tq+JuNYdJ ex88uPvPtsSI1iEwXT+kobTw0L5cA1Y= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=bCmLRwfe; spf=none (imf26.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=a3ZTH8nL1tyaewAJnOApG6Iuk7ZCfPQQszhrvLxioIY=; b=bCmLRwfe7wegiAzQT8MPjfec89 S19NY6XMcnZ5VBeUvQzDwk2WCq0770wuhN2vIzU8HhgcatGVYrhEq8RSefysoU7Y7g/oBcKRETvJP e4nNUXkgMl9XPKrXQ7zRfWmrR6wVGLs02/e80VhF7eWNrVmaINzI4V2Yt6V8oFMVl/RiwM+DFv552 pr1DlDWTSvuQgF69977Ajwl4AO4s/td9SoG3LQKx/S1UTQy0Q5+zlpcsNBmTTqVLjBcn/qveJeBup IsEnxPFX7vatH67xDum6A3GDOEBs6EiJPsxK9wVPO8oehN3YSqMdLQ9+rRPu+MTAWWNZWRHOzKDuS FCNLFWQQ==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rf33D-00000003B1Y-2cqL; 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 7/8] mm: Constify more page/folio tests Date: Tue, 27 Feb 2024 19:23:34 +0000 Message-ID: <20240227192337.757313-8-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: tcg31eeia5o3exg5r8bg3jhh9tbwjzjg X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: AC837140008 X-Rspam-User: X-HE-Tag: 1709061822-481152 X-HE-Meta: U2FsdGVkX19nfXh1yAAKsG/tYjWo4GGH5gL426SLUhg+vJaCFxTDYqJO/uKAH55dnnWQO2jpN99bqo6Xa8PkIdUxjOHbfE0nZl5uKcWSu/geEdDC0DqHEpILq6SbHcqG99IS3/Jutu6jspaeIw32AA8nOQIF/p3HvlnRgm+3/SFSTNQ1PQOd5YdMv/f1oD2SjaGoyslzrK48b1aErwDKotrLLJhKaB2hZRDwSXGcyG2Dzui08ibWTd4kI0ivOP5gf0e8DuOJPlpfel7C+ULhgaDgwQ8BOHuSY683v6/WnqnG472pg5u8dPCckYL33FODPbTUxYjdkfXtyvEDa6l9E+cPCuHHKex7C83JrPQHrDRwq0+GcM/OTYf/lr28CcEGTXHYfYdiSPAeINEouFc5otzIqh9JyoQJEaRNrOG9ro73stnQCmPrpWur244tUhU3JiluH6em9FiVxQOnAx7BhFdLrsfFHG80AXJz+4ifBKoQXZDnmPxJe9lPrDEGUsNAJu9icIRm/jDz+gRJwFi5ZcXphlIPUoP6yTm5D1HNXiB2SNi9C0/gW3x4VY2B8amkkMTWRWYhnuJn18CY7yrlsyVH37UlvwX7ergNunU5+UHKxnpooC/428oh+oHnJySYARF7BqDc0H/XgOL51nbN/eDZIS65M4R1jNLDPzmy9BL1hIoyTshnqM/N0aBtWL10qxjUThbkG5QuocnWDo6WkOfP+o8N0GOKTqIrGVPbV2uprxj1moqedL8wcI23LEkZFQDJhGVb0O3mPaFIbxfeLjLbzBLMxyOhA3yO/Lrey/jU2/71EkvV/2Sl5Z+V1hMd55usO1prhTIFo6hOx/jyExg9Az1+nwe6rbHqm/PBZgAKaKfQ8UG8xQ== 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: Constify the flag tests that aren't automatically generated and the tests that look like flag tests but are more complicated. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: David Hildenbrand --- include/linux/page-flags.h | 52 +++++++++++++++++++------------------- mm/hugetlb.c | 4 +-- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 3463cd1baebf..652d77805e99 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -558,13 +558,13 @@ PAGEFLAG_FALSE(HighMem, highmem) #endif #ifdef CONFIG_SWAP -static __always_inline bool folio_test_swapcache(struct folio *folio) +static __always_inline bool folio_test_swapcache(const struct folio *folio) { return folio_test_swapbacked(folio) && - test_bit(PG_swapcache, folio_flags(folio, 0)); + test_bit(PG_swapcache, const_folio_flags(folio, 0)); } -static __always_inline bool PageSwapCache(struct page *page) +static __always_inline bool PageSwapCache(const struct page *page) { return folio_test_swapcache(page_folio(page)); } @@ -663,22 +663,22 @@ PAGEFLAG_FALSE(VmemmapSelfHosted, vmemmap_self_hosted) */ #define PAGE_MAPPING_DAX_SHARED ((void *)0x1) -static __always_inline bool folio_mapping_flags(struct folio *folio) +static __always_inline bool folio_mapping_flags(const struct folio *folio) { return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) != 0; } -static __always_inline int PageMappingFlags(struct page *page) +static __always_inline int PageMappingFlags(const struct page *page) { return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != 0; } -static __always_inline bool folio_test_anon(struct folio *folio) +static __always_inline bool folio_test_anon(const struct folio *folio) { return ((unsigned long)folio->mapping & PAGE_MAPPING_ANON) != 0; } -static __always_inline bool PageAnon(struct page *page) +static __always_inline bool PageAnon(const struct page *page) { return folio_test_anon(page_folio(page)); } @@ -689,7 +689,7 @@ static __always_inline bool __folio_test_movable(const struct folio *folio) PAGE_MAPPING_MOVABLE; } -static __always_inline int __PageMovable(struct page *page) +static __always_inline int __PageMovable(const struct page *page) { return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) == PAGE_MAPPING_MOVABLE; @@ -702,13 +702,13 @@ static __always_inline int __PageMovable(struct page *page) * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any * anon_vma, but to that page's node of the stable tree. */ -static __always_inline bool folio_test_ksm(struct folio *folio) +static __always_inline bool folio_test_ksm(const struct folio *folio) { return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) == PAGE_MAPPING_KSM; } -static __always_inline bool PageKsm(struct page *page) +static __always_inline bool PageKsm(const struct page *page) { return folio_test_ksm(page_folio(page)); } @@ -747,9 +747,9 @@ static inline bool folio_xor_flags_has_waiters(struct folio *folio, * some of the bytes in it may be; see the is_partially_uptodate() * address_space operation. */ -static inline bool folio_test_uptodate(struct folio *folio) +static inline bool folio_test_uptodate(const struct folio *folio) { - bool ret = test_bit(PG_uptodate, folio_flags(folio, 0)); + bool ret = test_bit(PG_uptodate, const_folio_flags(folio, 0)); /* * Must ensure that the data we read out of the folio is loaded * _after_ we've loaded folio->flags to check the uptodate bit. @@ -764,7 +764,7 @@ static inline bool folio_test_uptodate(struct folio *folio) return ret; } -static inline int PageUptodate(struct page *page) +static inline int PageUptodate(const struct page *page) { return folio_test_uptodate(page_folio(page)); } @@ -806,9 +806,9 @@ void set_page_writeback(struct page *page); #define folio_start_writeback_keepwrite(folio) \ __folio_start_writeback(folio, true) -static __always_inline bool folio_test_head(struct folio *folio) +static __always_inline bool folio_test_head(const struct folio *folio) { - return test_bit(PG_head, folio_flags(folio, FOLIO_PF_ANY)); + return test_bit(PG_head, const_folio_flags(folio, FOLIO_PF_ANY)); } static __always_inline int PageHead(const struct page *page) @@ -827,7 +827,7 @@ CLEARPAGEFLAG(Head, head, PF_ANY) * * Return: True if the folio is larger than one page. */ -static inline bool folio_test_large(struct folio *folio) +static inline bool folio_test_large(const struct folio *folio) { return folio_test_head(folio); } @@ -856,7 +856,7 @@ TESTPAGEFLAG_FALSE(LargeRmappable, large_rmappable) #define PG_head_mask ((1UL << PG_head)) #ifdef CONFIG_HUGETLB_PAGE -int PageHuge(struct page *page); +int PageHuge(const struct page *page); SETPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) CLEARPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) @@ -869,10 +869,10 @@ CLEARPAGEFLAG(HugeTLB, hugetlb, PF_SECOND) * Return: True for hugetlbfs folios, false for anon folios or folios * belonging to other filesystems. */ -static inline bool folio_test_hugetlb(struct folio *folio) +static inline bool folio_test_hugetlb(const struct folio *folio) { return folio_test_large(folio) && - test_bit(PG_hugetlb, folio_flags(folio, 1)); + test_bit(PG_hugetlb, const_folio_flags(folio, 1)); } #else TESTPAGEFLAG_FALSE(Huge, hugetlb) @@ -887,7 +887,7 @@ TESTPAGEFLAG_FALSE(Huge, hugetlb) * hugetlbfs pages, but not normal pages. PageTransHuge() can only be * called only in the core VM paths where hugetlbfs pages can't exist. */ -static inline int PageTransHuge(struct page *page) +static inline int PageTransHuge(const struct page *page) { VM_BUG_ON_PAGE(PageTail(page), page); return PageHead(page); @@ -898,7 +898,7 @@ static inline int PageTransHuge(struct page *page) * and hugetlbfs pages, so it should only be called when it's known * that hugetlbfs pages aren't involved. */ -static inline int PageTransCompound(struct page *page) +static inline int PageTransCompound(const struct page *page) { return PageCompound(page); } @@ -908,7 +908,7 @@ static inline int PageTransCompound(struct page *page) * and hugetlbfs pages, so it should only be called when it's known * that hugetlbfs pages aren't involved. */ -static inline int PageTransTail(struct page *page) +static inline int PageTransTail(const struct page *page) { return PageTail(page); } @@ -972,7 +972,7 @@ static inline int page_type_has_type(unsigned int page_type) return (int)page_type < PAGE_MAPCOUNT_RESERVE; } -static inline int page_has_type(struct page *page) +static inline int page_has_type(const struct page *page) { return page_type_has_type(page->page_type); } @@ -1056,7 +1056,7 @@ extern bool is_free_buddy_page(struct page *page); PAGEFLAG(Isolated, isolated, PF_ANY); -static __always_inline int PageAnonExclusive(struct page *page) +static __always_inline int PageAnonExclusive(const struct page *page) { VM_BUG_ON_PGFLAGS(!PageAnon(page), page); VM_BUG_ON_PGFLAGS(PageHuge(page) && !PageHead(page), page); @@ -1129,12 +1129,12 @@ static __always_inline void __ClearPageAnonExclusive(struct page *page) * Determine if a page has private stuff, indicating that release routines * should be invoked upon it. */ -static inline int page_has_private(struct page *page) +static inline int page_has_private(const struct page *page) { return !!(page->flags & PAGE_FLAGS_PRIVATE); } -static inline bool folio_has_private(struct folio *folio) +static inline bool folio_has_private(const struct folio *folio) { return page_has_private(&folio->page); } diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 418d66953224..bb17e5c22759 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2164,9 +2164,9 @@ static bool prep_compound_gigantic_folio_for_demote(struct folio *folio, * transparent huge pages. See the PageTransHuge() documentation for more * details. */ -int PageHuge(struct page *page) +int PageHuge(const struct page *page) { - struct folio *folio; + const struct folio *folio; if (!PageCompound(page)) return 0;