Re: [PATCH] perf_counter: allow and require one-page mmap on counting counters

Ingo Molnar
2009-03-25T11:53:25Z

* Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:

> On Wed, 2009-03-25 at 19:15 +1100, Paul Mackerras wrote:
> > Impact: bug fix
> >
> > Currently the mmap code requires that the length of the mmap be at least
> > two pages. That is fine for sampling counters, but for counting
> > counters the second and subsequent pages are just wasted, since counting
> > counters don't generate events.
> >
> > This changes the code to require that the mmap be one page in length
> > for counting counters, and applies the existing check to sampling
> > counters.
>
> Does the below work for you Paul?
>
> ---
> Subject: perf_counter: allow one-page mmap on counters
> From: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Date: Wed Mar 25 12:44:16 CET 2009
>
> A brainfart stopped single page mmap()s working. The rest of the code
> should be perfectly fine with not having any data pages.
>
> Reported-by: Paul Mackerras <paulus@samba.org>
> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
> ---
> kernel/perf_counter.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> Index: linux-2.6/kernel/perf_counter.c
> ===================================================================
> --- linux-2.6.orig/kernel/perf_counter.c
> +++ linux-2.6/kernel/perf_counter.c
> @@ -1369,7 +1369,11 @@ static int perf_mmap(struct file *file,
> vma_size = vma->vm_end - vma->vm_start;
> nr_pages = (vma_size / PAGE_SIZE) - 1;
>
> - if (nr_pages == 0 || !is_power_of_2(nr_pages))
> + /*
> + * If we have data pages ensure they're a power-of-two number, so we
> + * can do bitmasks instead of modulo.
> + */
> + if (nr_pages != 0 && !is_power_of_2(nr_pages))
> return -EINVAL;

Yeah - this is cleaner.

Ingo