From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
David Hildenbrand <david@redhat.com>,
Hyeonggon Yoo <42.hyeyoo@gmail.com>,
linux-mm@kvack.org, Kent Overstreet <kent.overstreet@linux.dev>
Subject: [PATCH 2/4] mm: Introduce page_mapcount_is_type()
Date: Wed, 21 Aug 2024 18:39:10 +0100 [thread overview]
Message-ID: <20240821173914.2270383-3-willy@infradead.org> (raw)
In-Reply-To: <20240821173914.2270383-1-willy@infradead.org>
Resolve the awkward "and add one to this opaque constant" test into a
self-documenting inline function.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
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));
}
--
2.43.0
next prev parent reply other threads:[~2024-08-21 17:39 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 17:39 [PATCH 0/4] Increase the number of bits available in page_type Matthew Wilcox (Oracle)
2024-08-21 17:39 ` [PATCH 1/4] printf: Remove %pGt support Matthew Wilcox (Oracle)
2024-08-21 21:00 ` David Hildenbrand
2024-08-21 21:08 ` Matthew Wilcox
2024-08-21 17:39 ` Matthew Wilcox (Oracle) [this message]
2024-08-21 21:01 ` [PATCH 2/4] mm: Introduce page_mapcount_is_type() David Hildenbrand
2024-08-21 17:39 ` [PATCH 3/4] mm: Support only one page_type per page Matthew Wilcox (Oracle)
2024-08-21 21:05 ` David Hildenbrand
2024-08-28 3:35 ` Kefeng Wang
2025-08-01 2:43 ` Matthew Wilcox
2025-08-01 2:49 ` Kent Overstreet
2025-08-01 8:13 ` Kefeng Wang
2025-08-01 14:27 ` Matthew Wilcox
2025-08-02 2:00 ` Kefeng Wang
2024-08-21 17:39 ` [PATCH 4/4] zsmalloc: Use all available 24 bits of page_type Matthew Wilcox (Oracle)
2024-08-21 21:06 ` David Hildenbrand
2024-08-21 21:15 ` [PATCH 0/4] Increase the number of bits available in page_type Kent Overstreet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240821173914.2270383-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=42.hyeyoo@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox