Skip to content

Commit 1d40a5e

Browse files
Matthew Wilcoxtorvalds
Matthew Wilcox
authored andcommitted
mm: mark pages in use for page tables
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]>
1 parent 6e292b9 commit 1d40a5e

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

fs/proc/page.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ u64 stable_page_flags(struct page *page)
154154

155155
if (PageBalloon(page))
156156
u |= 1 << KPF_BALLOON;
157+
if (PageTable(page))
158+
u |= 1 << KPF_PGTABLE;
157159

158160
if (page_is_idle(page))
159161
u |= 1 << KPF_IDLE;

include/linux/mm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,13 +1851,15 @@ static inline bool pgtable_page_ctor(struct page *page)
18511851
{
18521852
if (!ptlock_init(page))
18531853
return false;
1854+
__SetPageTable(page);
18541855
inc_zone_page_state(page, NR_PAGETABLE);
18551856
return true;
18561857
}
18571858

18581859
static inline void pgtable_page_dtor(struct page *page)
18591860
{
18601861
pte_lock_deinit(page);
1862+
__ClearPageTable(page);
18611863
dec_zone_page_state(page, NR_PAGETABLE);
18621864
}
18631865

include/linux/page-flags.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ PAGEFLAG_FALSE(DoubleMap)
655655
#define PG_buddy 0x00000080
656656
#define PG_balloon 0x00000100
657657
#define PG_kmemcg 0x00000200
658+
#define PG_table 0x00000400
658659

659660
#define PageType(page, flag) \
660661
((page->page_type & (PAGE_TYPE_BASE | flag)) == PAGE_TYPE_BASE)
@@ -693,6 +694,11 @@ PAGE_TYPE_OPS(Balloon, balloon)
693694
*/
694695
PAGE_TYPE_OPS(Kmemcg, kmemcg)
695696

697+
/*
698+
* Marks pages in use as page tables.
699+
*/
700+
PAGE_TYPE_OPS(Table, table)
701+
696702
extern bool is_free_buddy_page(struct page *page);
697703

698704
__PAGEFLAG(Isolated, isolated, PF_ANY);

include/uapi/linux/kernel-page-flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535
#define KPF_BALLOON 23
3636
#define KPF_ZERO_PAGE 24
3737
#define KPF_IDLE 25
38-
38+
#define KPF_PGTABLE 26
3939

4040
#endif /* _UAPILINUX_KERNEL_PAGE_FLAGS_H */

tools/vm/page-types.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static const char * const page_flag_names[] = {
131131
[KPF_KSM] = "x:ksm",
132132
[KPF_THP] = "t:thp",
133133
[KPF_BALLOON] = "o:balloon",
134+
[KPF_PGTABLE] = "g:pgtable",
134135
[KPF_ZERO_PAGE] = "z:zero_page",
135136
[KPF_IDLE] = "i:idle_page",
136137

0 commit comments

Comments
 (0)