[PATCH v6 3/5] Use get_proc_pid for /proc paths

Ákos Uzonyi uzonyi.akos at gmail.com
Fri Aug 7 21:11:22 UTC 2020


On Fri, 7 Aug 2020 at 21:29, Dmitry V. Levin <ldv at altlinux.org> wrote:
> On Fri, Aug 07, 2020 at 09:12:05PM +0200, Ákos Uzonyi wrote:
> > On Fri, 7 Aug 2020 at 20:53, Dmitry V. Levin <ldv at altlinux.org> wrote:
> > > On Thu, Aug 06, 2020 at 09:02:09PM +0200, Ákos Uzonyi wrote:
[...]
> > > > diff --git a/util.c b/util.c
> > > > index 094e5818..d87d022e 100644
> > > > --- a/util.c
> > > > +++ b/util.c
> > > > @@ -582,8 +582,11 @@ printdev(struct tcb *tcp, int fd, const char *path)
> > > >  pid_t
> > > >  pidfd_get_pid(pid_t pid_of_fd, int fd)
> > > >  {
> > > > +     int proc_pid = 0;
> > > > +     translate_pid(NULL, pid_of_fd, PT_TID, &proc_pid);
> > > > +
> > > >       char fdi_path[sizeof("/proc/%u/fdinfo/%u") + 2 * sizeof(int) * 3];
> > > > -     xsprintf(fdi_path, "/proc/%u/fdinfo/%u", pid_of_fd, fd);
> > > > +     xsprintf(fdi_path, "/proc/%u/fdinfo/%u", proc_pid, fd);
> > > >
> > > >       FILE *f = fopen_stream(fdi_path, "r");
> > > >       if (!f)
> > >
> > > Likewise, this would invoke the whole translate_pid machinery even for the
> > > case when is_proc_ours() returns true.  Could something be done about it?
> > >
> > > The idea is not to bring all these heavy translation mechanisms up
> > > unnecessarily, that is, unless /proc is messed up or --pidns-translation
> > > is specified.
> >
> > Actually, translation happens very fast in that case, as the following
> > condition will be true (in translate_pid):
> >
> > /* If translation is trivial */
> > if (tip.from_ns == our_ns && (is_proc_ours() || !proc_pid_ptr)) {
> >
> > So we could even remove the "if (is_proc_ours())" optimization from
> > get_proc_pid, as it is already done in translate_pid.
>
> Sorry, I don't follow: translate_pid(NULL) calls both get_our_ns()
> and is_proc_ours(), but I don't understand why it has to call
> get_our_ns() if the result is essentially ignored anyway.

Indeed, it calls get_our_ns, which is not needed if tcp is NULL. It's
not a very big performance problem however, as get_our_ns return value
is cached. But I'll modify translate_pid a bit, so get_our_ns is only
called if really needed.


More information about the Strace-devel mailing list