Skip to content

Commit d68e679

Browse files
virtuosoPeter Zijlstra
authored andcommitted
perf: Cap allocation order at aux_watermark
Currently, we start allocating AUX pages half the size of the total requested AUX buffer size, ignoring the attr.aux_watermark setting. This, in turn, makes intel_pt driver disregard the watermark also, as it uses page order for its SG (ToPA) configuration. Now, this can be fixed in the intel_pt PMU driver, but seeing as it's the only one currently making use of high order allocations, there is no reason not to fix the allocator instead. This way, any other driver wishing to add this support would not have to worry about this. Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lkml.kernel.org/r/20210414154955.49603-2-alexander.shishkin@linux.intel.com
1 parent cface03 commit d68e679

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

‎kernel/events/ring_buffer.c‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -674,21 +674,26 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
674674
if (!has_aux(event))
675675
return -EOPNOTSUPP;
676676

677-
/*
678-
* We need to start with the max_order that fits in nr_pages,
679-
* not the other way around, hence ilog2() and not get_order.
680-
*/
681-
max_order = ilog2(nr_pages);
682-
683-
/*
684-
* PMU requests more than one contiguous chunks of memory
685-
* for SW double buffering
686-
*/
687677
if (!overwrite) {
688-
if (!max_order)
689-
return -EINVAL;
678+
/*
679+
* Watermark defaults to half the buffer, and so does the
680+
* max_order, to aid PMU drivers in double buffering.
681+
*/
682+
if (!watermark)
683+
watermark = nr_pages << (PAGE_SHIFT - 1);
690684

691-
max_order--;
685+
/*
686+
* Use aux_watermark as the basis for chunking to
687+
* help PMU drivers honor the watermark.
688+
*/
689+
max_order = get_order(watermark);
690+
} else {
691+
/*
692+
* We need to start with the max_order that fits in nr_pages,
693+
* not the other way around, hence ilog2() and not get_order.
694+
*/
695+
max_order = ilog2(nr_pages);
696+
watermark = 0;
692697
}
693698

694699
rb->aux_pages = kcalloc_node(nr_pages, sizeof(void *), GFP_KERNEL,
@@ -743,9 +748,6 @@ int rb_alloc_aux(struct perf_buffer *rb, struct perf_event *event,
743748
rb->aux_overwrite = overwrite;
744749
rb->aux_watermark = watermark;
745750

746-
if (!rb->aux_watermark && !rb->aux_overwrite)
747-
rb->aux_watermark = nr_pages << (PAGE_SHIFT - 1);
748-
749751
out:
750752
if (!ret)
751753
rb->aux_pgoff = pgoff;

0 commit comments

Comments
 (0)