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: Re: [PATCH 4/9] perf kmem: Implement stat --page --caller Date: Tue, 14 Apr 2015 11:17:06 +0900 [thread overview] Message-ID: <20150414021706.GI23913@sejong> (raw) In-Reply-To: <20150413134024.GD3200@kernel.org> Hi Arnaldo, On Mon, Apr 13, 2015 at 10:40:24AM -0300, Arnaldo Carvalho de Melo wrote: > Em Mon, Apr 06, 2015 at 02:36:11PM +0900, Namhyung Kim escreveu: > > +static int build_alloc_func_list(void) > > +{ > > + int ret; > > + struct map *kernel_map; > > + struct symbol *sym; > > + struct rb_node *node; > > + struct alloc_func *func; > > + struct machine *machine = &kmem_session->machines.host; > > + > > Why having a blank like here? Will remove. > > > + regex_t alloc_func_regex; > > + const char pattern[] = "^_?_?(alloc|get_free|get_zeroed)_pages?"; > > + > > + ret = regcomp(&alloc_func_regex, pattern, REG_EXTENDED); > > + if (ret) { > > + char err[BUFSIZ]; > > + > > + regerror(ret, &alloc_func_regex, err, sizeof(err)); > > + pr_err("Invalid regex: %s\n%s", pattern, err); > > + return -EINVAL; > > + } > > + > > + kernel_map = machine->vmlinux_maps[MAP__FUNCTION]; > > + map__load(kernel_map, NULL); > > What if the map can't be loaded? Hmm.. yes, I need to check the return code. > > > + > > + map__for_each_symbol(kernel_map, sym, node) { > > + if (regexec(&alloc_func_regex, sym->name, 0, NULL, 0)) > > + continue; > > + > > + func = realloc(alloc_func_list, > > + (nr_alloc_funcs + 1) * sizeof(*func)); > > + if (func == NULL) > > + return -ENOMEM; > > + > > + pr_debug("alloc func: %s\n", sym->name); > > + func[nr_alloc_funcs].start = sym->start; > > + func[nr_alloc_funcs].end = sym->end; > > + func[nr_alloc_funcs].name = sym->name; > > + > > + alloc_func_list = func; > > + nr_alloc_funcs++; > > + } > > + > > + qsort(alloc_func_list, nr_alloc_funcs, sizeof(*func), funcmp); > > + > > + regfree(&alloc_func_regex); > > + return 0; > > +} > > + > > +/* > > + * Find first non-memory allocation function from callchain. > > + * The allocation functions are in the 'alloc_func_list'. > > + */ > > +static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample) > > +{ > > + struct addr_location al; > > + struct machine *machine = &kmem_session->machines.host; > > + struct callchain_cursor_node *node; > > + > > + if (alloc_func_list == NULL) > > + build_alloc_func_list(); And here too.. > > + > > + al.thread = machine__findnew_thread(machine, sample->pid, sample->tid); > > + sample__resolve_callchain(sample, NULL, evsel, &al, 16); > > + > > + callchain_cursor_commit(&callchain_cursor); > > + while (true) { > > + struct alloc_func key, *caller; > > + u64 addr; > > + > > + node = callchain_cursor_current(&callchain_cursor); > > + if (node == NULL) > > + break; > > + > > + key.start = key.end = node->ip; > > + caller = bsearch(&key, alloc_func_list, nr_alloc_funcs, > > + sizeof(key), callcmp); > > + if (!caller) { > > + /* found */ > > + if (node->map) > > + addr = map__unmap_ip(node->map, node->ip); > > + else > > + addr = node->ip; > > + > > + return addr; > > + } else > > + pr_debug3("skipping alloc function: %s\n", caller->name); > > + > > + callchain_cursor_advance(&callchain_cursor); > > + } > > + > > + pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip); > > + return sample->ip; > > +} > > + > > +static struct page_stat *search_page(u64 page, bool create) > > { > > struct rb_node **node = &page_tree.rb_node; > > struct rb_node *parent = NULL; > > @@ -357,6 +491,41 @@ static struct page_stat *search_page_alloc_stat(struct page_stat *stat, bool cre > > return data; > > } > > > > +static struct page_stat *search_page_caller_stat(u64 callsite, bool create) > > +{ > > + struct rb_node **node = &page_caller_tree.rb_node; > > + struct rb_node *parent = NULL; > > + struct page_stat *data; > > Please use the "findnew" idiom to name this function, looking at only > its name one things it searches a tree, a read only operation, but it > may insert elements too, a modify operation. > > Since we use the findnew idiom elsewhere for operations that do that, > i.e. optimize the "new" part of "findnew" by using the "find" part, > please use it here as well. OK. Will change and resend v7 soon. Thanks for your review! Namhyung
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: Re: [PATCH 4/9] perf kmem: Implement stat --page --caller Date: Tue, 14 Apr 2015 11:17:06 +0900 [thread overview] Message-ID: <20150414021706.GI23913@sejong> (raw) In-Reply-To: <20150413134024.GD3200@kernel.org> Hi Arnaldo, On Mon, Apr 13, 2015 at 10:40:24AM -0300, Arnaldo Carvalho de Melo wrote: > Em Mon, Apr 06, 2015 at 02:36:11PM +0900, Namhyung Kim escreveu: > > +static int build_alloc_func_list(void) > > +{ > > + int ret; > > + struct map *kernel_map; > > + struct symbol *sym; > > + struct rb_node *node; > > + struct alloc_func *func; > > + struct machine *machine = &kmem_session->machines.host; > > + > > Why having a blank like here? Will remove. > > > + regex_t alloc_func_regex; > > + const char pattern[] = "^_?_?(alloc|get_free|get_zeroed)_pages?"; > > + > > + ret = regcomp(&alloc_func_regex, pattern, REG_EXTENDED); > > + if (ret) { > > + char err[BUFSIZ]; > > + > > + regerror(ret, &alloc_func_regex, err, sizeof(err)); > > + pr_err("Invalid regex: %s\n%s", pattern, err); > > + return -EINVAL; > > + } > > + > > + kernel_map = machine->vmlinux_maps[MAP__FUNCTION]; > > + map__load(kernel_map, NULL); > > What if the map can't be loaded? Hmm.. yes, I need to check the return code. > > > + > > + map__for_each_symbol(kernel_map, sym, node) { > > + if (regexec(&alloc_func_regex, sym->name, 0, NULL, 0)) > > + continue; > > + > > + func = realloc(alloc_func_list, > > + (nr_alloc_funcs + 1) * sizeof(*func)); > > + if (func == NULL) > > + return -ENOMEM; > > + > > + pr_debug("alloc func: %s\n", sym->name); > > + func[nr_alloc_funcs].start = sym->start; > > + func[nr_alloc_funcs].end = sym->end; > > + func[nr_alloc_funcs].name = sym->name; > > + > > + alloc_func_list = func; > > + nr_alloc_funcs++; > > + } > > + > > + qsort(alloc_func_list, nr_alloc_funcs, sizeof(*func), funcmp); > > + > > + regfree(&alloc_func_regex); > > + return 0; > > +} > > + > > +/* > > + * Find first non-memory allocation function from callchain. > > + * The allocation functions are in the 'alloc_func_list'. > > + */ > > +static u64 find_callsite(struct perf_evsel *evsel, struct perf_sample *sample) > > +{ > > + struct addr_location al; > > + struct machine *machine = &kmem_session->machines.host; > > + struct callchain_cursor_node *node; > > + > > + if (alloc_func_list == NULL) > > + build_alloc_func_list(); And here too.. > > + > > + al.thread = machine__findnew_thread(machine, sample->pid, sample->tid); > > + sample__resolve_callchain(sample, NULL, evsel, &al, 16); > > + > > + callchain_cursor_commit(&callchain_cursor); > > + while (true) { > > + struct alloc_func key, *caller; > > + u64 addr; > > + > > + node = callchain_cursor_current(&callchain_cursor); > > + if (node == NULL) > > + break; > > + > > + key.start = key.end = node->ip; > > + caller = bsearch(&key, alloc_func_list, nr_alloc_funcs, > > + sizeof(key), callcmp); > > + if (!caller) { > > + /* found */ > > + if (node->map) > > + addr = map__unmap_ip(node->map, node->ip); > > + else > > + addr = node->ip; > > + > > + return addr; > > + } else > > + pr_debug3("skipping alloc function: %s\n", caller->name); > > + > > + callchain_cursor_advance(&callchain_cursor); > > + } > > + > > + pr_debug2("unknown callsite: %"PRIx64 "\n", sample->ip); > > + return sample->ip; > > +} > > + > > +static struct page_stat *search_page(u64 page, bool create) > > { > > struct rb_node **node = &page_tree.rb_node; > > struct rb_node *parent = NULL; > > @@ -357,6 +491,41 @@ static struct page_stat *search_page_alloc_stat(struct page_stat *stat, bool cre > > return data; > > } > > > > +static struct page_stat *search_page_caller_stat(u64 callsite, bool create) > > +{ > > + struct rb_node **node = &page_caller_tree.rb_node; > > + struct rb_node *parent = NULL; > > + struct page_stat *data; > > Please use the "findnew" idiom to name this function, looking at only > its name one things it searches a tree, a read only operation, but it > may insert elements too, a modify operation. > > Since we use the findnew idiom elsewhere for operations that do that, > i.e. optimize the "new" part of "findnew" by using the "find" part, > please use it here as well. OK. Will change and resend v7 soon. Thanks for your review! Namhyung -- 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-14 2:22 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 [this message] 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 ` [PATCH 6/9] perf kmem: Add --live option for current allocation stat Namhyung Kim 2015-04-06 5:36 ` 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=20150414021706.GI23913@sejong \ --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.