Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Merge from ad-namecache:



details:   https://anonhg.NetBSD.org/src/rev/84b6ec271634
branches:  trunk
changeset: 745171:84b6ec271634
user:      ad <ad%NetBSD.org@localhost>
date:      Sun Feb 23 22:14:03 2020 +0000

description:
Merge from ad-namecache:

- Have a stab at clustering the members of vnode_t and vnode_impl_t in a
  more cache-conscious way.  With that done, go back to adjusting v_usecount
  with atomics and keep vi_lock directly in vnode_impl_t (saves KVA).

- Allow VOP_LOCK(LK_NONE) for the benefit of VFS_VGET() and VFS_ROOT().
  Make sure LK_UPGRADE always comes with LK_NOWAIT.

- Make cwdinfo use mostly lockless.

diffstat:

 sys/compat/netbsd32/netbsd32_fs.c |   14 +--
 sys/kern/kern_exec.c              |   23 +++---
 sys/kern/kern_proc.c              |   18 ++--
 sys/kern/uipc_usrreq.c            |   23 ++++--
 sys/kern/vfs_cwd.c                |  133 +++++++++++++++++++++++++++++++++++--
 sys/kern/vfs_getcwd.c             |   13 +--
 sys/kern/vfs_lookup.c             |   11 +-
 sys/kern/vfs_mount.c              |   34 +++++----
 sys/kern/vfs_subr.c               |   21 +++--
 sys/kern/vfs_syscalls.c           |  106 +++++++++++++----------------
 sys/kern/vfs_vnode.c              |  121 ++++++++++++++++++++++++++++------
 sys/kern/vnode_if.sh              |    4 +-
 sys/miscfs/genfs/genfs_vnops.c    |   44 +++++------
 sys/miscfs/procfs/procfs_vnops.c  |   48 +++++++------
 sys/sys/filedesc.h                |   14 ++-
 sys/sys/vfs_syscalls.h            |    4 +-
 sys/sys/vnode.h                   |   59 ++++++----------
 sys/sys/vnode_impl.h              |   53 +++++++++++---
 18 files changed, 479 insertions(+), 264 deletions(-)

diffs (truncated from 1664 to 300 lines):

diff -r 901380e45683 -r 84b6ec271634 sys/compat/netbsd32/netbsd32_fs.c
--- a/sys/compat/netbsd32/netbsd32_fs.c Sun Feb 23 21:50:21 2020 +0000
+++ b/sys/compat/netbsd32/netbsd32_fs.c Sun Feb 23 22:14:03 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_fs.c,v 1.86 2020/01/31 09:01:23 maxv Exp $    */
+/*     $NetBSD: netbsd32_fs.c,v 1.87 2020/02/23 22:14:03 ad Exp $      */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.86 2020/01/31 09:01:23 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.87 2020/02/23 22:14:03 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -740,13 +740,12 @@
                syscallarg(char *) bufp;
                syscallarg(size_t) length;
        } */
-       struct proc *p = l->l_proc;
        int     error;
        char   *path;
        char   *bp, *bend;
        int     len = (int)SCARG(uap, length);
        int     lenused;
-       struct  cwdinfo *cwdi;
+       struct  vnode *dvp;
 
        if (len > MAXPATHLEN*4)
                len = MAXPATHLEN*4;
@@ -764,11 +763,10 @@
         * limit it to N/2 vnodes for an N byte buffer.
         */
 #define GETCWD_CHECK_ACCESS 0x0001
