Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1276391 > unrolled thread
| Started by | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| First post | 2015-11-24 13:40 +0100 |
| Last post | 2015-11-26 11:50 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() Vlastimil Babka <vbabka@suse.cz> - 2015-11-24 13:40 +0100
Re: [PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() Michal Hocko <mhocko@kernel.org> - 2015-11-25 16:00 +0100
Re: [PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() Vlastimil Babka <vbabka@suse.cz> - 2015-11-26 11:50 +0100
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2015-11-24 13:40 +0100 |
| Subject | [PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() |
| Message-ID | <qyl34-86O-15@gated-at.bofh.it> |
The page_owner mechanism is useful for dealing with memory leaks. By reading
/sys/kernel/debug/page_owner one can determine the stack traces leading to
allocations of all pages, and find e.g. a buggy driver.
This information might be also potentially useful for debugging, such as the
VM_BUG_ON_PAGE() calls to dump_page(). So let's print the stored info from
dump_page().
Example output:
page:ffffea0002868a00 count:1 mapcount:0 mapping:ffff8800bba8e958 index:0x63a22c
flags: 0x1fffff80000060(lru|active)
page dumped because: VM_BUG_ON_PAGE(1)
page->mem_cgroup:ffff880138efdc00
page allocated via order 0, migratetype Movable, gfp_mask 0x2420848(GFP_NOFS|GFP_NOFAIL|GFP_HARDWALL|GFP_MOVABLE)
[<ffffffff81164e8a>] __alloc_pages_nodemask+0x15a/0xa30
[<ffffffff811ab808>] alloc_pages_current+0x88/0x120
[<ffffffff8115bc36>] __page_cache_alloc+0xe6/0x120
[<ffffffff8115c226>] pagecache_get_page+0x56/0x200
[<ffffffff812058c2>] __getblk_slow+0xd2/0x2b0
[<ffffffff81205ae0>] __getblk_gfp+0x40/0x50
[<ffffffffa0283abe>] jbd2_journal_get_descriptor_buffer+0x3e/0x90 [jbd2]
[<ffffffffa027c793>] jbd2_journal_commit_transaction+0x8e3/0x1870 [jbd2]
page has been migrated, last migrate reason: compaction
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
---
include/linux/page_owner.h | 9 +++++++++
mm/debug.c | 2 ++
mm/page_alloc.c | 1 +
mm/page_owner.c | 25 +++++++++++++++++++++++++
4 files changed, 37 insertions(+)
diff --git a/include/linux/page_owner.h b/include/linux/page_owner.h
index 555893b..46f1b93 100644
--- a/include/linux/page_owner.h
+++ b/include/linux/page_owner.h
@@ -13,6 +13,7 @@ extern void __set_page_owner(struct page *page,
extern gfp_t __get_page_owner_gfp(struct page *page);
extern void __copy_page_owner(struct page *oldpage, struct page *newpage);
extern void __set_page_owner_migrate_reason(struct page *page, int reason);
+extern void __dump_page_owner(struct page *page);
static inline void reset_page_owner(struct page *page, unsigned int order)
{
@@ -44,6 +45,11 @@ static inline void set_page_owner_migrate_reason(struct page *page, int reason)
if (static_branch_unlikely(&page_owner_inited))
__set_page_owner_migrate_reason(page, reason);
}
+static inline void dump_page_owner(struct page *page)
+{
+ if (static_branch_unlikely(&page_owner_inited))
+ __dump_page_owner(page);
+}
#else
static inline void reset_page_owner(struct page *page, unsigned int order)
{
@@ -62,5 +68,8 @@ static inline void copy_page_owner(struct page *oldpage, struct page *newpage)
static inline void set_page_owner_migrate_reason(struct page *page, int reason)
{
}
+static inline void dump_page_owner(struct page *page)
+{
+}
#endif /* CONFIG_PAGE_OWNER */
#endif /* __LINUX_PAGE_OWNER_H */
diff --git a/mm/debug.c b/mm/debug.c
index 1a71a3b..c3300ee 100644
--- a/mm/debug.c
+++ b/mm/debug.c
@@ -10,6 +10,7 @@
#include <linux/trace_events.h>
#include <linux/memcontrol.h>
#include <trace/events/gfpflags.h>
+#include <linux/page_owner.h>
static const struct trace_print_flags pageflag_names[] = {
{1UL << PG_locked, "locked" },
@@ -118,6 +119,7 @@ void dump_page_badflags(struct page *page, const char *reason,
void dump_page(struct page *page, const char *reason)
{
dump_page_badflags(page, reason, 0);
+ dump_page_owner(page);
}
EXPORT_SYMBOL(dump_page);
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 61a023a..f806a1a 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -448,6 +448,7 @@ static void bad_page(struct page *page, const char *reason,
printk(KERN_ALERT "BUG: Bad page state in process %s pfn:%05lx\n",
current->comm, page_to_pfn(page));
dump_page_badflags(page, reason, bad_flags);
+ dump_page_owner(page);
print_modules();
dump_stack();
diff --git a/mm/page_owner.c b/mm/page_owner.c
index 59fd6f1..a81cfa0 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -193,6 +193,31 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
return -ENOMEM;
}
+void __dump_page_owner(struct page *page)
+{
+ struct page_ext *page_ext = lookup_page_ext(page);
+ struct stack_trace trace = {
+ .nr_entries = page_ext->nr_entries,
+ .entries = &page_ext->trace_entries[0],
+ };
+ gfp_t gfp_mask = page_ext->gfp_mask;
+ int mt = gfpflags_to_migratetype(gfp_mask);
+
+ if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
+ pr_alert("page_owner info is not active (free page?)\n");
+ return;
+ }
+ ;
+ pr_alert("page allocated via order %u, migratetype %s, gfp_mask 0x%x",
+ page_ext->order, migratetype_names[mt], gfp_mask);
+ dump_gfpflag_names(gfp_mask);
+ print_stack_trace(&trace, 0);
+
+ if (page_ext->last_migrate_reason != -1)
+ pr_alert("page has been migrated, last migrate reason: %s\n",
+ migrate_reason_names[page_ext->last_migrate_reason]);
+}
+
static ssize_t
read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
{
--
2.6.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2015-11-25 16:00 +0100 |
| Subject | Re: [PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() |
| Message-ID | <qyJI6-7CO-27@gated-at.bofh.it> |
| In reply to | #1276391 |
On Tue 24-11-15 13:36:19, Vlastimil Babka wrote:
> The page_owner mechanism is useful for dealing with memory leaks. By reading
> /sys/kernel/debug/page_owner one can determine the stack traces leading to
> allocations of all pages, and find e.g. a buggy driver.
>
> This information might be also potentially useful for debugging, such as the
> VM_BUG_ON_PAGE() calls to dump_page(). So let's print the stored info from
> dump_page().
>
> Example output:
>
> page:ffffea0002868a00 count:1 mapcount:0 mapping:ffff8800bba8e958 index:0x63a22c
> flags: 0x1fffff80000060(lru|active)
> page dumped because: VM_BUG_ON_PAGE(1)
> page->mem_cgroup:ffff880138efdc00
> page allocated via order 0, migratetype Movable, gfp_mask 0x2420848(GFP_NOFS|GFP_NOFAIL|GFP_HARDWALL|GFP_MOVABLE)
> [<ffffffff81164e8a>] __alloc_pages_nodemask+0x15a/0xa30
> [<ffffffff811ab808>] alloc_pages_current+0x88/0x120
> [<ffffffff8115bc36>] __page_cache_alloc+0xe6/0x120
> [<ffffffff8115c226>] pagecache_get_page+0x56/0x200
> [<ffffffff812058c2>] __getblk_slow+0xd2/0x2b0
> [<ffffffff81205ae0>] __getblk_gfp+0x40/0x50
> [<ffffffffa0283abe>] jbd2_journal_get_descriptor_buffer+0x3e/0x90 [jbd2]
> [<ffffffffa027c793>] jbd2_journal_commit_transaction+0x8e3/0x1870 [jbd2]
> page has been migrated, last migrate reason: compaction
Nice! This can be really helpful.
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Appart from a typo below, looks good to me
Acked-by: Michal Hocko <mhocko@suse.com>
[...]
> +void __dump_page_owner(struct page *page)
> +{
> + struct page_ext *page_ext = lookup_page_ext(page);
> + struct stack_trace trace = {
> + .nr_entries = page_ext->nr_entries,
> + .entries = &page_ext->trace_entries[0],
> + };
> + gfp_t gfp_mask = page_ext->gfp_mask;
> + int mt = gfpflags_to_migratetype(gfp_mask);
> +
> + if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
> + pr_alert("page_owner info is not active (free page?)\n");
> + return;
> + }
> + ;
Typo?
> + pr_alert("page allocated via order %u, migratetype %s, gfp_mask 0x%x",
> + page_ext->order, migratetype_names[mt], gfp_mask);
> + dump_gfpflag_names(gfp_mask);
> + print_stack_trace(&trace, 0);
> +
> + if (page_ext->last_migrate_reason != -1)
> + pr_alert("page has been migrated, last migrate reason: %s\n",
> + migrate_reason_names[page_ext->last_migrate_reason]);
> +}
> +
> static ssize_t
> read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
> {
> --
> 2.6.3
--
Michal Hocko
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Vlastimil Babka <vbabka@suse.cz> |
|---|---|
| Date | 2015-11-26 11:50 +0100 |
| Subject | Re: [PATCH v2 7/9] mm, page_owner: dump page owner info from dump_page() |
| Message-ID | <qz2hH-3Y1-13@gated-at.bofh.it> |
| In reply to | #1277448 |
On 11/25/2015 03:58 PM, Michal Hocko wrote:
> Nice! This can be really helpful.
>
>> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
>
> Appart from a typo below, looks good to me
> Acked-by: Michal Hocko <mhocko@suse.com>
Thanks!
> [...]
>
>> +void __dump_page_owner(struct page *page)
>> +{
>> + struct page_ext *page_ext = lookup_page_ext(page);
>> + struct stack_trace trace = {
>> + .nr_entries = page_ext->nr_entries,
>> + .entries = &page_ext->trace_entries[0],
>> + };
>> + gfp_t gfp_mask = page_ext->gfp_mask;
>> + int mt = gfpflags_to_migratetype(gfp_mask);
>> +
>> + if (!test_bit(PAGE_EXT_OWNER, &page_ext->flags)) {
>> + pr_alert("page_owner info is not active (free page?)\n");
>> + return;
>> + }
>> + ;
>
> Typo?
The cat did it!
------8<------
From: Vlastimil Babka <vbabka@suse.cz>
Date: Thu, 26 Nov 2015 11:41:11 +0100
Subject: mm, page_owner: dump page owner info from dump_page()-fix
Remove stray semicolon.
---
mm/page_owner.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mm/page_owner.c b/mm/page_owner.c
index a81cfa0c13c3..f4acd2452c35 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -207,7 +207,7 @@ void __dump_page_owner(struct page *page)
pr_alert("page_owner info is not active (free page?)\n");
return;
}
- ;
+
pr_alert("page allocated via order %u, migratetype %s, gfp_mask 0x%x",
page_ext->order, migratetype_names[mt], gfp_mask);
dump_gfpflag_names(gfp_mask);
--
2.6.3
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web