Skip to content

Commit e880034

Browse files
Matthew Wilcox (Oracle)akpm00
Matthew Wilcox (Oracle)
authored andcommitted
mm: introduce page_mapcount_is_type()
Resolve the awkward "and add one to this opaque constant" test into a self-documenting inline function. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Acked-by: David Hildenbrand <[email protected]> Cc: Hyeonggon Yoo <[email protected]> Cc: Kent Overstreet <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e27ad65 commit e880034

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

fs/proc/internal.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ static inline int folio_precise_page_mapcount(struct folio *folio,
166166
{
167167
int mapcount = atomic_read(&page->_mapcount) + 1;
168168

169-
/* Handle page_has_type() pages */
170-
if (mapcount < PAGE_MAPCOUNT_RESERVE + 1)
169+
if (page_mapcount_is_type(mapcount))
171170
mapcount = 0;
172171
if (folio_test_large(folio))
173172
mapcount += folio_entire_mapcount(folio);

include/linux/mm.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -1228,8 +1228,7 @@ static inline int folio_mapcount(const struct folio *folio)
12281228

12291229
if (likely(!folio_test_large(folio))) {
12301230
mapcount = atomic_read(&folio->_mapcount) + 1;
1231-
/* Handle page_has_type() pages */
1232-
if (mapcount < PAGE_MAPCOUNT_RESERVE + 1)
1231+
if (page_mapcount_is_type(mapcount))
12331232
mapcount = 0;
12341233
return mapcount;
12351234
}

include/linux/page-flags.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -956,12 +956,18 @@ enum pagetype {
956956
#define folio_test_type(folio, flag) \
957957
((READ_ONCE(folio->page.page_type) & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
958958

959-
static inline int page_type_has_type(unsigned int page_type)
959+
static inline bool page_type_has_type(int page_type)
960960
{
961-
return (int)page_type < PAGE_MAPCOUNT_RESERVE;
961+
return page_type < PAGE_MAPCOUNT_RESERVE;
962962
}
963963

964-
static inline int page_has_type(const struct page *page)
964+
/* This takes a mapcount which is one more than page->_mapcount */
965+
static inline bool page_mapcount_is_type(unsigned int mapcount)
966+
{
967+
return page_type_has_type(mapcount - 1);
968+
}
969+
970+
static inline bool page_has_type(const struct page *page)
965971
{
966972
return page_type_has_type(READ_ONCE(page->page_type));
967973
}

0 commit comments

Comments
 (0)