-       cwdi = p->p_cwdi;
-       rw_enter(&cwdi->cwdi_lock, RW_READER);
-       error = getcwd_common (cwdi->cwdi_cdir, NULL, &bp, path, len/2,
+       dvp = cwdcdir();
+       error = getcwd_common (dvp, NULL, &bp, path, len/2,
                               GETCWD_CHECK_ACCESS, l);
-       rw_exit(&cwdi->cwdi_lock);
+       vrele(dvp);
 
        if (error)
                goto out;
diff -r 901380e45683 -r 84b6ec271634 sys/kern/kern_exec.c
--- a/sys/kern/kern_exec.c      Sun Feb 23 21:50:21 2020 +0000
+++ b/sys/kern/kern_exec.c      Sun Feb 23 22:14:03 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: kern_exec.c,v 1.492 2020/02/15 17:13:55 ad Exp $       */
+/*     $NetBSD: kern_exec.c,v 1.493 2020/02/23 22:14:03 ad Exp $       */
 
 /*-
- * Copyright (c) 2008, 2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.492 2020/02/15 17:13:55 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_exec.c,v 1.493 2020/02/23 22:14:03 ad Exp $");
 
 #include "opt_exec.h"
 #include "opt_execfmt.h"
@@ -672,7 +672,7 @@
        char *path, *bp;
        size_t len, tlen;
        int error;
-       struct cwdinfo *cwdi;
+       struct vnode *dvp;
 
        path = PNBUF_GET();
        if (seg == UIO_SYSSPACE) {
@@ -698,11 +698,10 @@
        memmove(bp, path, len);
        *(--bp) = '/';
 
-       cwdi = l->l_proc->p_cwdi;
-       rw_enter(&cwdi->cwdi_lock, RW_READER);
-       error = getcwd_common(cwdi->cwdi_cdir, NULL, &bp, path, MAXPATHLEN / 2,
+       dvp = cwdcdir();
+       error = getcwd_common(dvp, NULL, &bp, path, MAXPATHLEN / 2,
            GETCWD_CHECK_ACCESS, l);
-       rw_exit(&cwdi->cwdi_lock);
+       vrele(dvp);
 
        if (error)
                goto err;
@@ -1119,6 +1118,7 @@
 emulexec(struct lwp *l, struct exec_package *epp)
 {
        struct proc             *p = l->l_proc;
+       struct cwdinfo          *cwdi;
 
        /* The emulation root will usually have been found when we looked
         * for the elf interpreter (or similar), if not look now. */
@@ -1127,9 +1127,10 @@
                emul_find_root(l, epp);
 
        /* Any old emulation root got removed by fdcloseexec */
-       rw_enter(&p->p_cwdi->cwdi_lock, RW_WRITER);
-       p->p_cwdi->cwdi_edir = epp->ep_emul_root;
-       rw_exit(&p->p_cwdi->cwdi_lock);
+       KASSERT(p == curproc);
+       cwdi = cwdenter(RW_WRITER);
+       cwdi->cwdi_edir = epp->ep_emul_root;
+       cwdexit(cwdi);
        epp->ep_emul_root = NULL;
        if (epp->ep_interp != NULL)
                vrele(epp->ep_interp);
diff -r 901380e45683 -r 84b6ec271634 sys/kern/kern_proc.c
--- a/sys/kern/kern_proc.c      Sun Feb 23 21:50:21 2020 +0000
+++ b/sys/kern/kern_proc.c      Sun Feb 23 22:14:03 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: kern_proc.c,v 1.241 2020/02/21 00:26:22 joerg Exp $    */
+/*     $NetBSD: kern_proc.c,v 1.242 2020/02/23 22:14:03 ad Exp $       */
 
 /*-
- * Copyright (c) 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 1999, 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.241 2020/02/21 00:26:22 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_proc.c,v 1.242 2020/02/23 22:14:03 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kstack.h"
@@ -106,6 +106,7 @@
 #include <sys/exec.h>
 #include <sys/cpu.h>
 #include <sys/compat_stub.h>
+#include <sys/vnode.h>
 
 #include <uvm/uvm_extern.h>
 #include <uvm/uvm.h>
@@ -476,7 +477,7 @@
        p->p_cred = cred0;
 
        /* Create the CWD info. */
-       rw_init(&cwdi0.cwdi_lock);
+       mutex_init(&cwdi0.cwdi_lock, MUTEX_DEFAULT, IPL_NONE);
 
        /* Create the limits structures. */
        mutex_init(&limit0.pl_lock, MUTEX_DEFAULT, IPL_NONE);
@@ -2594,7 +2595,7 @@
        struct proc *p;
        char *path;
        char *bp, *bend;
-       struct cwdinfo *cwdi;
+       const struct cwdinfo *cwdi;
        struct vnode *vp;
        size_t len, lenused;
 
@@ -2609,11 +2610,12 @@
        bend = bp;
        *(--bp) = '\0';
 
-       cwdi = p->p_cwdi;
-       rw_enter(&cwdi->cwdi_lock, RW_READER);
+       cwdi = cwdlock(p);
        vp = cwdi->cwdi_cdir;
+       vref(vp);
+       cwdunlock(p);
        error = getcwd_common(vp, NULL, &bp, path, len/2, 0, l);
-       rw_exit(&cwdi->cwdi_lock);
+       vrele(vp);
 
        if (error)
                goto out;
diff -r 901380e45683 -r 84b6ec271634 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Sun Feb 23 21:50:21 2020 +0000
+++ b/sys/kern/uipc_usrreq.c    Sun Feb 23 22:14:03 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.196 2020/02/01 02:23:23 riastradh Exp $      */
+/*     $NetBSD: uipc_usrreq.c,v 1.197 2020/02/23 22:14:03 ad Exp $     */
 
 /*-
- * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.196 2020/02/01 02:23:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.197 2020/02/23 22:14:03 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -1395,6 +1395,7 @@
 {
        struct cmsghdr * const cm = mtod(rights, struct cmsghdr *);
        struct proc * const p = l->l_proc;
+       struct vnode *rvp = NULL;
        file_t **rp;
        int error = 0;
 
@@ -1404,9 +1405,11 @@
                goto noop;
 
        int * const fdp = kmem_alloc(nfds * sizeof(int), KM_SLEEP);
-       rw_enter(&p->p_cwdi->cwdi_lock, RW_READER);
+
+       KASSERT(l == curlwp);
 
        /* Make sure the recipient should be able to see the files.. */
+       rvp = cwdrdir();
        rp = (file_t **)CMSG_DATA(cm);
        for (size_t i = 0; i < nfds; i++) {
                file_t * const fp = *rp++;
@@ -1420,16 +1423,15 @@
                 * sure it's inside the subtree we're allowed
                 * to access.
                 */
-               if (p->p_cwdi->cwdi_rdir != NULL && fp->f_type == DTYPE_VNODE) {
+               if (rvp != NULL && fp->f_type == DTYPE_VNODE) {
                        vnode_t *vp = fp->f_vnode;
-                       if ((vp->v_type == VDIR) &&
-                           !vn_isunder(vp, p->p_cwdi->cwdi_rdir, l)) {
+                       if ((vp->v_type == VDIR) && !vn_isunder(vp, rvp, l)) {
                                error = EPERM;
                                goto out;
                        }
                }
        }
-
+       
  restart:
        /*
         * First loop -- allocate file descriptor table slots for the
@@ -1506,7 +1508,6 @@
                cm->cmsg_len = CMSG_LEN(0);
                rights->m_len = CMSG_SPACE(0);
        }
-       rw_exit(&p->p_cwdi->cwdi_lock);
        kmem_free(fdp, nfds * sizeof(int));
 
  noop:
@@ -1516,6 +1517,10 @@
        KASSERT(cm->cmsg_len <= rights->m_len);
        memset(&mtod(rights, char *)[cm->cmsg_len], 0, rights->m_len -
            cm->cmsg_len);
+
+       /* Async release since in the networking code. */
+       if (rvp != NULL)
+               vrele_async(rvp);
        return error;
 }
 
diff -r 901380e45683 -r 84b6ec271634 sys/kern/vfs_cwd.c
--- a/sys/kern/vfs_cwd.c        Sun Feb 23 21:50:21 2020 +0000
+++ b/sys/kern/vfs_cwd.c        Sun Feb 23 22:14:03 2020 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $        */
+/*     $NetBSD: vfs_cwd.c,v 1.5 2020/02/23 22:14:03 ad Exp $   */
 
 /*-
- * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,13 +31,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.4 2011/02/15 15:54:28 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cwd.c,v 1.5 2020/02/23 22:14:03 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
 #include <sys/filedesc.h>
 #include <sys/proc.h>
 #include <sys/vnode.h>
+#include <sys/xcall.h>
 
 static int     cwdi_ctor(void *, void *, int);
 static void    cwdi_dtor(void *, void *);
@@ -64,9 +65,8 @@
        struct cwdinfo *copy;
 
        cwdi = pool_cache_get(cwdi_cache, PR_WAITOK);
-       copy = curproc->p_cwdi;
 
-       rw_enter(&copy->cwdi_lock, RW_READER);
+       copy = cwdenter(RW_READER);
        cwdi->cwdi_cdir = copy->cwdi_cdir;



Home | Main Index | Thread Index | Old Index