Re: [PATCH 2/3] perf tools: Skip MMAP record synthesis for kernel threads

From: Jiri Olsa
Date: Mon Feb 01 2021 - 15:34:32 EST


On Mon, Feb 01, 2021 at 01:54:32PM +0900, Namhyung Kim wrote:
> On Mon, Feb 1, 2021 at 7:48 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote:
> >
> > On Fri, Jan 29, 2021 at 02:49:00PM +0900, Namhyung Kim wrote:
> > > To synthesize information to resolve sample IPs, it needs to scan task
> > > and mmap info from the /proc filesystem. For each process, it
> > > opens (and reads) status and maps file respectively. But as kernel
> > > threads don't have memory maps so we can skip the maps file.
> > >
> > > To find kernel threads, check "VmPeak:" line in /proc/<PID>/status
> > > file. It's about the peak virtual memory usage so only user-level
> > > tasks have that. Also check "Threads:" line (which follows the VmPeak
> > > line whether or not it exists) to be sure it's read enough data - just
> > > in case of deeply nested pid namespaces or large number of
> > > supplementary groups are involved.
> >
> > I don't understand this Threads: check, could you please
> > show example where it's useful for the check?
>
> Sure!
>
> I think there's a chance that the status file actually has the VmPeak line,
> but it didn't read to the line for some reason. In that case, we should
> not assume the task is a kernel thread.
>
> So it needs to make sure whether there's no such line in the file
> or it just didn't read enough data. To check the latter case, it
> searches the "Threads" line which follows the VmPeak always.

ah ok, there's limited buffer for the status file

we could call filename__read_str to read the whole file
and skip these checks.. but perhaps that'd be another
slowdown you trying to prevent

if you put that comment to the code, I'm ok with that

thanks,
jirka