Skip to content

Commit dce088a

Browse files
Leo Yanacmel
authored andcommitted
perf kmem: Support field "node" in evsel__process_alloc_event() coping with recent tracepoint restructuring
Commit 11e9734 ("mm/slab_common: unify NUMA and UMA version of tracepoints") adds the field "node" into the tracepoints 'kmalloc' and 'kmem_cache_alloc', so this patch modifies the event process function to support the field "node". If field "node" is detected by checking function evsel__field(), it stats the cross allocation. When the "node" value is NUMA_NO_NODE (-1), it means the memory can be allocated from any memory node, in this case, we don't account it as a cross allocation. Fixes: 11e9734 ("mm/slab_common: unify NUMA and UMA version of tracepoints") Reported-by: Ravi Bangoria <[email protected]> Reviewed-by: James Clark <[email protected]> Signed-off-by: Leo Yan <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Hyeonggon Yoo <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Vlastimil Babka <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b371910 commit dce088a

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

tools/perf/builtin-kmem.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "util/string2.h"
2727

2828
#include <linux/kernel.h>
29+
#include <linux/numa.h>
2930
#include <linux/rbtree.h>
3031
#include <linux/string.h>
3132
#include <linux/zalloc.h>
@@ -185,22 +186,33 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s
185186
total_allocated += bytes_alloc;
186187

187188
nr_allocs++;
188-
return 0;
189-
}
190189

191-
static int evsel__process_alloc_node_event(struct evsel *evsel, struct perf_sample *sample)
192-
{
193-
int ret = evsel__process_alloc_event(evsel, sample);
190+
/*
191+
* Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA
192+
* version of tracepoints") adds the field "node" into the
193+
* tracepoints 'kmalloc' and 'kmem_cache_alloc'.
194+
*
195+
* The legacy tracepoints 'kmalloc_node' and 'kmem_cache_alloc_node'
196+
* also contain the field "node".
197+
*
198+
* If the tracepoint contains the field "node" the tool stats the
199+
* cross allocation.
200+
*/
201+
if (evsel__field(evsel, "node")) {
202+
int node1, node2;
194203

195-
if (!ret) {
196-
int node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}),
197-
node2 = evsel__intval(evsel, sample, "node");
204+
node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu});
205+
node2 = evsel__intval(evsel, sample, "node");
198206

199-
if (node1 != node2)
207+
/*
208+
* If the field "node" is NUMA_NO_NODE (-1), we don't take it
209+
* as a cross allocation.
210+
*/
211+
if ((node2 != NUMA_NO_NODE) && (node1 != node2))
200212
nr_cross_allocs++;
201213
}
202214

203-
return ret;
215+
return 0;
204216
}
205217

206218
static int ptr_cmp(void *, void *);
@@ -1369,8 +1381,8 @@ static int __cmd_kmem(struct perf_session *session)
13691381
/* slab allocator */
13701382
{ "kmem:kmalloc", evsel__process_alloc_event, },
13711383
{ "kmem:kmem_cache_alloc", evsel__process_alloc_event, },
1372-
{ "kmem:kmalloc_node", evsel__process_alloc_node_event, },
1373-
{ "kmem:kmem_cache_alloc_node", evsel__process_alloc_node_event, },
1384+
{ "kmem:kmalloc_node", evsel__process_alloc_event, },
1385+
{ "kmem:kmem_cache_alloc_node", evsel__process_alloc_event, },
13741386
{ "kmem:kfree", evsel__process_free_event, },
13751387
{ "kmem:kmem_cache_free", evsel__process_free_event, },
13761388
/* page allocator */

0 commit comments

Comments
 (0)