Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf kmem: Support field "node" in evsel__process_alloc_event() coping with recent tracepoint restructuring

Commit 11e9734bcb6a7361 ("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: 11e9734bcb6a7361 ("mm/slab_common: unify NUMA and UMA version of tracepoints")
Reported-by: Ravi Bangoria <ravi.bangoria@amd.com>
Reviewed-by: James Clark <james.clark@arm.com>
Signed-off-by: Leo Yan <leo.yan@linaro.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Link: https://lore.kernel.org/r/20230108062400.250690-2-leo.yan@linaro.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Leo Yan and committed by
Arnaldo Carvalho de Melo
dce088ab b3719108

+24 -12
+24 -12
tools/perf/builtin-kmem.c
··· 26 26 #include "util/string2.h" 27 27 28 28 #include <linux/kernel.h> 29 + #include <linux/numa.h> 29 30 #include <linux/rbtree.h> 30 31 #include <linux/string.h> 31 32 #include <linux/zalloc.h> ··· 186 185 total_allocated += bytes_alloc; 187 186 188 187 nr_allocs++; 189 - return 0; 190 - } 191 188 192 - static int evsel__process_alloc_node_event(struct evsel *evsel, struct perf_sample *sample) 193 - { 194 - int ret = evsel__process_alloc_event(evsel, sample); 189 + /* 190 + * Commit 11e9734bcb6a ("mm/slab_common: unify NUMA and UMA 191 + * version of tracepoints") adds the field "node" into the 192 + * tracepoints 'kmalloc' and 'kmem_cache_alloc'. 193 + * 194 + * The legacy tracepoints 'kmalloc_node' and 'kmem_cache_alloc_node' 195 + * also contain the field "node". 196 + * 197 + * If the tracepoint contains the field "node" the tool stats the 198 + * cross allocation. 199 + */ 200 + if (evsel__field(evsel, "node")) { 201 + int node1, node2; 195 202 196 - if (!ret) { 197 - int node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}), 198 - node2 = evsel__intval(evsel, sample, "node"); 203 + node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}); 204 + node2 = evsel__intval(evsel, sample, "node"); 199 205 200 - if (node1 != node2) 206 + /* 207 + * If the field "node" is NUMA_NO_NODE (-1), we don't take it 208 + * as a cross allocation. 209 + */ 210 + if ((node2 != NUMA_NO_NODE) && (node1 != node2)) 201 211 nr_cross_allocs++; 202 212 } 203 213 204 - return ret; 214 + return 0; 205 215 } 206 216 207 217 static int ptr_cmp(void *, void *); ··· 1381 1369 /* slab allocator */ 1382 1370 { "kmem:kmalloc", evsel__process_alloc_event, }, 1383 1371 { "kmem:kmem_cache_alloc", evsel__process_alloc_event, }, 1384 - { "kmem:kmalloc_node", evsel__process_alloc_node_event, }, 1385 - { "kmem:kmem_cache_alloc_node", evsel__process_alloc_node_event, }, 1372 + { "kmem:kmalloc_node", evsel__process_alloc_event, }, 1373 + { "kmem:kmem_cache_alloc_node", evsel__process_alloc_event, }, 1386 1374 { "kmem:kfree", evsel__process_free_event, }, 1387 1375 { "kmem:kmem_cache_free", evsel__process_free_event, }, 1388 1376 /* page allocator */