On Fri, May 25, 2018 at 10:35:35AM +0200, Martin Pieuchot wrote:
> On 22/05/18(Tue) 15:39, Martin Pieuchot wrote:
> > By assuming that `f_data' is immutable, which AFAIK is true for sockets,
> > we can remove the KERNEL_LOCK() from the following syscalls iff files are
> > refcounted in an MP-safe way.
> >
> > This diff includes the EBUSY check in dup2(2) which is currently required
> > to avoid races with accept(2) and will later make our life easier wrt
> > open(2).
> >
> > It also includes the fdinsert() diff I sent earlier.
> >
> > On top of that I'm introducing a global mutex, `fhdlk', that protects
> > `f_count' and the implicit reference in `filehead'.
> >
> > A socket stays alive as long as its associated file has a positive
> > refcount. When this refcount drops, fdrop() will be called and soclose()
> > will free/clean `f_data'. That's the only place where `f_data' is
> > changed during the life of a socket. That's why it is safe to dereference
> > `f_data' when getsock() returned a valid & refcounted `fp'.
> >
> > Many ktrace(2) internals now need to grab the KERNEL_LOCK(), just like
> > ptsignal().
> >
> > Note that for unix, routing and pfkey sockets, solock() still grabs the
> > KERNEL_LOCK(). So even if syscalls are marked as SY_NOLOCK that doesn't
> > mean they won't grab it. In fact some network functions like
> > ifa_ifwithaddr() below now need to grab the KERNEL_LOCK(). That's good
> > that means we're pushing the lock down.
> >
> > Tests? Comments?
>
> Updated diff that should prevent reported hangs, as analyzed by tb@ and
> visa@.
I've been running this on my main laptop since Visa figured out the
problem on Wednesday and saw no more issues since then. I've completed
a make build with a WITNESS kernel while letting youtube play videos.
For people who want to do 'make build', the following additional diff is
needed:
Index: usr.sbin/pstat/pstat.8
===================================================================
RCS file: /var/cvs/src/usr.sbin/pstat/pstat.8,v
retrieving revision 1.52
diff -u -p -r1.52 pstat.8
--- usr.sbin/pstat/pstat.8 26 Nov 2016 11:18:43 -0000 1.52
+++ usr.sbin/pstat/pstat.8 23 May 2018 16:33:54 -0000
@@ -101,8 +101,6 @@ open for appending
exclusive or shared lock present
.It I
signal pgrp when data ready
-.It l
-file descriptor slot is larval
.El
.It CNT
Number of processes that know this open file.
Index: usr.sbin/pstat/pstat.c
===================================================================
RCS file: /var/cvs/src/usr.sbin/pstat/pstat.c,v
retrieving revision 1.114
diff -u -p -r1.114 pstat.c
--- usr.sbin/pstat/pstat.c 2 Jan 2018 06:38:45 -0000 1.114
+++ usr.sbin/pstat/pstat.c 23 May 2018 16:22:56 -0000
@@ -1044,8 +1044,6 @@ filemode(void)
if (kf->f_iflags & FIF_HASLOCK)
*fbp++ = 'L';
- if (kf->f_iflags & FIF_LARVAL)
- *fbp++ = 'l';
*fbp = '\0';
(void)printf("%6s %3ld", flagbuf, (long)kf->f_count);