Module Name: src Committed By: hannken Date: Mon Aug 21 08:56:45 UTC 2017
Modified Files: src/sys/kern: vfs_vnode.c src/sys/miscfs/deadfs: dead_vfsops.c Log Message: No need to cache anonymous device vnodes, they will never be looked up. Set key to (dead_rootmount, 0, NULL) and add assertions. To generate a diff of this commit: cvs rdiff -u -r1.96 -r1.97 src/sys/kern/vfs_vnode.c cvs rdiff -u -r1.7 -r1.8 src/sys/miscfs/deadfs/dead_vfsops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/vfs_vnode.c diff -u src/sys/kern/vfs_vnode.c:1.96 src/sys/kern/vfs_vnode.c:1.97 --- src/sys/kern/vfs_vnode.c:1.96 Sun Jun 4 08:05:42 2017 +++ src/sys/kern/vfs_vnode.c Mon Aug 21 08:56:45 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: vfs_vnode.c,v 1.96 2017/06/04 08:05:42 hannken Exp $ */ +/* $NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $ */ /*- * Copyright (c) 1997-2011 The NetBSD Foundation, Inc. @@ -156,7 +156,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.96 2017/06/04 08:05:42 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.97 2017/08/21 08:56:45 hannken Exp $"); #include <sys/param.h> #include <sys/kernel.h> @@ -1028,6 +1028,8 @@ vcache_hash(const struct vcache_key *key { uint32_t hash = HASH32_BUF_INIT; + KASSERT(key->vk_key_len > 0); + hash = hash32_buf(&key->vk_mount, sizeof(struct mount *), hash); hash = hash32_buf(key->vk_key, key->vk_key_len, hash); return hash; @@ -1381,23 +1383,29 @@ vcache_new(struct mount *mp, struct vnod KASSERT(*vpp == NULL); return error; } - KASSERT(vip->vi_key.vk_key != NULL); KASSERT(vp->v_op != NULL); - hash = vcache_hash(&vip->vi_key); + KASSERT((vip->vi_key.vk_key_len == 0) == (mp == dead_rootmount)); + if (vip->vi_key.vk_key_len > 0) { + KASSERT(vip->vi_key.vk_key != NULL); + hash = vcache_hash(&vip->vi_key); - /* Wait for previous instance to be reclaimed, then insert new node. */ - mutex_enter(&vcache_lock); - while ((ovip = vcache_hash_lookup(&vip->vi_key, hash))) { - ovp = VIMPL_TO_VNODE(ovip); - mutex_enter(ovp->v_interlock); - mutex_exit(&vcache_lock); - error = vcache_vget(ovp); - KASSERT(error == ENOENT); + /* + * Wait for previous instance to be reclaimed, + * then insert new node. + */ mutex_enter(&vcache_lock); + while ((ovip = vcache_hash_lookup(&vip->vi_key, hash))) { + ovp = VIMPL_TO_VNODE(ovip); + mutex_enter(ovp->v_interlock); + mutex_exit(&vcache_lock); + error = vcache_vget(ovp); + KASSERT(error == ENOENT); + mutex_enter(&vcache_lock); + } + SLIST_INSERT_HEAD(&vcache_hashtab[hash & vcache_hashmask], + vip, vi_hash); + mutex_exit(&vcache_lock); } - SLIST_INSERT_HEAD(&vcache_hashtab[hash & vcache_hashmask], - vip, vi_hash); - mutex_exit(&vcache_lock); vfs_insmntque(vp, mp); if ((mp->mnt_iflag & IMNT_MPSAFE) != 0) vp->v_vflag |= VV_MPSAFE; @@ -1556,10 +1564,12 @@ vcache_reclaim(vnode_t *vp) } else { temp_key = temp_buf; } - mutex_enter(&vcache_lock); - memcpy(temp_key, vip->vi_key.vk_key, temp_key_len); - vip->vi_key.vk_key = temp_key; - mutex_exit(&vcache_lock); + if (vip->vi_key.vk_key_len > 0) { + mutex_enter(&vcache_lock); + memcpy(temp_key, vip->vi_key.vk_key, temp_key_len); + vip->vi_key.vk_key = temp_key; + mutex_exit(&vcache_lock); + } fstrans_start(mp); @@ -1604,13 +1614,15 @@ vcache_reclaim(vnode_t *vp) /* Purge name cache. */ cache_purge(vp); + if (vip->vi_key.vk_key_len > 0) { /* Remove from vnode cache. */ - hash = vcache_hash(&vip->vi_key); - mutex_enter(&vcache_lock); - KASSERT(vip == vcache_hash_lookup(&vip->vi_key, hash)); - SLIST_REMOVE(&vcache_hashtab[hash & vcache_hashmask], - vip, vnode_impl, vi_hash); - mutex_exit(&vcache_lock); + hash = vcache_hash(&vip->vi_key); + mutex_enter(&vcache_lock); + KASSERT(vip == vcache_hash_lookup(&vip->vi_key, hash)); + SLIST_REMOVE(&vcache_hashtab[hash & vcache_hashmask], + vip, vnode_impl, vi_hash); + mutex_exit(&vcache_lock); + } if (temp_key != temp_buf) kmem_free(temp_key, temp_key_len); Index: src/sys/miscfs/deadfs/dead_vfsops.c diff -u src/sys/miscfs/deadfs/dead_vfsops.c:1.7 src/sys/miscfs/deadfs/dead_vfsops.c:1.8 --- src/sys/miscfs/deadfs/dead_vfsops.c:1.7 Wed Jul 1 08:13:53 2015 +++ src/sys/miscfs/deadfs/dead_vfsops.c Mon Aug 21 08:56:45 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: dead_vfsops.c,v 1.7 2015/07/01 08:13:53 hannken Exp $ */ +/* $NetBSD: dead_vfsops.c,v 1.8 2017/08/21 08:56:45 hannken Exp $ */ /*- * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dead_vfsops.c,v 1.7 2015/07/01 08:13:53 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dead_vfsops.c,v 1.8 2017/08/21 08:56:45 hannken Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -108,8 +108,8 @@ dead_newvnode(struct mount *mp, struct v uvm_vnp_setsize(vp, 0); spec_node_init(vp, vap->va_rdev); - *key_len = sizeof(vp->v_interlock); - *new_key = &vp->v_interlock; + *key_len = 0; + *new_key = NULL; return 0; }