Skip to content

Commit fd1a745

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: support page_mapcount() on page_has_type() pages
Return 0 for pages which can't be mapped. This matches how page_mapped() works. It is more convenient for users to not have to filter out these pages. Link: https://lkml.kernel.org/r/[email protected] Fixes: 9c5ccf2 ("mm: remove HUGETLB_PAGE_DTOR") Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Miaohe Lin <[email protected]> Cc: Muchun Song <[email protected]> Cc: Oscar Salvador <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 12bbaae commit fd1a745

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

fs/proc/page.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
6767
*/
6868
ppage = pfn_to_online_page(pfn);
6969

70-
if (!ppage || PageSlab(ppage) || page_has_type(ppage))
70+
if (!ppage)
7171
pcount = 0;
7272
else
7373
pcount = page_mapcount(ppage);
@@ -124,11 +124,8 @@ u64 stable_page_flags(struct page *page)
124124

125125
/*
126126
* pseudo flags for the well known (anonymous) memory mapped pages
127-
*
128-
* Note that page->_mapcount is overloaded in SLAB, so the
129-
* simple test in page_mapped() is not enough.
130127
*/
131-
if (!PageSlab(page) && page_mapped(page))
128+
if (page_mapped(page))
132129
u |= 1 << KPF_MMAP;
133130
if (PageAnon(page))
134131
u |= 1 << KPF_ANON;

include/linux/mm.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,14 +1223,16 @@ static inline void page_mapcount_reset(struct page *page)
12231223
* a large folio, it includes the number of times this page is mapped
12241224
* as part of that folio.
12251225
*
1226-
* The result is undefined for pages which cannot be mapped into userspace.
1227-
* For example SLAB or special types of pages. See function page_has_type().
1228-
* They use this field in struct page differently.
1226+
* Will report 0 for pages which cannot be mapped into userspace, eg
1227+
* slab, page tables and similar.
12291228
*/
12301229
static inline int page_mapcount(struct page *page)
12311230
{
12321231
int mapcount = atomic_read(&page->_mapcount) + 1;
12331232

1233+
/* Handle page_has_type() pages */
1234+
if (mapcount < 0)
1235+
mapcount = 0;
12341236
if (unlikely(PageCompound(page)))
12351237
mapcount += folio_entire_mapcount(page_folio(page));
12361238

include/linux/page-flags.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,12 @@ static inline bool is_page_hwpoison(struct page *page)
971971
* page_type may be used. Because it is initialised to -1, we invert the
972972
* sense of the bit, so __SetPageFoo *clears* the bit used for PageFoo, and
973973
* __ClearPageFoo *sets* the bit used for PageFoo. We reserve a few high and
974-
* low bits so that an underflow or overflow of page_mapcount() won't be
974+
* low bits so that an underflow or overflow of _mapcount won't be
975975
* mistaken for a page type value.
976976
*/
977977

978978
#define PAGE_TYPE_BASE 0xf0000000
979-
/* Reserve 0x0000007f to catch underflows of page_mapcount */
979+
/* Reserve 0x0000007f to catch underflows of _mapcount */
980980
#define PAGE_MAPCOUNT_RESERVE -128
981981
#define PG_buddy 0x00000080
982982
#define PG_offline 0x00000100

0 commit comments

Comments
 (0)