Skip to content

Commit 44d462a

Browse files
Alexey Budankovacmel
authored andcommitted
perf record: Fix binding of AIO user space buffers to nodes
Correct maxnode parameter value passed to mbind() syscall to be the amount of node mask bits to analyze plus 1. Dynamically allocate node mask memory depending on the index of node of cpu being profiled. Fixes: c44a8b4 ("perf record: Bind the AIO user space buffers to nodes") Signed-off-by: Alexey Budankov <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] [ Remove leftover nr_bits + 1 comment in mbind() call ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 67439d5 commit 44d462a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

tools/perf/util/mmap.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,29 @@ static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity)
9898
{
9999
void *data;
100100
size_t mmap_len;
101-
unsigned long node_mask;
101+
unsigned long *node_mask;
102+
unsigned long node_index;
103+
int err = 0;
102104

103105
if (affinity != PERF_AFFINITY_SYS && cpu__max_node() > 1) {
104106
data = map->aio.data[idx];
105107
mmap_len = mmap__mmap_len(map);
106-
node_mask = 1UL << cpu__get_node(cpu);
107-
if (mbind(data, mmap_len, MPOL_BIND, &node_mask, 1, 0)) {
108-
pr_err("Failed to bind [%p-%p] AIO buffer to node %d: error %m\n",
109-
data, data + mmap_len, cpu__get_node(cpu));
108+
node_index = cpu__get_node(cpu);
109+
node_mask = bitmap_alloc(node_index + 1);
110+
if (!node_mask) {
111+
pr_err("Failed to allocate node mask for mbind: error %m\n");
110112
return -1;
111113
}
114+
set_bit(node_index, node_mask);
115+
if (mbind(data, mmap_len, MPOL_BIND, node_mask, node_index + 1 + 1, 0)) {
116+
pr_err("Failed to bind [%p-%p] AIO buffer to node %lu: error %m\n",
117+
data, data + mmap_len, node_index);
118+
err = -1;
119+
}
120+
bitmap_free(node_mask);
112121
}
113122

114-
return 0;
123+
return err;
115124
}
116125
#else /* !HAVE_LIBNUMA_SUPPORT */
117126
static int perf_mmap__aio_alloc(struct mmap *map, int idx)

0 commit comments

Comments
 (0)