Re: [RFC][PATCH 2/4] tracing: Use pid bitmap instead of a pid array for set_event_pid

From: Steven Rostedt
Date: Fri Apr 22 2016 - 11:30:30 EST


On Fri, 22 Apr 2016 11:45:30 +0900
Namhyung Kim <namhyung@xxxxxxxxxx> wrote:

> > + pid_list->pid_max = READ_ONCE(pid_max);
> > + /* Only truncating will shrink pid_max */
> > + if (filtered_pids && filtered_pids->pid_max > pid_list->pid_max)
> > + pid_list->pid_max = filtered_pids->pid_max;
> > + pid_list->pids = vzalloc((pid_list->pid_max + 7) >> 3);
> > + if (!pid_list->pids) {
> > + kfree(pid_list);
> > + read = -ENOMEM;
> > + goto out;
> > + }
> > + if (filtered_pids) {
> > + /* copy the current bits to the new max */
> > + pid = find_first_bit(filtered_pids->pids,
> > + filtered_pids->pid_max);
> > + while (pid < filtered_pids->pid_max) {
> > + set_bit(pid, pid_list->pids);
> > + pid = find_next_bit(filtered_pids->pids,
> > + filtered_pids->pid_max,
> > + pid + 1);
> > + nr_pids++;
> > + }
>
> Why not just use memcpy and keep nr_pids in the pid_list?

This is the slow path (very slow ;-), and this was the first method
that came to my mind (while I programmed this during a conference). I
could use memcpy, or simply one of the bitmask copies, and then get the
nr_pids from bitmask_weight(). I would not keep nr_pids in pid_list
because that would mean that I would have to manage it in the fast path.

Maybe later I'll convert it to bitmap_copy(), but for now I'll just
keep it as is. I move this code in my queue for 4.8, and don't want to
deal with conflicts unless there's a real bug discovered.

Thanks for looking at this code!

-- Steve