Module Name:    src
Committed By:   ad
Date:           Wed Jan  8 12:04:57 UTC 2020

Modified Files:
        src/sbin/mount_procfs: mount_procfs.8
        src/sys/conf: files
        src/sys/kern: vfs_cache.c vfs_getcwd.c vfs_vnode.c
        src/sys/sys: namei.src vnode_impl.h

Log Message:
- 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.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sbin/mount_procfs/mount_procfs.8
cvs rdiff -u -r1.1248 -r1.1249 src/sys/conf/files
cvs rdiff -u -r1.126 -r1.127 src/sys/kern/vfs_cache.c
cvs rdiff -u -r1.53 -r1.54 src/sys/kern/vfs_getcwd.c
cvs rdiff -u -r1.105 -r1.106 src/sys/kern/vfs_vnode.c
cvs rdiff -u -r1.47 -r1.48 src/sys/sys/namei.src
cvs rdiff -u -r1.19 -r1.20 src/sys/sys/vnode_impl.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/mount_procfs/mount_procfs.8
diff -u src/sbin/mount_procfs/mount_procfs.8:1.37 src/sbin/mount_procfs/mount_procfs.8:1.38
--- src/sbin/mount_procfs/mount_procfs.8:1.37	Mon Aug 28 05:58:08 2017
+++ src/sbin/mount_procfs/mount_procfs.8	Wed Jan  8 12:04:57 2020
@@ -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.

Index: src/sys/conf/files
diff -u src/sys/conf/files:1.1248 src/sys/conf/files:1.1249
--- src/sys/conf/files:1.1248	Mon Dec 23 06:45:37 2019
+++ src/sys/conf/files	Wed Jan  8 12:04:56 2020
@@ -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_BSD
 
 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

Index: src/sys/kern/vfs_cache.c
diff -u src/sys/kern/vfs_cache.c:1.126 src/sys/kern/vfs_cache.c:1.127
--- src/sys/kern/vfs_cache.c:1.126	Mon Jan  6 11:22:33 2020
+++ src/sys/kern/vfs_cache.c	Wed Jan  8 12:04:56 2020
@@ -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,
  * - 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
 	 */
 	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 vn
 	/* 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 cha
 	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 (
 	}
 	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);
 		}
 	}

Index: src/sys/kern/vfs_getcwd.c
diff -u src/sys/kern/vfs_getcwd.c:1.53 src/sys/kern/vfs_getcwd.c:1.54
--- src/sys/kern/vfs_getcwd.c:1.53	Sat Sep 14 21:23:34 2019
+++ src/sys/kern/vfs_getcwd.c	Wed Jan  8 12:04:56 2020
@@ -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

Index: src/sys/kern/vfs_vnode.c
diff -u src/sys/kern/vfs_vnode.c:1.105 src/sys/kern/vfs_vnode.c:1.106
--- src/sys/kern/vfs_vnode.c:1.105	Mon Dec 16 22:47:54 2019
+++ src/sys/kern/vfs_vnode.c	Wed Jan  8 12:04:56 2020
@@ -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);

Index: src/sys/sys/namei.src
diff -u src/sys/sys/namei.src:1.47 src/sys/sys/namei.src:1.48
--- src/sys/sys/namei.src:1.47	Mon Jan  6 11:22:33 2020
+++ src/sys/sys/namei.src	Wed Jan  8 12:04:56 2020
@@ -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 */

Index: src/sys/sys/vnode_impl.h
diff -u src/sys/sys/vnode_impl.h:1.19 src/sys/sys/vnode_impl.h:1.20
--- src/sys/sys/vnode_impl.h:1.19	Sun Dec 22 19:47:34 2019
+++ src/sys/sys/vnode_impl.h	Wed Jan  8 12:04:56 2020
@@ -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 */

Reply via email to