Commit 528871b4 authored by Ingo Molnar's avatar Ingo Molnar

perf/core: Fix impossible ring-buffer sizes warning

The following commit:

  9dff0aa9 ("perf/core: Don't WARN() for impossible ring-buffer sizes")

results in perf recording failures with larger mmap areas:

  root@skl:/tmp# perf record -g -a
  failed to mmap with 12 (Cannot allocate memory)

The root cause is that the following condition is buggy:

	if (order_base_2(size) >= MAX_ORDER)
		goto fail;

The problem is that @size is in bytes and MAX_ORDER is in pages,
so the right test is:

	if (order_base_2(size) >= PAGE_SHIFT+MAX_ORDER)
		goto fail;

Fix it.
Reported-by: default avatar"Jin, Yao" <>
Bisected-by: b0R1sLAV's avatarBorislav Petkov <>
Analyzed-by: default avatarPeter Zijlstra <>
Cc: Julien Thierry <>
Cc: Mark Rutland <>
Cc: Alexander Shishkin <>
Cc: Arnaldo Carvalho de Melo <>
Cc: Jiri Olsa <>
Cc: Linus Torvalds <>
Cc: Namhyung Kim <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Cc: Greg Kroah-Hartman <>
Cc: <>
Fixes: 9dff0aa9 ("perf/core: Don't WARN() for impossible ring-buffer sizes")
Signed-off-by: default avatarIngo Molnar <>
parent 81ec3f3c
......@@ -734,7 +734,7 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags)
size = sizeof(struct ring_buffer);
size += nr_pages * sizeof(void *);
if (order_base_2(size) >= MAX_ORDER)
if (order_base_2(size) >= PAGE_SHIFT+MAX_ORDER)
goto fail;
rb = kzalloc(size, GFP_KERNEL);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment