summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorad <ad@NetBSD.org>2020-01-08 12:04:56 +0000
committerad <ad@NetBSD.org>2020-01-08 12:04:56 +0000
commit324217bda51c0b06d331c8fcc3ed24e75b7241de (patch)
treee4df4b0a249e59f9244e56fd776df9593607ceeb
parentc6a5d67514960a309b4a7533514be01b6e12b579 (diff)
- 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.
-rw-r--r--sbin/mount_procfs/mount_procfs.87
-rw-r--r--sys/conf/files4
-rw-r--r--sys/kern/vfs_cache.c134
-rw-r--r--sys/kern/vfs_getcwd.c9
-rw-r--r--sys/kern/vfs_vnode.c6
-rw-r--r--sys/sys/namei.src4
-rw-r--r--sys/sys/vnode_impl.h4
7 files changed, 86 insertions, 82 deletions
diff --git a/sbin/mount_procfs/mount_procfs.8 b/sbin/mount_procfs/mount_procfs.8
index ffd787a23ce..86124fa00dd 100644
--- a/sbin/mount_procfs/mount_procfs.8
+++ b/sbin/mount_procfs/mount_procfs.8
@@ -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 @@ A map of the process' virtual memory.
.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 --git a/sys/conf/files b/sys/conf/files
index 61a9fed9128..aca8e691a7b 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -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 @@ defflag opt_ptm.h NO_DEV_PTM COMPAT_BSDPTY
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 --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 683d25b2235..7e1b7e3287e 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.126 2020/01/06 11:22:33 ad Exp $");
* - 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 @@ cache_invalidate(struct namecache *ncp)
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 @@ cache_disassociate(struct namecache *ncp)
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 @@ cache_revlookup(struct vnode *vp, struct vnode **dvpp, char **bpp, char *bufp)
*/
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;
- }
- 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;
-
- 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;
+ /* 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;
}
+ }
+ COUNT(cpup, ncs_revhits);
- 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;
+ if (bufp) {
+ bp = *bpp;
+ bp -= nlen;
+ if (bp <= bufp) {
*dvpp = NULL;
- SDT_PROBE(vfs, namecache, revlookup, fail, vp,
- error, 0, 0, 0);
- return -1;
+ mutex_exit(&ncp->nc_lock);
+ mutex_exit(namecache_lock);
+ SDT_PROBE(vfs, namecache, revlookup,
+ fail, vp, ERANGE, 0, 0, 0);
+ return (ERANGE);
}
- *dvpp = dvp;
- SDT_PROBE(vfs, namecache, revlookup, success, vp, dvp,
- 0, 0, 0);
- return (0);
+ 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);
}
COUNT(cpup, ncs_revmiss);
mutex_exit(namecache_lock);
@@ -902,11 +904,19 @@ cache_enter(struct vnode *dvp, struct vnode *vp,
/* 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 @@ cache_purge1(struct vnode *vp, const char *name, size_t namelen, int flags)
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 @@ namecache_print(struct vnode *vp, void (*pr)(const char *, ...))
}
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 --git a/sys/kern/vfs_getcwd.c b/sys/kern/vfs_getcwd.c
index c69f3c6b3e4..65f2e68ad67 100644
--- a/sys/kern/vfs_getcwd.c
+++ b/sys/kern/vfs_getcwd.c
@@ -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 @@ out:
}
/*
- * 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 --git a/sys/kern/vfs_vnode.c b/sys/kern/vfs_vnode.c
index 472abb6a4f9..44dab0b3550 100644
--- a/sys/kern/vfs_vnode.c
+++ b/sys/kern/vfs_vnode.c
@@ -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>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.105 2019/12/16 22:47:54 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.106 2020/01/08 12:04:56 ad Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@@ -1127,7 +1127,7 @@ vcache_alloc(void)
vip->vi_lock = rw_obj_alloc();
/* SLIST_INIT(&vip->vi_hash); */
- /* LIST_INIT(&vip->vi_nclist); */
+ TAILQ_INIT(&vip->vi_nclist);
/* LIST_INIT(&vip->vi_dnclist); */
vp = VIMPL_TO_VNODE(vip);
diff --git a/sys/sys/namei.src b/sys/sys/namei.src
index dad30afadb9..868a08c1255 100644
--- a/sys/sys/namei.src
+++ b/sys/sys/namei.src
@@ -1,4 +1,4 @@
-/* $NetBSD: namei.src,v 1.47 2020/01/06 11:22:33 ad Exp $ */
+/* $NetBSD: namei.src,v 1.48 2020/01/08 12:04:56 ad Exp $ */
/*
* Copyright (c) 1985, 1989, 1991, 1993
@@ -212,7 +212,7 @@ struct namecache {
LIST_ENTRY(namecache) nc_hash; /* L/C hash chain */
TAILQ_ENTRY(namecache) nc_lru; /* L pseudo-lru chain */
LIST_ENTRY(namecache) nc_dvlist;/* L dvp's list of cache entries */
- LIST_ENTRY(namecache) nc_vlist; /* L vp's list of cache entries */
+ TAILQ_ENTRY(namecache) nc_vlist;/* L vp's list of cache entries */
struct vnode *nc_dvp; /* N vnode of parent of name */
struct vnode *nc_vp; /* N vnode the name refers to */
void *nc_gcqueue; /* N queue for garbage collection */
diff --git a/sys/sys/vnode_impl.h b/sys/sys/vnode_impl.h
index ed9ed94a98a..ee3eb30fa72 100644
--- a/sys/sys/vnode_impl.h
+++ b/sys/sys/vnode_impl.h
@@ -1,4 +1,4 @@
-/* $NetBSD: vnode_impl.h,v 1.19 2019/12/22 19:47:34 ad Exp $ */
+/* $NetBSD: vnode_impl.h,v 1.20 2020/01/08 12:04:56 ad Exp $ */
/*-
* Copyright (c) 2016, 2019 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@ struct vnode_impl {
struct vnodelst *vi_lrulisthd; /* d: current lru list head */
TAILQ_ENTRY(vnode_impl) vi_lrulist; /* d: lru list */
LIST_HEAD(, namecache) vi_dnclist; /* n: namecaches (children) */
- LIST_HEAD(, namecache) vi_nclist; /* n: namecaches (parent) */
+ TAILQ_HEAD(, namecache) vi_nclist; /* n: namecaches (parent) */
int vi_synclist_slot; /* s: synclist slot index */
int vi_lrulisttm; /* i: time of lru enqueue */
TAILQ_ENTRY(vnode_impl) vi_synclist; /* s: vnodes with dirty bufs */