]> www.infradead.org Git - users/willy/xarray.git/commitdiff
mm: introduce page_mapcount_is_type()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Wed, 21 Aug 2024 17:39:10 +0000 (18:39 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Sep 2024 04:15:42 +0000 (21:15 -0700)
Resolve the awkward "and add one to this opaque constant" test into a
self-documenting inline function.

Link: https://lkml.kernel.org/r/20240821173914.2270383-3-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/internal.h
include/linux/mm.h
include/linux/page-flags.h

index a8a8576d8592e660fc88652ac973e972ab99996e..cc520168f8b699149cf5279d920ab95b8ffdf81c 100644 (file)
@@ -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);
index 0fde51c0532f212a783c3ff8239231442a9376f7..6f6053d7ea6f5c921aede242016f6783de85e606 100644 (file)
@@ -1228,8 +1228,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;
        }
index 2515ae85f191b338171484e609e2d0081e50b100..0b5484fdbca1a6ff577c5b5978d1b4098b5d9afa 100644 (file)
@@ -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));
 }