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

Steven Rostedt <[email protected]>
Newsgroups org.kernel.vger.linux-trace-users,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Fri, 22 Apr 2016 11:45:30 +0900
Namhyung Kim <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.