linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Minchan Kim <minchan@kernel.org>,
	Sasha Levin <sasha.levin@oracle.com>,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>,
	Mel Gorman <mgorman@suse.de>
Subject: Re: [PATCH 5/5] mm, page_owner: dump page owner info from dump_page()
Date: Wed, 4 Nov 2015 21:41:04 +0200	[thread overview]
Message-ID: <20151104194104.GB13303@node.shutemov.name> (raw)
In-Reply-To: <1446649261-27122-6-git-send-email-vbabka@suse.cz>

On Wed, Nov 04, 2015 at 04:01:01PM +0100, 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:
> 
> [  199.188777] page:ffffea0002900540 count:2 mapcount:0 mapping:ffff880131993e18 index:0x34e
> [  199.202832] flags: 0x1fffff80020048(uptodate|active|mappedtodisk)
> [  199.207048] page dumped because: VM_BUG_ON_PAGE(1)
> [  199.207048] page->mem_cgroup:ffff880138efdc00
> [  199.207050] page allocated via order 0, mask 0x213da, migratetype 2, trace:

Can we decode gfp_mask and migratetype into something more human readable?

> [  199.207050]  [<ffffffff811622c5>] __alloc_pages_nodemask+0x175/0x900
> [  199.207057]  [<ffffffff811a69c1>] alloc_pages_current+0x91/0x100
> [  199.207061]  [<ffffffff81158da1>] __page_cache_alloc+0xb1/0xf0
> [  199.207066]  [<ffffffff81165eeb>] __do_page_cache_readahead+0xdb/0x200
> [  199.207067]  [<ffffffff81166155>] ondemand_readahead+0x145/0x270
> [  199.207069]  [<ffffffff811662ec>] page_cache_async_readahead+0x6c/0x70
> [  199.207070]  [<ffffffff8115a838>] generic_file_read_iter+0x378/0x590
> [  199.207074]  [<ffffffff811cd2d7>] __vfs_read+0xa7/0xd0
> [  199.207074] page has been migrated, last migrate reason: 0

Same here.

> 
> Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> ---
>  include/linux/page_owner.h |  9 +++++++++
>  mm/debug.c                 |  2 ++
>  mm/page_owner.c            | 18 ++++++++++++++++++
>  3 files changed, 29 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 8362765..93373d1 100644
> --- a/mm/debug.c
> +++ b/mm/debug.c
> @@ -9,6 +9,7 @@
>  #include <linux/mm.h>
>  #include <linux/trace_events.h>
>  #include <linux/memcontrol.h>
> +#include <linux/page_owner.h>
>  
>  static const struct trace_print_flags pageflag_names[] = {
>  	{1UL << PG_locked,		"locked"	},
> @@ -98,6 +99,7 @@ void dump_page_badflags(struct page *page, const char *reason,
>  	if (page->mem_cgroup)
>  		pr_alert("page->mem_cgroup:%p\n", page->mem_cgroup);
>  #endif
> +	dump_page_owner(page);

I tend to put dump_page() into random places during debug. Dumping page
owner for all dump_page() cases can be too verbose.

Can we introduce dump_page_verbose() which would do usual dump_page() plus
dump_page_owner()?

>  }
>  
>  void dump_page(struct page *page, const char *reason)
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index 388898f..d7e0aaf 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -183,6 +183,24 @@ 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],
> +	};
> +
> +	pr_alert("page allocated via order %u, mask 0x%x, migratetype %d, trace:\n",
> +			page_ext->order, page_ext->gfp_mask,
> +			gfpflags_to_migratetype(page_ext->gfp_mask));
> +	print_stack_trace(&trace, 0);
> +
> +	if (page_ext->last_migrate_reason != -1)
> +		pr_alert("page has been migrated, last migrate reason: %d\n",
> +			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.2
> 
> --
> 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/

-- 
 Kirill A. Shutemov

  reply	other threads:[~2015-11-04 19:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-04 15:00 [PATCH 0/5] page_owner improvements for debugging Vlastimil Babka
2015-11-04 15:00 ` [PATCH 1/5] mm, page_owner: print migratetype of a page, not pageblock Vlastimil Babka
2015-11-05  8:09   ` Joonsoo Kim
2015-11-05  8:15     ` Vlastimil Babka
2015-11-05  8:19       ` Joonsoo Kim
2015-11-04 15:00 ` [PATCH 2/5] mm, page_owner: convert page_owner_inited to static key Vlastimil Babka
2015-11-04 15:00 ` [PATCH 3/5] mm, page_owner: copy page owner info during migration Vlastimil Babka
2015-11-04 15:10   ` checkpatch false warning. was: " Vlastimil Babka
2015-11-04 15:30     ` Joe Perches
2015-11-05  8:10   ` Joonsoo Kim
2015-11-05  8:17     ` Vlastimil Babka
2015-11-05  8:23       ` Joonsoo Kim
2015-11-08 21:29   ` Hugh Dickins
2015-11-19 16:44     ` Vlastimil Babka
2015-11-04 15:01 ` [PATCH 4/5] mm, page_owner: track last migrate reason Vlastimil Babka
2015-11-04 15:01 ` [PATCH 5/5] mm, page_owner: dump page owner info from dump_page() Vlastimil Babka
2015-11-04 19:41   ` Kirill A. Shutemov [this message]
2015-11-04 20:12     ` Sasha Levin
2015-11-04 20:41       ` Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151104194104.GB13303@node.shutemov.name \
    --to=kirill@shutemov.name \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=minchan@kernel.org \
    --cc=sasha.levin@oracle.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).