Skip to content

Commit

Permalink
mm: mark pages in use for page tables
Browse files Browse the repository at this point in the history
Define a new PageTable bit in the page_type and use it to mark pages in
use as page tables.  This can be helpful when debugging crashdumps or
analysing memory fragmentation.  Add a KPF flag to report these pages to
userspace and update page-types.c to interpret that flag.

Note that only pages currently accounted as NR_PAGETABLES are tracked as
PageTable; this does not include pgd/p4d/pud/pmd pages.  Those will be the
subject of a later patch.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox <[email protected]>
Acked-by: Kirill A. Shutemov <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Jérôme Glisse <[email protected]>
Cc: Lai Jiangshan <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: Randy Dunlap <[email protected]>
Cc: Andrey Ryabinin <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Matthew Wilcox authored and torvalds committed Jun 8, 2018
1 parent 6e292b9 commit 1d40a5e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions fs/proc/page.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ u64 stable_page_flags(struct page *page)

if (PageBalloon(page))
u |= 1 << KPF_BALLOON;
if (PageTable(page))
u |= 1 << KPF_PGTABLE;

if (page_is_idle(page))
u |= 1 << KPF_IDLE;
Expand Down
2 changes: 2 additions & 0 deletions include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1851,13 +1851,15 @@ static inline bool pgtable_page_ctor(struct page *page)
{
if (!ptlock_init(page))
return false;
__SetPageTable(page);
inc_zone_page_state(page, NR_PAGETABLE);
return true;
}

static inline void pgtable_page_dtor(struct page *page)
{
pte_lock_deinit(page);
__ClearPageTable(page);
dec_zone_page_state(page, NR_PAGETABLE);
}

Expand Down
6 changes: 6 additions & 0 deletions include/linux/page-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ PAGEFLAG_FALSE(DoubleMap)
#define PG_buddy 0x00000080
#define PG_balloon 0x00000100
#define PG_kmemcg 0x00000200
#define PG_table 0x00000400

#define PageType(page, flag) \
((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
Expand Down Expand Up @@ -693,6 +694,11 @@ PAGE_TYPE_OPS(Balloon, balloon)
*/
PAGE_TYPE_OPS(Kmemcg, kmemcg)

/*
* Marks pages in use as page tables.
*/
PAGE_TYPE_OPS(Table, table)

extern bool is_free_buddy_page(struct page *page);

__PAGEFLAG(Isolated, isolated, PF_ANY);
Expand Down
2 changes: 1 addition & 1 deletion include/uapi/linux/kernel-page-flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
#define KPF_BALLOON 23
#define KPF_ZERO_PAGE 24
#define KPF_IDLE 25

#define KPF_PGTABLE 26

#endif /* _UAPILINUX_KERNEL_PAGE_FLAGS_H */
1 change: 1 addition & 0 deletions tools/vm/page-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ static const char * const page_flag_names[] = {
[KPF_KSM] = "x:ksm",
[KPF_THP] = "t:thp",
[KPF_BALLOON] = "o:balloon",
[KPF_PGTABLE] = "g:pgtable",
[KPF_ZERO_PAGE] = "z:zero_page",
[KPF_IDLE] = "i:idle_page",

Expand Down

0 comments on commit 1d40a5e

Please sign in to comment.