Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 Apr 1997 18:31:02 +0200
From:      Poul-Henning Kamp <phk@dk.tfs.com>
To:        Doug Rabson <dfr@nlsystems.com>
Cc:        Poul-Henning Kamp <phk@dk.tfs.com>, current@freebsd.org
Subject:   Re: vnode->v_usage 
Message-ID:  <207.862417862@critter>
In-Reply-To: Your message of "Sun, 27 Apr 1997 14:36:36 BST." <Pine.BSF.3.95q.970427143216.346G-100000@herring.nlsystems.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <Pine.BSF.3.95q.970427143216.346G-100000@herring.nlsystems.com>, Dou
g Rabson writes:
>On Sun, 27 Apr 1997, Poul-Henning Kamp wrote:
>> 
>> Unless somebody convinces me of the utility of this field, I will remove
>> it from the vnodes.
>> 
>I think it is intended to be used to keep frequently used vnodes from
>being recycled by getnewvnode.

Well, I've done it.  Here is a patch that implements LRU for name-cache
hits on the vnode freelist.  I doubt that it has any performance impact,
but it makes the vnode 4 bytes smaller, which is a good thing.

Please test and report.

Recompile or rename your LKMs before trying this!

Poul-Henning


Index: sys/vnode.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/vnode.h,v
retrieving revision 1.43
diff -u -r1.43 vnode.h
--- vnode.h	1997/04/04 17:43:32	1.43
+++ vnode.h	1997/04/30 16:12:08
@@ -104,7 +104,6 @@
 	daddr_t	v_cstart;			/* start block of cluster */
 	daddr_t	v_lasta;			/* last allocation */
 	int	v_clen;				/* length of current cluster */
-	int	v_usage;			/* Vnode usage counter */
 	struct vm_object *v_object;		/* Place to store VM object */
 	struct	simplelock v_interlock;		/* lock on usecount and flag */
 	struct	lock *v_vnlock;			/* used for non-locking fs's */
@@ -506,6 +505,7 @@
 	checkalias __P((struct vnode *vp, dev_t nvp_rdev, struct mount *mp));
 void 	vput __P((struct vnode *vp));
 void 	vrele __P((struct vnode *vp));
+void	vtouch __P((struct vnode *vp));
 #endif /* KERNEL */
 
 #endif /* !_SYS_VNODE_H_ */
Index: kern/vfs_cache.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_cache.c,v
retrieving revision 1.24
diff -u -r1.24 vfs_cache.c
--- vfs_cache.c	1997/03/08 15:22:14	1.24
+++ vfs_cache.c	1997/04/30 16:15:56
@@ -187,9 +187,9 @@
         if (ncp->nc_vp) {
 		nchstats.ncs_goodhits++;
 		TOUCH(ncp);
+		if (!ncp->nc_vp->v_usecount)	/* on the freelist, LRU it */
+			vtouch(ncp->nc_vp);
 		*vpp = ncp->nc_vp;
-		if ((*vpp)->v_usage < MAXVNODEUSE)
-			(*vpp)->v_usage++;
 		return (-1);
 	}
 
@@ -263,9 +263,9 @@
 	 */
 	ncp->nc_vp = vp;
 	if (vp) {
+		if (!vp->v_usecount)	/* on the freelist, LRU it */
+			vtouch(vp);
 		ncp->nc_vpid = vp->v_id;
-		if (vp->v_usage < MAXVNODEUSE)
-			++vp->v_usage;
 	} else
 		ncp->nc_vpid = cnp->cn_flags & ISWHITEOUT;
 	ncp->nc_dvp = dvp;
Index: kern/vfs_subr.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/vfs_subr.c,v
retrieving revision 1.83
diff -u -r1.83 vfs_subr.c
--- vfs_subr.c	1997/04/25 06:47:12	1.83
+++ vfs_subr.c	1997/04/30 16:13:35
@@ -382,12 +382,6 @@
 		if (vp->v_usecount)
 			panic("free vnode isn't");
 		TAILQ_REMOVE(&vnode_free_list, vp, v_freelist);
-		if (vp->v_usage > 0) {
-			simple_unlock(&vp->v_interlock);
-			--vp->v_usage;
-			TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
-			goto retry;
-		}
 		freevnodes--;
 
 		/* see comment on why 0xdeadb is set at end of vgone (below) */
@@ -420,7 +414,6 @@
 		vp->v_clen = 0;
 		vp->v_socket = 0;
 		vp->v_writecount = 0;	/* XXX */
-		vp->v_usage = 0;
 	}
 	vp->v_type = VNON;
 	cache_purge(vp);
@@ -1119,7 +1112,6 @@
 	simple_lock(&vnode_free_list_slock);
 	if (vp->v_flag & VAGE) {
 		vp->v_flag &= ~VAGE;
-		vp->v_usage = 0;
 		if(vp->v_tag != VT_TFS)
 			TAILQ_INSERT_HEAD(&vnode_free_list, vp, v_freelist);
 	} else {
@@ -2146,4 +2138,16 @@
 
 retn:
 	return error;
+}
+
+void
+vtouch(vp)
+	struct vnode *vp;
+{
+	if (vp->v_usecount)
+		return;
+	simple_lock(&vnode_free_list_slock);
+	TAILQ_REMOVE(&vnode_free_list, vp, v_freelist);
+	TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
+	simple_unlock(&vnode_free_list_slock);
 }


--
Poul-Henning Kamp           | phk@FreeBSD.ORG       FreeBSD Core-team.
http://www.freebsd.org/~phk | phk@login.dknet.dk    Private mailbox.
whois: [PHK]                | phk@tfs.com           TRW Financial Systems, Inc.
Power and ignorance is a disgusting cocktail.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?207.862417862>