From 99c9264eec8fe529aa3074c739ecc4f9a2212714 Mon Sep 17 00:00:00 2001 From: tholo Date: Mon, 14 Apr 1997 04:23:21 +0000 Subject: [PATCH] Minor performance enhancements from NetBSD --- sys/kern/vfs_bio.c | 36 ++++++++++++++++++++++++++++++++++-- sys/kern/vfs_subr.c | 8 +++----- sys/sys/buf.h | 5 +++-- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 33ad1cad470..ffa423f0c88 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.13 1997/01/05 11:09:01 niklas Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.14 1997/04/14 04:23:23 tholo Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /*- @@ -602,6 +602,20 @@ brelse(bp) if (ISSET(bp->b_flags, (B_NOCACHE|B_ERROR))) SET(bp->b_flags, B_INVAL); + if (ISSET(bp->b_flags, B_VFLUSH)) { + /* + * This is a delayed write buffer that was just flushed to + * disk. It is still on the LRU queue. If it's become + * invalid, then we need to move it to a different queue; + * otherwise leave it in its current position. + */ + CLR(bp->b_flags, B_VFLUSH); + if (!ISSET(bp->b_flags, B_ERROR|B_INVAL|B_LOCKED|B_AGE)) + goto already_queued; + else + bremfree(bp); + } + if ((bp->b_bufsize <= 0) || ISSET(bp->b_flags, B_INVAL)) { /* * If it's invalid or empty, dissociate it from its vnode @@ -636,6 +650,7 @@ brelse(bp) binstailfree(bp, bufq); } +already_queued: /* Unlock the buffer. */ CLR(bp->b_flags, (B_AGE | B_ASYNC | B_BUSY | B_NOCACHE)); @@ -870,13 +885,30 @@ start: return (0); } + if (ISSET(bp->b_flags, B_VFLUSH)) { + /* + * This is a delayed write buffer being flushed to disk. Make + * sure it gets aged out of the queue when it's finished, and + * leave it off the LRU queue. + */ + CLR(bp->b_flags, B_VFLUSH); + SET(bp->b_flags, B_AGE); + splx(s); + goto start; + } + /* Buffer is no longer on free lists. */ SET(bp->b_flags, B_BUSY); /* If buffer was a delayed write, start it, and go back to the top. */ if (ISSET(bp->b_flags, B_DELWRI)) { splx(s); - bawrite (bp); + /* + * This buffer has gone through the LRU, so make sure it gets + * reused ASAP. + */ + SET(bp->b_flags, B_AGE); + bawrite(bp); goto start; } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 2c05c9f01f8..0d2ac94fbc1 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_subr.c,v 1.8 1997/02/24 14:20:02 niklas Exp $ */ +/* $OpenBSD: vfs_subr.c,v 1.9 1997/04/14 04:23:26 tholo Exp $ */ /* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */ /* @@ -467,8 +467,7 @@ vinvalbuf(vp, flags, cred, p, slpflag, slptimeo) return (error); break; } - bremfree(bp); - bp->b_flags |= B_BUSY; + bp->b_flags |= B_BUSY | B_VFLUSH; splx(s); /* * XXX Since there are no node locks for NFS, I believe @@ -505,8 +504,7 @@ loop: continue; if ((bp->b_flags & B_DELWRI) == 0) panic("vflushbuf: not dirty"); - bremfree(bp); - bp->b_flags |= B_BUSY; + bp->b_flags |= B_BUSY | B_VFLUSH; splx(s); /* * Wait for I/O associated with indirect blocks to complete, diff --git a/sys/sys/buf.h b/sys/sys/buf.h index 888eca306c6..c96a71a1765 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -1,5 +1,5 @@ -/* $OpenBSD: buf.h,v 1.5 1996/06/11 03:25:14 tholo Exp $ */ -/* $NetBSD: buf.h,v 1.24 1996/02/18 11:55:45 fvdl Exp $ */ +/* $OpenBSD: buf.h,v 1.6 1997/04/14 04:23:21 tholo Exp $ */ +/* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -124,6 +124,7 @@ struct buf { #define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */ #define B_WRITEINPROG 0x01000000 /* Write in progress. */ #define B_XXX 0x02000000 /* Debugging flag. */ +#define B_VFLUSH 0x04000000 /* Buffer is being synced. */ /* * This structure describes a clustered I/O. It is stored in the b_saveaddr -- 2.20.1