svn commit: r274167 - in head/sys: kern sys
Mateusz Guzik
mjguzik at gmail.com
Fri Nov 21 05:51:05 UTC 2014
On Thu, Nov 20, 2014 at 09:24:37PM -0800, Rui Paulo wrote:
> On Nov 6, 2014, at 00:12, Mateusz Guzik <mjg at freebsd.org> wrote:
> >
> > Author: mjg
> > Date: Thu Nov 6 08:12:34 2014
> > New Revision: 274167
> > URL: https://svnweb.freebsd.org/changeset/base/274167
> >
> > Log:
> > Add sysctl kern.proc.cwd
> >
> > It returns only current working directory of given process which saves a lot of
> > overhead over kern.proc.filedesc if given proc has a lot of open fds.
> >
> > Submitted by: Tiwei Bie <btw mail.ustc.edu.cn> (slightly modified)
> > X-Additional: JuniorJobs project
> >
> > Modified:
> > head/sys/kern/kern_descrip.c
> > head/sys/sys/sysctl.h
> > head/sys/sys/user.h
> >
> > Modified: head/sys/kern/kern_descrip.c
> > ==============================================================================
> > --- head/sys/kern/kern_descrip.c Thu Nov 6 07:44:10 2014 (r274166)
> > +++ head/sys/kern/kern_descrip.c Thu Nov 6 08:12:34 2014 (r274167)
> > @@ -3406,6 +3406,73 @@ static SYSCTL_NODE(_kern_proc, KERN_PROC
> > CTLFLAG_RD|CTLFLAG_MPSAFE, sysctl_kern_proc_filedesc,
> > "Process filedesc entries");
> >
> > +/*
> > + * Store a process current working directory information to sbuf.
> > + *
> > + * Takes a locked proc as argument, and returns with the proc unlocked.
>
> I never really liked this approach because it makes it harder to see the locking pattern.
>
> Why not call fdhold(p) in the sysctl handler, unlock the process, call kern_proc_cwd_out() with an additional fdp argument, and then call fddrop()?
>
This code just mimics what was done with kern_proc_filedesc_out, which
happens to have semi-valid usecase when fdhold returns NULL.
In general I agree and this scheme is going away.
I have a patch in my backlog which "pins" the process (i.e. prevents exec
and exit) for the duration of kern_proc_filedesc_out/whatever, so it will
effectively mean such functions will no longer play with fdhold/fddrop.
Interestingly enough this requires some changes in devfs and I didn't have
the time to ensure they work properly.
--
Mateusz Guzik <mjguzik gmail.com>
More information about the svn-src-head
mailing list