Commit 37389167 authored by Vlastimil Babka's avatar Vlastimil Babka Committed by Linus Torvalds

mm, page_owner: keep owner info when freeing the page

For debugging purposes it might be useful to keep the owner info even
after page has been freed, and include it in e.g.  dump_page() when
detecting a bad page state.  For that, change the PAGE_EXT_OWNER flag
meaning to "page owner info has been set at least once" and add new
PAGE_EXT_OWNER_ACTIVE for tracking whether page is supposed to be
currently tracked allocated or free.  Adjust dump_page() accordingly,
distinguishing free and allocated pages.  In the page_owner debugfs file,
keep printing only allocated pages so that existing scripts are not
confused, and also because free pages are irrelevant for the memory
statistics or leak detection that's the typical use case of the file,
anyway.

Link: http://lkml.kernel.org/r/20190820131828.22684-4-vbabka@suse.czSigned-off-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Kirill A. Shutemov <kirill@shutemov.name>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7e2f2a0c
...@@ -18,6 +18,7 @@ struct page_ext_operations { ...@@ -18,6 +18,7 @@ struct page_ext_operations {
enum page_ext_flags { enum page_ext_flags {
PAGE_EXT_OWNER, PAGE_EXT_OWNER,
PAGE_EXT_OWNER_ACTIVE,
#if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT) #if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT)
PAGE_EXT_YOUNG, PAGE_EXT_YOUNG,
PAGE_EXT_IDLE, PAGE_EXT_IDLE,
......
...@@ -111,7 +111,7 @@ void __reset_page_owner(struct page *page, unsigned int order) ...@@ -111,7 +111,7 @@ void __reset_page_owner(struct page *page, unsigned int order)
page_ext = lookup_page_ext(page + i); page_ext = lookup_page_ext(page + i);
if (unlikely(!page_ext)) if (unlikely(!page_ext))
continue; continue;
__clear_bit(PAGE_EXT_OWNER, &page_ext->flags); __clear_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags);
} }
} }
...@@ -168,6 +168,7 @@ static inline void __set_page_owner_handle(struct page *page, ...@@ -168,6 +168,7 @@ static inline void __set_page_owner_handle(struct page *page,
page_owner->gfp_mask = gfp_mask; page_owner->gfp_mask = gfp_mask;
page_owner->last_migrate_reason = -1; page_owner->last_migrate_reason = -1;
__set_bit(PAGE_EXT_OWNER, &page_ext->flags); __set_bit(PAGE_EXT_OWNER, &page_ext->flags);
__set_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags);
page_ext = lookup_page_ext(page + i); page_ext = lookup_page_ext(page + i);
} }
...@@ -243,6 +244,7 @@ void __copy_page_owner(struct page *oldpage, struct page *newpage) ...@@ -243,6 +244,7 @@ void __copy_page_owner(struct page *oldpage, struct page *newpage)
* the new page, which will be freed. * the new page, which will be freed.
*/ */
__set_bit(PAGE_EXT_OWNER, &new_ext->flags); __set_bit(PAGE_EXT_OWNER, &new_ext->flags);
__set_bit(PAGE_EXT_OWNER_ACTIVE, &new_ext->flags);
} }
void pagetypeinfo_showmixedcount_print(struct seq_file *m, void pagetypeinfo_showmixedcount_print(struct seq_file *m,
...@@ -302,7 +304,7 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m, ...@@ -302,7 +304,7 @@ void pagetypeinfo_showmixedcount_print(struct seq_file *m,
if (unlikely(!page_ext)) if (unlikely(!page_ext))
continue; continue;
if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) if (!test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags))
continue; continue;
page_owner = get_page_owner(page_ext); page_owner = get_page_owner(page_ext);
...@@ -413,21 +415,26 @@ void __dump_page_owner(struct page *page) ...@@ -413,21 +415,26 @@ void __dump_page_owner(struct page *page)
mt = gfpflags_to_migratetype(gfp_mask); mt = gfpflags_to_migratetype(gfp_mask);
if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) { if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
pr_alert("page_owner info is not active (free page?)\n"); pr_alert("page_owner info is not present (never set?)\n");
return; return;
} }
if (test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags))
pr_alert("page_owner tracks the page as allocated\n");
else
pr_alert("page_owner tracks the page as freed\n");
pr_alert("page last allocated via order %u, migratetype %s, gfp_mask %#x(%pGg)\n",
page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask);
handle = READ_ONCE(page_owner->handle); handle = READ_ONCE(page_owner->handle);
if (!handle) { if (!handle) {
pr_alert("page_owner info is not active (free page?)\n"); pr_alert("page_owner allocation stack trace missing\n");
return; } else {
nr_entries = stack_depot_fetch(handle, &entries);
stack_trace_print(entries, nr_entries, 0);
} }
nr_entries = stack_depot_fetch(handle, &entries);
pr_alert("page allocated via order %u, migratetype %s, gfp_mask %#x(%pGg)\n",
page_owner->order, migratetype_names[mt], gfp_mask, &gfp_mask);
stack_trace_print(entries, nr_entries, 0);
if (page_owner->last_migrate_reason != -1) if (page_owner->last_migrate_reason != -1)
pr_alert("page has been migrated, last migrate reason: %s\n", pr_alert("page has been migrated, last migrate reason: %s\n",
migrate_reason_names[page_owner->last_migrate_reason]); migrate_reason_names[page_owner->last_migrate_reason]);
...@@ -489,6 +496,13 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -489,6 +496,13 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags))
continue; continue;
/*
* Although we do have the info about past allocation of free
* pages, it's not relevant for current memory usage.
*/
if (!test_bit(PAGE_EXT_OWNER_ACTIVE, &page_ext->flags))
continue;
page_owner = get_page_owner(page_ext); page_owner = get_page_owner(page_ext);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment