From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <a.p.zijlstra@chello.nl>, Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>, David Ahern <dsahern@gmail.com>, Minchan Kim <minchan@kernel.org>, Joonsoo Kim <js1304@gmail.com>, linux-mm@kvack.org Subject: [PATCH 6/9] perf kmem: Add --live option for current allocation stat Date: Mon, 6 Apr 2015 14:36:13 +0900 [thread overview] Message-ID: <1428298576-9785-7-git-send-email-namhyung@kernel.org> (raw) In-Reply-To: <1428298576-9785-1-git-send-email-namhyung@kernel.org> Currently perf kmem shows total (page) allocation stat by default, but sometimes one might want to see live (total alloc-only) requests/pages only. The new --live option does this by subtracting freed allocation from the stat. Signed-off-by: Namhyung Kim <namhyung@kernel.org> --- tools/perf/Documentation/perf-kmem.txt | 5 ++ tools/perf/builtin-kmem.c | 103 ++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 39 deletions(-) diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt index 69e181272c51..ff0f433b3fce 100644 --- a/tools/perf/Documentation/perf-kmem.txt +++ b/tools/perf/Documentation/perf-kmem.txt @@ -56,6 +56,11 @@ OPTIONS --page:: Analyze page allocator events +--live:: + Show live page stat. The perf kmem shows total allocation stat by + default, but this option shows live (currently allocated) pages + instead. (This option works with --page option only) + SEE ALSO -------- linkperf:perf-record[1] diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 719aaf782116..3311ebdd4fb8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -244,6 +244,7 @@ static unsigned long nr_page_fails; static unsigned long nr_page_nomatch; static bool use_pfn; +static bool live_page; static struct perf_session *kmem_session; #define MAX_MIGRATE_TYPES 6 @@ -264,7 +265,7 @@ struct page_stat { int nr_free; }; -static struct rb_root page_tree; +static struct rb_root page_live_tree; static struct rb_root page_alloc_tree; static struct rb_root page_alloc_sorted; static struct rb_root page_caller_tree; @@ -398,10 +399,19 @@ static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample) return sample->ip; } +struct sort_dimension { + const char name[20]; + sort_fn_t cmp; + struct list_head list; +}; + +static LIST_HEAD(page_alloc_sort_input); +static LIST_HEAD(page_caller_sort_input); -static struct page_stat *search_page(u64 page, bool create) +static struct page_stat *search_page_live_stat(struct page_stat *this, + bool create) { - struct rb_node **node = &page_tree.rb_node; + struct rb_node **node = &page_live_tree.rb_node; struct rb_node *parent = NULL; struct page_stat *data; @@ -411,7 +421,7 @@ static struct page_stat *search_page(u64 page, bool create) parent = *node; data = rb_entry(*node, struct page_stat, node); - cmp = data->page - page; + cmp = data->page - this->page; if (cmp < 0) node = &parent->rb_left; else if (cmp > 0) @@ -425,24 +435,17 @@ static struct page_stat *search_page(u64 page, bool create) data = zalloc(sizeof(*data)); if (data != NULL) { - data->page = page; + data->page = this->page; + data->order = this->order; + data->migrate_type = this->migrate_type; + data->gfp_flags = this->gfp_flags; rb_link_node(&data->node, parent, node); - rb_insert_color(&data->node, &page_tree); + rb_insert_color(&data->node, &page_live_tree); } return data; } - -struct sort_dimension { - const char name[20]; - sort_fn_t cmp; - struct list_head list; -}; - -static LIST_HEAD(page_alloc_sort_input); -static LIST_HEAD(page_caller_sort_input); - static struct page_stat *search_page_alloc_stat(struct page_stat *this, bool create) { @@ -580,17 +583,8 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel, * This is to find the current page (with correct gfp flags and * migrate type) at free event. */ - stat = search_page(page, true); - if (stat == NULL) - return -ENOMEM; - - stat->order = order; - stat->gfp_flags = gfp_flags; - stat->migrate_type = migrate_type; - stat->callsite = callsite; - this.page = page; - stat = search_page_alloc_stat(&this, true); + stat = search_page_live_stat(&this, true); if (stat == NULL) return -ENOMEM; @@ -598,6 +592,16 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel, stat->alloc_bytes += bytes; stat->callsite = callsite; + if (!live_page) { + stat = search_page_alloc_stat(&this, true); + if (stat == NULL) + return -ENOMEM; + + stat->nr_alloc++; + stat->alloc_bytes += bytes; + stat->callsite = callsite; + } + this.callsite = callsite; stat = search_page_caller_stat(&this, true); if (stat == NULL) @@ -630,7 +634,8 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, nr_page_frees++; total_page_free_bytes += bytes; - stat = search_page(page, false); + this.page = page; + stat = search_page_live_stat(&this, false); if (stat == NULL) { pr_debug2("missing free at page %"PRIx64" (order: %d)\n", page, order); @@ -641,20 +646,23 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, return 0; } - this.page = page; this.gfp_flags = stat->gfp_flags; this.migrate_type = stat->migrate_type; this.callsite = stat->callsite; - rb_erase(&stat->node, &page_tree); + rb_erase(&stat->node, &page_live_tree); free(stat); - stat = search_page_alloc_stat(&this, false); - if (stat == NULL) - return -ENOENT; + if (live_page) { + order_stats[this.order][this.migrate_type]--; + } else { + stat = search_page_alloc_stat(&this, false); + if (stat == NULL) + return -ENOMEM; - stat->nr_free++; - stat->free_bytes += bytes; + stat->nr_free++; + stat->free_bytes += bytes; + } stat = search_page_caller_stat(&this, false); if (stat == NULL) @@ -663,6 +671,16 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, stat->nr_free++; stat->free_bytes += bytes; + if (live_page) { + stat->nr_alloc--; + stat->alloc_bytes -= bytes; + + if (stat->nr_alloc == 0) { + rb_erase(&stat->node, &page_caller_tree); + free(stat); + } + } + return 0; } @@ -780,8 +798,8 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines) const char *format; printf("\n%.105s\n", graph_dotted_line); - printf(" %-16s | Total alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", - use_pfn ? "PFN" : "Page"); + printf(" %-16s | %5s alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", + use_pfn ? "PFN" : "Page", live_page ? "Live" : "Total"); printf("%.105s\n", graph_dotted_line); if (use_pfn) @@ -825,7 +843,8 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines struct machine *machine = &session->machines.host; printf("\n%.105s\n", graph_dotted_line); - printf(" Total alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n"); + printf(" %5s alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", + live_page ? "Live" : "Total"); printf("%.105s\n", graph_dotted_line); while (next && n_lines--) { @@ -1050,8 +1069,13 @@ static void sort_result(void) &slab_caller_sort); } if (kmem_page) { - __sort_page_result(&page_alloc_tree, &page_alloc_sorted, - &page_alloc_sort); + if (live_page) + __sort_page_result(&page_live_tree, &page_alloc_sorted, + &page_alloc_sort); + else + __sort_page_result(&page_alloc_tree, &page_alloc_sorted, + &page_alloc_sort); + __sort_page_result(&page_caller_tree, &page_caller_sorted, &page_caller_sort); } @@ -1595,6 +1619,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) parse_slab_opt), OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator", parse_page_opt), + OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"), OPT_END() }; const char *const kmem_subcommands[] = { "record", "stat", NULL }; -- 2.3.2
WARNING: multiple messages have this Message-ID (diff)
From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org> Cc: Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <a.p.zijlstra@chello.nl>, Jiri Olsa <jolsa@redhat.com>, LKML <linux-kernel@vger.kernel.org>, David Ahern <dsahern@gmail.com>, Minchan Kim <minchan@kernel.org>, Joonsoo Kim <js1304@gmail.com>, linux-mm@kvack.org Subject: [PATCH 6/9] perf kmem: Add --live option for current allocation stat Date: Mon, 6 Apr 2015 14:36:13 +0900 [thread overview] Message-ID: <1428298576-9785-7-git-send-email-namhyung@kernel.org> (raw) In-Reply-To: <1428298576-9785-1-git-send-email-namhyung@kernel.org> Currently perf kmem shows total (page) allocation stat by default, but sometimes one might want to see live (total alloc-only) requests/pages only. The new --live option does this by subtracting freed allocation from the stat. Signed-off-by: Namhyung Kim <namhyung@kernel.org> --- tools/perf/Documentation/perf-kmem.txt | 5 ++ tools/perf/builtin-kmem.c | 103 ++++++++++++++++++++------------- 2 files changed, 69 insertions(+), 39 deletions(-) diff --git a/tools/perf/Documentation/perf-kmem.txt b/tools/perf/Documentation/perf-kmem.txt index 69e181272c51..ff0f433b3fce 100644 --- a/tools/perf/Documentation/perf-kmem.txt +++ b/tools/perf/Documentation/perf-kmem.txt @@ -56,6 +56,11 @@ OPTIONS --page:: Analyze page allocator events +--live:: + Show live page stat. The perf kmem shows total allocation stat by + default, but this option shows live (currently allocated) pages + instead. (This option works with --page option only) + SEE ALSO -------- linkperf:perf-record[1] diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index 719aaf782116..3311ebdd4fb8 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -244,6 +244,7 @@ static unsigned long nr_page_fails; static unsigned long nr_page_nomatch; static bool use_pfn; +static bool live_page; static struct perf_session *kmem_session; #define MAX_MIGRATE_TYPES 6 @@ -264,7 +265,7 @@ struct page_stat { int nr_free; }; -static struct rb_root page_tree; +static struct rb_root page_live_tree; static struct rb_root page_alloc_tree; static struct rb_root page_alloc_sorted; static struct rb_root page_caller_tree; @@ -398,10 +399,19 @@ static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample) return sample->ip; } +struct sort_dimension { + const char name[20]; + sort_fn_t cmp; + struct list_head list; +}; + +static LIST_HEAD(page_alloc_sort_input); +static LIST_HEAD(page_caller_sort_input); -static struct page_stat *search_page(u64 page, bool create) +static struct page_stat *search_page_live_stat(struct page_stat *this, + bool create) { - struct rb_node **node = &page_tree.rb_node; + struct rb_node **node = &page_live_tree.rb_node; struct rb_node *parent = NULL; struct page_stat *data; @@ -411,7 +421,7 @@ static struct page_stat *search_page(u64 page, bool create) parent = *node; data = rb_entry(*node, struct page_stat, node); - cmp = data->page - page; + cmp = data->page - this->page; if (cmp < 0) node = &parent->rb_left; else if (cmp > 0) @@ -425,24 +435,17 @@ static struct page_stat *search_page(u64 page, bool create) data = zalloc(sizeof(*data)); if (data != NULL) { - data->page = page; + data->page = this->page; + data->order = this->order; + data->migrate_type = this->migrate_type; + data->gfp_flags = this->gfp_flags; rb_link_node(&data->node, parent, node); - rb_insert_color(&data->node, &page_tree); + rb_insert_color(&data->node, &page_live_tree); } return data; } - -struct sort_dimension { - const char name[20]; - sort_fn_t cmp; - struct list_head list; -}; - -static LIST_HEAD(page_alloc_sort_input); -static LIST_HEAD(page_caller_sort_input); - static struct page_stat *search_page_alloc_stat(struct page_stat *this, bool create) { @@ -580,17 +583,8 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel, * This is to find the current page (with correct gfp flags and * migrate type) at free event. */ - stat = search_page(page, true); - if (stat == NULL) - return -ENOMEM; - - stat->order = order; - stat->gfp_flags = gfp_flags; - stat->migrate_type = migrate_type; - stat->callsite = callsite; - this.page = page; - stat = search_page_alloc_stat(&this, true); + stat = search_page_live_stat(&this, true); if (stat == NULL) return -ENOMEM; @@ -598,6 +592,16 @@ static int perf_evsel__process_page_alloc_event(struct perf_evsel *evsel, stat->alloc_bytes += bytes; stat->callsite = callsite; + if (!live_page) { + stat = search_page_alloc_stat(&this, true); + if (stat == NULL) + return -ENOMEM; + + stat->nr_alloc++; + stat->alloc_bytes += bytes; + stat->callsite = callsite; + } + this.callsite = callsite; stat = search_page_caller_stat(&this, true); if (stat == NULL) @@ -630,7 +634,8 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, nr_page_frees++; total_page_free_bytes += bytes; - stat = search_page(page, false); + this.page = page; + stat = search_page_live_stat(&this, false); if (stat == NULL) { pr_debug2("missing free at page %"PRIx64" (order: %d)\n", page, order); @@ -641,20 +646,23 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, return 0; } - this.page = page; this.gfp_flags = stat->gfp_flags; this.migrate_type = stat->migrate_type; this.callsite = stat->callsite; - rb_erase(&stat->node, &page_tree); + rb_erase(&stat->node, &page_live_tree); free(stat); - stat = search_page_alloc_stat(&this, false); - if (stat == NULL) - return -ENOENT; + if (live_page) { + order_stats[this.order][this.migrate_type]--; + } else { + stat = search_page_alloc_stat(&this, false); + if (stat == NULL) + return -ENOMEM; - stat->nr_free++; - stat->free_bytes += bytes; + stat->nr_free++; + stat->free_bytes += bytes; + } stat = search_page_caller_stat(&this, false); if (stat == NULL) @@ -663,6 +671,16 @@ static int perf_evsel__process_page_free_event(struct perf_evsel *evsel, stat->nr_free++; stat->free_bytes += bytes; + if (live_page) { + stat->nr_alloc--; + stat->alloc_bytes -= bytes; + + if (stat->nr_alloc == 0) { + rb_erase(&stat->node, &page_caller_tree); + free(stat); + } + } + return 0; } @@ -780,8 +798,8 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines) const char *format; printf("\n%.105s\n", graph_dotted_line); - printf(" %-16s | Total alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", - use_pfn ? "PFN" : "Page"); + printf(" %-16s | %5s alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", + use_pfn ? "PFN" : "Page", live_page ? "Live" : "Total"); printf("%.105s\n", graph_dotted_line); if (use_pfn) @@ -825,7 +843,8 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines struct machine *machine = &session->machines.host; printf("\n%.105s\n", graph_dotted_line); - printf(" Total alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n"); + printf(" %5s alloc (KB) | Hits | Order | Mig.type | GFP flags | Callsite\n", + live_page ? "Live" : "Total"); printf("%.105s\n", graph_dotted_line); while (next && n_lines--) { @@ -1050,8 +1069,13 @@ static void sort_result(void) &slab_caller_sort); } if (kmem_page) { - __sort_page_result(&page_alloc_tree, &page_alloc_sorted, - &page_alloc_sort); + if (live_page) + __sort_page_result(&page_live_tree, &page_alloc_sorted, + &page_alloc_sort); + else + __sort_page_result(&page_alloc_tree, &page_alloc_sorted, + &page_alloc_sort); + __sort_page_result(&page_caller_tree, &page_caller_sorted, &page_caller_sort); } @@ -1595,6 +1619,7 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused) parse_slab_opt), OPT_CALLBACK_NOOPT(0, "page", NULL, NULL, "Analyze page allocator", parse_page_opt), + OPT_BOOLEAN(0, "live", &live_page, "Show live page stat"), OPT_END() }; const char *const kmem_subcommands[] = { "record", "stat", NULL }; -- 2.3.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-04-06 5:39 UTC|newest] Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-04-06 5:36 [PATCHSET 0/9] perf kmem: Implement page allocation analysis (v6) Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-06 5:36 ` [PATCH 1/9] perf kmem: Respect -i option Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-08 15:11 ` [tip:perf/core] " tip-bot for Jiri Olsa 2015-04-06 5:36 ` [PATCH 2/9] tracing, mm: Record pfn instead of pointer to struct page Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-14 12:16 ` [tip:perf/urgent] " tip-bot for Namhyung Kim 2015-04-06 5:36 ` [PATCH 3/9] perf kmem: Analyze page allocator events also Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-10 21:06 ` Arnaldo Carvalho de Melo 2015-04-10 21:06 ` Arnaldo Carvalho de Melo 2015-04-10 21:10 ` Arnaldo Carvalho de Melo 2015-04-10 21:10 ` Arnaldo Carvalho de Melo 2015-04-13 6:59 ` Namhyung Kim 2015-04-13 6:59 ` Namhyung Kim 2015-04-13 13:21 ` Arnaldo Carvalho de Melo 2015-04-13 13:21 ` Arnaldo Carvalho de Melo 2015-04-13 13:40 ` Arnaldo Carvalho de Melo 2015-04-13 13:40 ` Arnaldo Carvalho de Melo 2015-04-14 12:17 ` [tip:perf/urgent] " tip-bot for Namhyung Kim 2015-04-06 5:36 ` [PATCH 4/9] perf kmem: Implement stat --page --caller Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-13 13:40 ` Arnaldo Carvalho de Melo 2015-04-13 13:40 ` Arnaldo Carvalho de Melo 2015-04-14 2:17 ` Namhyung Kim 2015-04-14 2:17 ` Namhyung Kim 2015-04-06 5:36 ` [PATCH 5/9] perf kmem: Support sort keys on page analysis Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim [this message] 2015-04-06 5:36 ` [PATCH 6/9] perf kmem: Add --live option for current allocation stat Namhyung Kim 2015-04-06 5:36 ` [PATCH 7/9] perf kmem: Print gfp flags in human readable string Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-06 5:36 ` [PATCH 8/9] perf kmem: Add kmem.default config option Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-06 5:36 ` [PATCH 9/9] tools lib traceevent: Honor operator priority Namhyung Kim 2015-04-06 5:36 ` Namhyung Kim 2015-04-06 14:45 ` Steven Rostedt 2015-04-06 14:45 ` Steven Rostedt 2015-04-07 7:52 ` Namhyung Kim 2015-04-07 7:52 ` Namhyung Kim 2015-04-07 13:02 ` Arnaldo Carvalho de Melo 2015-04-07 13:02 ` Arnaldo Carvalho de Melo 2015-04-07 13:57 ` Steven Rostedt 2015-04-07 13:57 ` Steven Rostedt 2015-04-07 14:10 ` Namhyung Kim 2015-04-07 14:10 ` Namhyung Kim 2015-04-08 15:11 ` [tip:perf/core] " tip-bot for Namhyung Kim 2015-04-13 13:41 ` [PATCH 9/9] " Arnaldo Carvalho de Melo 2015-04-13 13:41 ` Arnaldo Carvalho de Melo
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=1428298576-9785-7-git-send-email-namhyung@kernel.org \ --to=namhyung@kernel.org \ --cc=a.p.zijlstra@chello.nl \ --cc=acme@kernel.org \ --cc=dsahern@gmail.com \ --cc=jolsa@redhat.com \ --cc=js1304@gmail.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=minchan@kernel.org \ --cc=mingo@kernel.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.