Source-Changes-HG archive

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

[src/trunk]: src - options NAMECACHE_ENTER_REVERSE is no more.



details:   https://anonhg.NetBSD.org/src/rev/8990f3c7a5fe
branches:  trunk
changeset: 1006276:8990f3c7a5fe
user:      ad <ad%NetBSD.org@localhost>
date:      Wed Jan 08 12:04:56 2020 +0000

description:
- options NAMECACHE_ENTER_REVERSE is no more.

- Partially sort the list of per-vnode namecache entries by using a TAILQ.
  Put the real name to the head, and put dot and dotdot to the tail so that
  cache_lookup_reverse() doesn't have to consider them.

diffstat:

 sbin/mount_procfs/mount_procfs.8 |    7 +-
 sys/conf/files                   |    4 +-
 sys/kern/vfs_cache.c             |  136 ++++++++++++++++++++------------------
 sys/kern/vfs_getcwd.c            |    9 +-
 sys/kern/vfs_vnode.c             |    6 +-
 sys/sys/namei.src                |    4 +-
 sys/sys/vnode_impl.h             |    4 +-
 7 files changed, 87 insertions(+), 83 deletions(-)

diffs (truncated from 350 to 300 lines):

diff -r 0774093d994e -r 8990f3c7a5fe sbin/mount_procfs/mount_procfs.8
--- a/sbin/mount_procfs/mount_procfs.8  Wed Jan 08 11:58:02 2020 +0000
+++ b/sbin/mount_procfs/mount_procfs.8  Wed Jan 08 12:04:56 2020 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mount_procfs.8,v 1.37 2017/08/28 05:58:08 wiz Exp $
+.\"    $NetBSD: mount_procfs.8,v 1.38 2020/01/08 12:04:57 ad Exp $
 .\"
 .\" Copyright (c) 1992, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -34,7 +34,7 @@
 .\"    @(#)mount_procfs.8      8.3 (Berkeley) 6/1/94
 .\"
 .\"
-.Dd August 28, 2017
+.Dd January 8, 2020
 .Dt MOUNT_PROCFS 8
 .Os
 .Sh NAME
@@ -111,9 +111,6 @@
 .It Pa maps
 A map of the process' virtual memory in a form like the
 proc filesystem as implemented in Linux.
-Note that the paths corresponding to file backed mappings will
-not be present unless the kernel was built with the
-NAMECACHE_ENTER_REVERSE option.
 .It Pa mem
 The complete virtual memory image of the process.
 Only those addresses which exist in the process can be accessed.
diff -r 0774093d994e -r 8990f3c7a5fe sys/conf/files
--- a/sys/conf/files    Wed Jan 08 11:58:02 2020 +0000
+++ b/sys/conf/files    Wed Jan 08 12:04:56 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1248 2019/12/23 06:45:37 maxv Exp $
+#      $NetBSD: files,v 1.1249 2020/01/08 12:04:56 ad Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20171118
@@ -90,8 +90,6 @@
 
 defparam opt_kmempages.h       NKMEMPAGES NKMEMPAGES_MIN NKMEMPAGES_MAX
 
-defflag        opt_revcache.h          NAMECACHE_ENTER_REVERSE
-
 defflag        opt_exec.h              DEBUG_EXEC
 
 defflag        opt_execfmt.h           EXEC_AOUT EXEC_COFF EXEC_ECOFF EXEC_ELF32
diff -r 0774093d994e -r 8990f3c7a5fe sys/kern/vfs_cache.c
--- a/sys/kern/vfs_cache.c      Wed Jan 08 11:58:02 2020 +0000
+++ b/sys/kern/vfs_cache.c      Wed Jan 08 12:04:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_cache.c,v 1.126 2020/01/06 11:22:33 ad Exp $       */
+/*     $NetBSD: vfs_cache.c,v 1.127 2020/01/08 12:04:56 ad Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -58,13 +58,12 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.126 2020/01/06 11:22:33 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.127 2020/01/08 12:04:56 ad Exp $");
 
 #define __NAMECACHE_PRIVATE
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
 #include "opt_dtrace.h"
-#include "opt_revcache.h"
 #endif
 
 #include <sys/param.h>
@@ -129,7 +128,7 @@
  * - Invalidate: active--->queued
  *
  *   Done by cache_invalidate.  If not already invalidated, nullify
- *   ncp->nc_dvp and ncp->nc_vp, and add to cache_gcqueue.  Called,
+ *   ncp->nc_dvp and and add to cache_gcqueue.  Called,
  *   among various other places, in cache_lookup(dvp, name, namelen,
  *   nameiop, cnflags, &iswht, &vp) when MAKEENTRY is missing from
  *   cnflags.
@@ -376,7 +375,6 @@
                SDT_PROBE(vfs, namecache, invalidate, done, ncp->nc_dvp,
                    0, 0, 0, 0);
 
-               ncp->nc_vp = NULL;
                ncp->nc_dvp = NULL;
                do {
                        head = cache_gcqueue;
@@ -401,9 +399,11 @@
                TAILQ_REMOVE(&nclruhead, ncp, nc_lru);
                ncp->nc_lru.tqe_prev = NULL;
        }
-       if (ncp->nc_vlist.le_prev != NULL) {
-               LIST_REMOVE(ncp, nc_vlist);
-               ncp->nc_vlist.le_prev = NULL;
+       if (ncp->nc_vlist.tqe_prev != NULL) {
+               KASSERT(ncp->nc_vp != NULL);
+               TAILQ_REMOVE(&VNODE_TO_VIMPL(ncp->nc_vp)->vi_nclist, ncp,
+                   nc_vlist);
+               ncp->nc_vlist.tqe_prev = NULL;
        }
        if (ncp->nc_dvlist.le_prev != NULL) {
                LIST_REMOVE(ncp, nc_dvlist);
@@ -777,59 +777,61 @@
         */
        cpup = curcpu()->ci_data.cpu_nch;
        mutex_enter(namecache_lock);
