Skip to content

Commit 144552f

Browse files
Anthony Yznagatorvalds
authored andcommitted
/proc/kpagecount: return 0 for special pages that are never mapped
Certain pages that are never mapped to userspace have a type indicated in the page_type field of their struct pages (e.g. PG_buddy). page_type overlaps with _mapcount so set the count to 0 and avoid calling page_mapcount() for these pages. [[email protected]: incorporate feedback from Matthew Wilcox] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Anthony Yznaga <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Acked-by: Matthew Wilcox <[email protected]> Reviewed-by: Naoya Horiguchi <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: David Rientjes <[email protected]> Cc: Alexey Dobriyan <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Alexander Duyck <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Miles Chen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent b6fb87b commit 144552f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

fs/proc/page.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
4646
ppage = pfn_to_page(pfn);
4747
else
4848
ppage = NULL;
49-
if (!ppage || PageSlab(ppage))
49+
if (!ppage || PageSlab(ppage) || page_has_type(ppage))
5050
pcount = 0;
5151
else
5252
pcount = page_mapcount(ppage);

include/linux/page-flags.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ PAGEFLAG_FALSE(DoubleMap)
669669

670670
#define PAGE_TYPE_BASE 0xf0000000
671671
/* Reserve 0x0000007f to catch underflows of page_mapcount */
672+
#define PAGE_MAPCOUNT_RESERVE -128
672673
#define PG_buddy 0x00000080
673674
#define PG_balloon 0x00000100
674675
#define PG_kmemcg 0x00000200
@@ -677,6 +678,11 @@ PAGEFLAG_FALSE(DoubleMap)
677678
#define PageType(page, flag) \
678679
((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
679680

681+
static inline int page_has_type(struct page *page)
682+
{
683+
return (int)page->page_type < PAGE_MAPCOUNT_RESERVE;
684+
}
685+
680686
#define PAGE_TYPE_OPS(uname, lname) \
681687
static __always_inline int Page##uname(struct page *page) \
682688
{ \

0 commit comments

Comments
 (0)