From patchwork Wed Aug 21 17:39:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13771935 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 080C0C52D7C for ; Wed, 21 Aug 2024 17:39:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 189A36B0168; Wed, 21 Aug 2024 13:39:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EAA96B016A; Wed, 21 Aug 2024 13:39:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EF5946B016B; Wed, 21 Aug 2024 13:39:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C9C126B0168 for ; Wed, 21 Aug 2024 13:39:32 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 89FB340517 for ; Wed, 21 Aug 2024 17:39:32 +0000 (UTC) X-FDA: 82476964584.30.1E9880A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf19.hostedemail.com (Postfix) with ESMTP id DB8CC1A0002 for ; Wed, 21 Aug 2024 17:39:30 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HmrbttBd; 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=1724261954; 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=UxIoSp9JEZWib8zcfiFfoEXleyGuw9ixgY5suc0x7jk=; b=40X+LMe69iaSo0B6Co7H99nwJuFvsKsphx+qzSJQg5G9NaIdzLR3vZJyZxXgm1337jbQln k4YytLqMSH3w3SExPje6aOAX+6q6jkulC481MvYtiz1bZ0b12sng5FxaXYRvvilWXBWQmo I11zjixUMngiXbytnmzyi+Fv8NxnxZw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=HmrbttBd; 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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724261954; a=rsa-sha256; cv=none; b=EzzSOK4Nutkt3lE0vLjTwlo2IFzCjNcwoSgEGFMjy0NOZbNBNAH2llev9FQedjl0P+PNJq 5lQbjpz0mg8r7elWUNxcUVJRMsQqpJRHcMfa+Ty4NrFy+7wIkZ2TpdgbmGmDNwj/ZnHWmh 36sw/5u9lQTwUVZqlk8H2PqD/OpXZMc= 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=UxIoSp9JEZWib8zcfiFfoEXleyGuw9ixgY5suc0x7jk=; b=HmrbttBdREjF8300bxxNoLyjFi IPd+vfBfYy6+LI/HzZTXl8HV+e1O6eA1D7kbRShruKCyveGUH+FhJauUW2qoV+FVBmJre7AjjA2vc 5cXtGv8HM6bFQ/ROvjL+PNk68YjWK7ze61xigf2dvlwxQLSlKcU8hlfYEuLOKCUJCUNuUURUyNBJ0 vr6h/zPVJDHKJOdvN4XTiK0pRU1cPL3HCg6lOEly07gHqUI7YKnKL7zKC+OFHJoccis45MUGg9Yly YIxaXHX9JCjA9lPI3+DTRPBMvEgB27rS3P6gmVqg/N91q8dE6Ugtfoh7WaO4B3OuAnJ0ek+ZjRfZ5 LLnc5QDA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgpIi-00000009WdK-18AI; Wed, 21 Aug 2024 17:39:16 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , David Hildenbrand , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Kent Overstreet Subject: [PATCH 2/4] mm: Introduce page_mapcount_is_type() Date: Wed, 21 Aug 2024 18:39:10 +0100 Message-ID: <20240821173914.2270383-3-willy@infradead.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240821173914.2270383-1-willy@infradead.org> References: <20240821173914.2270383-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: a58uzxcq6gpsws67q4wi8gjmfpd7wdrw X-Rspamd-Queue-Id: DB8CC1A0002 X-Rspamd-Server: rspam11 X-HE-Tag: 1724261970-280940 X-HE-Meta: U2FsdGVkX1/b/tYq0j7C2K23fXnbqGiiLKARu9nwUedS8P3ODdunjHrGC32Q5Ceoy+sSrFG/vn+xHznZXQqjOhC6IutevrDqrxdC2cQRZvsNPZwKXiecaP3tEbFa4Kd9hRWk+QFPPngaRGYJOEOiMjVJFJnCdrVJGgvBEwXwmNa5fR41trNeEpnqNFCcGnYEKMkyr4AypiOD7fJiAhVew9Fmr4oJh2SSysK/6hiWVrxaNsyOZKtKVV2zf/eVNMCXBp78GyTV5fKrQzw4Ylie10pQNyL7kh74h9Dx/wfHrB7yeht/VVR3qn2u4UKPOmr22Xi43R7NB09Vr+mp7pnZgNQ6a46QbVQM5tXh3kpZb5axJWaxsn5ioErFALfWl+TuVpjTIEMrNwzbSEAc2yuWk45li344qMBDfJWvhkgFOopswn0phFDklIp1CEId8GHecd81g8VdHGnIN7HmHOJxLkjQD0NrStOlJc6EV41Lvvw/AFcSPMNFcgb7PSKhnlycbFH6MPl3NtGGcbwM2jTDLG/Kkn/PD5j0Rjng4iAS4/LTJiw+cg36kBwVhbmRBe1BcGb9IIZl3IFNiA4A3H7U0ba7eaux66FpBX9tA21fL1h1vYIUA9wNbKDmiKkRGOhcvdI3HDwRK7z/fkdmjZMtt1CMaZVQy9+pOyHracHnoB4FiM8P5QDIwy9pJt6173OQd6MiGfJupzziVhNymABTguKMXUxSvkiMwtRib48+DigKwY8eciCuxId4m0WIAewMcycAXHHLunZacZAUvd+Z8lsmN4cIoOq568y7PrKZI5uqyivhhM2EkXCoRWpvkZ9khwujwlmL0JKIw0s78mKDzztH9GL+d0N4cpCrP5ZSR2q2axJAs1VLb21tECBZHaFtaS9KSHxVAY2yaphL3oWXAkVgwivhqRRZAvzP4kNf5XFDVXcGGh2Bk8tDTMUs8dTI+YafAmspPTV50ek03Cg gI69h05h 00fF4JTDdLVBpJxlXxAZ8bUlXOmq7+3B5AgI5p73mu3SQPNKE1QLm1Tc+2XbxwRhEdj78vdhdw1xIpdMOXpB8cfLdJXpI/fIadyooO8kxM7YXr4PB9GAcPjYkjZidFv4rAzwOC3dVKEIXvriesR8tssaHWmJ8vAQy3+xEB9cjBBEGEzeDjkVUpPjUp/e66AT+s2gwYi5osgheMofvb02KF/z33lj/yLa193BpAzFZkwcQw0fYtalPuBiRMftlvcIaycSgZlm7aMvipzfAfWV7iFRcRJXnSivZRYaAVcjRcwqub7NTFswLoXMqUlHcbOEm+pwu5lbdpyefBvs= 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: Resolve the awkward "and add one to this opaque constant" test into a self-documenting inline function. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: David Hildenbrand --- fs/proc/internal.h | 3 +-- include/linux/mm.h | 3 +-- include/linux/page-flags.h | 12 +++++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fs/proc/internal.h b/fs/proc/internal.h index a8a8576d8592..cc520168f8b6 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -166,8 +166,7 @@ static inline int folio_precise_page_mapcount(struct folio *folio, { int mapcount = atomic_read(&page->_mapcount) + 1; - /* Handle page_has_type() pages */ - if (mapcount < PAGE_MAPCOUNT_RESERVE + 1) + if (page_mapcount_is_type(mapcount)) mapcount = 0; if (folio_test_large(folio)) mapcount += folio_entire_mapcount(folio); diff --git a/include/linux/mm.h b/include/linux/mm.h index 00501f85f45f..47aa932075a8 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1232,8 +1232,7 @@ static inline int folio_mapcount(const struct folio *folio) if (likely(!folio_test_large(folio))) { mapcount = atomic_read(&folio->_mapcount) + 1; - /* Handle page_has_type() pages */ - if (mapcount < PAGE_MAPCOUNT_RESERVE + 1) + if (page_mapcount_is_type(mapcount)) mapcount = 0; return mapcount; } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 17175a328e6b..998a99441e4f 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -956,12 +956,18 @@ enum pagetype { #define folio_test_type(folio, flag) \ ((READ_ONCE(folio->page.page_type) & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE) -static inline int page_type_has_type(unsigned int page_type) +static inline bool page_type_has_type(int page_type) { - return (int)page_type < PAGE_MAPCOUNT_RESERVE; + return page_type < PAGE_MAPCOUNT_RESERVE; } -static inline int page_has_type(const struct page *page) +/* This takes a mapcount which is one more than page->_mapcount */ +static inline bool page_mapcount_is_type(unsigned int mapcount) +{ + return page_type_has_type(mapcount - 1); +} + +static inline bool page_has_type(const struct page *page) { return page_type_has_type(READ_ONCE(page->page_type)); }