Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Merge the vnode and its corresponding vcache_node into one
details: https://anonhg.NetBSD.org/src/rev/f4bc1a5e99d1
branches: trunk
changeset: 345428:f4bc1a5e99d1
user: hannken <hannken%NetBSD.org@localhost>
date: Thu May 26 11:07:33 2016 +0000
description:
Merge the vnode and its corresponding vcache_node into one
vcache_node structure.
Print the vcache_node part in vprint() and vfs_vnode_print().
Presented on tech-kern@
diffstat:
sys/kern/vfs_subr.c | 9 +-
sys/kern/vfs_vnode.c | 209 ++++++++++++++++++++++++++++----------------------
sys/sys/vnode.h | 4 +-
3 files changed, 126 insertions(+), 96 deletions(-)
diffs (truncated from 426 to 300 lines):
diff -r ae4906b51443 -r f4bc1a5e99d1 sys/kern/vfs_subr.c
--- a/sys/kern/vfs_subr.c Thu May 26 10:38:07 2016 +0000
+++ b/sys/kern/vfs_subr.c Thu May 26 11:07:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_subr.c,v 1.448 2015/08/24 22:50:32 pooka Exp $ */
+/* $NetBSD: vfs_subr.c,v 1.449 2016/05/26 11:07:33 hannken Exp $ */
/*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.448 2015/08/24 22:50:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.449 2016/05/26 11:07:33 hannken Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -76,6 +76,8 @@
#include "opt_compat_43.h"
#endif
+#define _VFS_VNODE_PRIVATE /* for vcache_print(). */
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
@@ -1085,6 +1087,7 @@
ARRAY_PRINT(vp->v_type, vnode_types), vp->v_type,
vp->v_usecount, vp->v_writecount, vp->v_holdcnt,
vp->v_freelisthd, vp->v_mount, vp->v_data, &vp->v_lock);
+ vcache_print(vp, "\t", printf);
if (vp->v_data != NULL) {
printf("\t");
VOP_PRINT(vp);
@@ -1481,6 +1484,8 @@
(*pr)("v_lock %p\n", &vp->v_lock);
+ vcache_print(vp, "", pr);
+
if (full) {
struct buf *bp;
diff -r ae4906b51443 -r f4bc1a5e99d1 sys/kern/vfs_vnode.c
--- a/sys/kern/vfs_vnode.c Thu May 26 10:38:07 2016 +0000
+++ b/sys/kern/vfs_vnode.c Thu May 26 11:07:33 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vfs_vnode.c,v 1.49 2016/05/19 14:50:18 hannken Exp $ */
+/* $NetBSD: vfs_vnode.c,v 1.50 2016/05/26 11:07:33 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@@ -116,7 +116,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.49 2016/05/19 14:50:18 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.50 2016/05/26 11:07:33 hannken Exp $");
#define _VFS_VNODE_PRIVATE
@@ -154,14 +154,16 @@
size_t vk_key_len;
};
struct vcache_node {
+ struct vnode vn_data;
SLIST_ENTRY(vcache_node) vn_hash;
struct vnode *vn_vnode;
struct vcache_key vn_key;
};
-u_int numvnodes __cacheline_aligned;
+#define VN_TO_VP(node) ((vnode_t *)(node))
+#define VP_TO_VN(vp) ((struct vcache_node *)(vp))
-static pool_cache_t vnode_cache __read_mostly;
+u_int numvnodes __cacheline_aligned;
/*
* There are two free lists: one is for vnodes which have no buffer/page
@@ -189,14 +191,14 @@
} vcache __cacheline_aligned;
static int cleanvnode(void);
+static struct vcache_node *vcache_alloc(void);
+static void vcache_free(struct vcache_node *);
static void vcache_init(void);
static void vcache_reinit(void);
static void vclean(vnode_t *);
static void vrelel(vnode_t *, int);
static void vdrain_thread(void *);
static void vrele_thread(void *);
-static vnode_t * vnalloc(struct mount *);
-static void vnfree(vnode_t *);
static void vnpanic(vnode_t *, const char *, ...)
__printflike(2, 3);
static void vwait(vnode_t *, int);
@@ -211,10 +213,6 @@
{
int error __diagused;
- vnode_cache = pool_cache_init(sizeof(vnode_t), 0, 0, 0, "vnodepl",
- NULL, IPL_NONE, NULL, NULL, NULL);
- KASSERT(vnode_cache != NULL);
-
dead_rootmount = vfs_mountalloc(&dead_vfsops, NULL);
KASSERT(dead_rootmount != NULL);
dead_rootmount->mnt_iflag = IMNT_MPSAFE;
@@ -243,8 +241,18 @@
vnode_t *
vnalloc_marker(struct mount *mp)
{
+ struct vcache_node *node;
+ vnode_t *vp;
- return vnalloc(mp);
+ node = pool_cache_get(vcache.pool, PR_WAITOK);
+ memset(node, 0, sizeof(*node));
+ vp = VN_TO_VP(node);
+ uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 0);
+ vp->v_mount = mp;
+ vp->v_type = VBAD;
+ vp->v_iflag = VI_MARKER;
+
+ return vp;
}
/*
@@ -253,9 +261,12 @@
void
vnfree_marker(vnode_t *vp)
{
+ struct vcache_node *node;
+ node = VP_TO_VN(vp);
KASSERT(ISSET(vp->v_iflag, VI_MARKER));
- vnfree(vp);
+ uvm_obj_destroy(&vp->v_uobj, true);
+ pool_cache_put(vcache.pool, node);
}
/*
@@ -269,69 +280,6 @@
}
/*
- * Allocate a new, uninitialized vnode. If 'mp' is non-NULL, this is a
- * marker vnode.
- */
-static vnode_t *
-vnalloc(struct mount *mp)
-{
- vnode_t *vp;
-
- vp = pool_cache_get(vnode_cache, PR_WAITOK);
- KASSERT(vp != NULL);
-
- memset(vp, 0, sizeof(*vp));
- uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 0);
- cv_init(&vp->v_cv, "vnode");
- /*
- * Done by memset() above.
- * LIST_INIT(&vp->v_nclist);
- * LIST_INIT(&vp->v_dnclist);
- */
-
- if (mp != NULL) {
- vp->v_mount = mp;
- vp->v_type = VBAD;
- vp->v_iflag = VI_MARKER;
- return vp;
- }
-
- mutex_enter(&vnode_free_list_lock);
- numvnodes++;
- if (numvnodes > desiredvnodes + desiredvnodes / 10)
- cv_signal(&vdrain_cv);
- mutex_exit(&vnode_free_list_lock);
-
- rw_init(&vp->v_lock);
- vp->v_usecount = 1;
- vp->v_type = VNON;
- vp->v_size = vp->v_writesize = VSIZENOTSET;
-
- return vp;
-}
-
-/*
- * Free an unused, unreferenced vnode.
- */
-static void
-vnfree(vnode_t *vp)
-{
-
- KASSERT(vp->v_usecount == 0);
-
- if ((vp->v_iflag & VI_MARKER) == 0) {
- rw_destroy(&vp->v_lock);
- mutex_enter(&vnode_free_list_lock);
- numvnodes--;
- mutex_exit(&vnode_free_list_lock);
- }
-
- uvm_obj_destroy(&vp->v_uobj, true);
- cv_destroy(&vp->v_cv);
- pool_cache_put(vnode_cache, vp);
-}
-
-/*
* cleanvnode: grab a vnode from freelist, clean and free it.
*
* => Releases vnode_free_list_lock.
@@ -740,7 +688,7 @@
if (vp->v_type == VBLK || vp->v_type == VCHR) {
spec_node_destroy(vp);
}
- vnfree(vp);
+ vcache_free(VP_TO_VN(vp));
} else {
/*
* Otherwise, put it back onto the freelist. It
@@ -1156,6 +1104,63 @@
}
/*
+ * Allocate a new, uninitialized vcache node.
+ */
+static struct vcache_node *
+vcache_alloc(void)
+{
+ struct vcache_node *node;
+ vnode_t *vp;
+
+ node = pool_cache_get(vcache.pool, PR_WAITOK);
+ memset(node, 0, sizeof(*node));
+
+ /* SLIST_INIT(&node->vn_hash); */
+
+ vp = VN_TO_VP(node);
+ uvm_obj_init(&vp->v_uobj, &uvm_vnodeops, true, 0);
+ cv_init(&vp->v_cv, "vnode");
+ /* LIST_INIT(&vp->v_nclist); */
+ /* LIST_INIT(&vp->v_dnclist); */
+
+ mutex_enter(&vnode_free_list_lock);
+ numvnodes++;
+ if (numvnodes > desiredvnodes + desiredvnodes / 10)
+ cv_signal(&vdrain_cv);
+ mutex_exit(&vnode_free_list_lock);
+
+ rw_init(&vp->v_lock);
+ vp->v_usecount = 1;
+ vp->v_type = VNON;
+ vp->v_size = vp->v_writesize = VSIZENOTSET;
+
+ return node;
+}
+
+/*
+ * Free an unused, unreferenced vcache node.
+ */
+static void
+vcache_free(struct vcache_node *node)
+{
+ vnode_t *vp;
+
+ vp = VN_TO_VP(node);
+
+ KASSERT(vp->v_usecount == 0);
+ KASSERT((vp->v_iflag & VI_MARKER) == 0);
+
+ rw_destroy(&vp->v_lock);
+ mutex_enter(&vnode_free_list_lock);
+ numvnodes--;
+ mutex_exit(&vnode_free_list_lock);
+
+ uvm_obj_destroy(&vp->v_uobj, true);
+ cv_destroy(&vp->v_cv);
+ pool_cache_put(vcache.pool, node);
+}
+
+/*
* Get a vnode / fs node pair by key and return it referenced through vpp.
*/
int
@@ -1208,10 +1213,9 @@
error = vfs_busy(mp, NULL);
if (error)
return error;
- new_node = pool_cache_get(vcache.pool, PR_WAITOK);
- new_node->vn_vnode = NULL;
+ new_node = vcache_alloc();
new_node->vn_key = vcache_key;
- vp = vnalloc(NULL);
+ vp = VN_TO_VP(new_node);
mutex_enter(&vcache.lock);
node = vcache_hash_lookup(&vcache_key, hash);
if (node == NULL) {
@@ -1223,10 +1227,9 @@
Home |
Main Index |
Thread Index |
Old Index