-       LIST_FOREACH(ncp, &VNODE_TO_VIMPL(vp)->vi_nclist, nc_vlist) {
+       TAILQ_FOREACH(ncp, &VNODE_TO_VIMPL(vp)->vi_nclist, nc_vlist) {
                mutex_enter(&ncp->nc_lock);
-               if (ncp->nc_vp == vp &&
-                   (dvp = ncp->nc_dvp) != NULL &&
-                   dvp != vp) {                /* avoid pesky . entries.. */
-                       if (ncp->nc_nlen == 1 &&
-                           ncp->nc_name[0] == '.') {
-                               mutex_exit(&ncp->nc_lock);
-                               continue;
+               /* Ignore invalidated entries. */
+               dvp = ncp->nc_dvp;
+               if (dvp == NULL) {
+                       mutex_exit(&ncp->nc_lock);
+                       continue;
+               }
+               
+               /*
+                * The list is partially sorted.  Once we hit dot or dotdot
+                * it's only more dots from there on in.
+                */
+               nlen = ncp->nc_nlen;
+               if (ncp->nc_name[0] == '.') {
+                       if (nlen == 1 ||
+                           (nlen == 2 && ncp->nc_name[1] == '.')) {
+                               mutex_exit(&ncp->nc_lock);
+                               break;
                        }
-                       if (ncp->nc_nlen == 2 &&
-                           ncp->nc_name[0] == '.' &&
-                           ncp->nc_name[1] == '.') {
-                               mutex_exit(&ncp->nc_lock);
-                               continue;
-                       }
-                       COUNT(cpup, ncs_revhits);
-                       nlen = ncp->nc_nlen;
+               }
+               COUNT(cpup, ncs_revhits);
 
-                       if (bufp) {
-                               bp = *bpp;
-                               bp -= nlen;
-                               if (bp <= bufp) {
-                                       *dvpp = NULL;
-                                       mutex_exit(&ncp->nc_lock);
-                                       mutex_exit(namecache_lock);
-                                       SDT_PROBE(vfs, namecache, revlookup,
-                                           fail, vp, ERANGE, 0, 0, 0);
-                                       return (ERANGE);
-                               }
-                               memcpy(bp, ncp->nc_name, nlen);
-                               *bpp = bp;
+               if (bufp) {
+                       bp = *bpp;
+                       bp -= nlen;
+                       if (bp <= bufp) {
+                               *dvpp = NULL;
+                               mutex_exit(&ncp->nc_lock);
+                               mutex_exit(namecache_lock);
+                               SDT_PROBE(vfs, namecache, revlookup,
+                                   fail, vp, ERANGE, 0, 0, 0);
+                               return (ERANGE);
                        }
+                       memcpy(bp, ncp->nc_name, nlen);
+                       *bpp = bp;
+               }
 
-                       mutex_enter(dvp->v_interlock);
-                       mutex_exit(&ncp->nc_lock);
-                       mutex_exit(namecache_lock);
-                       error = vcache_tryvget(dvp);
-                       if (error) {
-                               KASSERT(error == EBUSY);
-                               if (bufp)
-                                       (*bpp) += nlen;
-                               *dvpp = NULL;
-                               SDT_PROBE(vfs, namecache, revlookup, fail, vp,
-                                   error, 0, 0, 0);
-                               return -1;
-                       }
-                       *dvpp = dvp;
-                       SDT_PROBE(vfs, namecache, revlookup, success, vp, dvp,
-                           0, 0, 0);
-                       return (0);
+               mutex_enter(dvp->v_interlock);
+               mutex_exit(&ncp->nc_lock);
+               mutex_exit(namecache_lock);
+               error = vcache_tryvget(dvp);
+               if (error) {
+                       KASSERT(error == EBUSY);
+                       if (bufp)
+                               (*bpp) += nlen;
+                       *dvpp = NULL;
+                       SDT_PROBE(vfs, namecache, revlookup, fail, vp,
+                           error, 0, 0, 0);
+                       return -1;
                }
-               mutex_exit(&ncp->nc_lock);
+               *dvpp = dvp;
+               SDT_PROBE(vfs, namecache, revlookup, success, vp, dvp,
+                   0, 0, 0);
+               return (0);
        }
        COUNT(cpup, ncs_revmiss);
        mutex_exit(namecache_lock);
@@ -902,11 +904,19 @@
        /* Fill in cache info. */
        ncp->nc_dvp = dvp;
        LIST_INSERT_HEAD(&VNODE_TO_VIMPL(dvp)->vi_dnclist, ncp, nc_dvlist);
-       if (vp)
-               LIST_INSERT_HEAD(&VNODE_TO_VIMPL(vp)->vi_nclist, ncp, nc_vlist);
-       else {
-               ncp->nc_vlist.le_prev = NULL;
-               ncp->nc_vlist.le_next = NULL;
+       if (vp) {
+               /* Partially sort the per-vnode list: dots go to back. */
+               if ((namelen == 1 && name[0] == '.') ||
+                   (namelen == 2 && name[0] == '.' && name[1] == '.')) {
+                       TAILQ_INSERT_TAIL(&VNODE_TO_VIMPL(vp)->vi_nclist, ncp,
+                           nc_vlist);
+               } else {
+                       TAILQ_INSERT_HEAD(&VNODE_TO_VIMPL(vp)->vi_nclist, ncp,
+                           nc_vlist);
+               }
+       } else {
+               ncp->nc_vlist.tqe_prev = NULL;
+               ncp->nc_vlist.tqe_next = NULL;
        }
        KASSERT(namelen <= USHRT_MAX);
        ncp->nc_nlen = namelen;
@@ -1044,9 +1054,9 @@
        if (flags & PURGE_PARENTS) {
                SDT_PROBE(vfs, namecache, purge, parents, vp, 0, 0, 0, 0);
 
-               for (ncp = LIST_FIRST(&VNODE_TO_VIMPL(vp)->vi_nclist);
+               for (ncp = TAILQ_FIRST(&VNODE_TO_VIMPL(vp)->vi_nclist);
                    ncp != NULL; ncp = ncnext) {
-                       ncnext = LIST_NEXT(ncp, nc_vlist);
+                       ncnext = TAILQ_NEXT(ncp, nc_vlist);
                        mutex_enter(&ncp->nc_lock);
                        cache_invalidate(ncp);
                        mutex_exit(&ncp->nc_lock);
@@ -1242,7 +1252,7 @@
        }
        vp = dvp;
        TAILQ_FOREACH(ncp, &nclruhead, nc_lru) {
-               if (ncp->nc_vp == vp) {
+               if (ncp->nc_vp == vp && ncp->nc_dvp != NULL) {
                        (*pr)("parent %.*s\n", ncp->nc_nlen, ncp->nc_name);
                }
        }
diff -r 0774093d994e -r 8990f3c7a5fe sys/kern/vfs_getcwd.c
--- a/sys/kern/vfs_getcwd.c     Wed Jan 08 11:58:02 2020 +0000
+++ b/sys/kern/vfs_getcwd.c     Wed Jan 08 12:04:56 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_getcwd.c,v 1.53 2019/09/14 21:23:34 christos Exp $ */
+/* $NetBSD: vfs_getcwd.c,v 1.54 2020/01/08 12:04:56 ad Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.53 2019/09/14 21:23:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.54 2020/01/08 12:04:56 ad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -539,9 +539,8 @@
 }
 
 /*
- * Try to find a pathname for a vnode. Since there is no mapping
- * vnode -> parent directory, this needs the NAMECACHE_ENTER_REVERSE
- * option to work (to make cache_revlookup succeed). Caller holds a
+ * Try to find a pathname for a vnode.  Since there is no mapping vnode ->
+ * parent directory, this needs the namecache to succeed.  Caller holds a
  * reference to the vnode.
  */
 int
diff -r 0774093d994e -r 8990f3c7a5fe sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c      Wed Jan 08 11:58:02 2020 +0000
+++ b/sys/kern/vfs_vnode.c      Wed Jan 08 12:04:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnode.c,v 1.105 2019/12/16 22:47:54 ad Exp $       */
+/*     $NetBSD: vfs_vnode.c,v 1.106 2020/01/08 12:04:56 ad Exp $       */
 
 /*-
  * Copyright (c) 1997-2011, 2019 The NetBSD Foundation, Inc.
@@ -146,7 +146,7 @@
  */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index