From 3927beeda173665780b5c46e57ce664ac66137bc Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Tue, 17 Oct 2000 00:41:36 +0000 Subject: [PATCH] Implement simple write combining for newfs - this is particularly useful for large scsi disks with WCE = 0. This yields around a 7 times speedup on elapsed newfs time on test disks here. 64k clusters seems to be the sweet spot for scsi disks using our present drivers. --- sbin/newfs/mkfs.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c index 615b5c2feb47..fea37d6e50d6 100644 --- a/sbin/newfs/mkfs.c +++ b/sbin/newfs/mkfs.c @@ -1324,6 +1324,11 @@ rdfs(bno, size, bf) } } +#define WCSIZE (128 * 1024) +daddr_t wc_sect; /* units of sectorsize */ +int wc_end; /* bytes */ +static char wc[WCSIZE]; /* bytes */ + /* * write a block to the file system */ @@ -1334,6 +1339,7 @@ wtfs(bno, size, bf) char *bf; { int n; + int done; if (mfs) { memmove(membase + bno * sectorsize, bf, size); @@ -1341,6 +1347,37 @@ wtfs(bno, size, bf) } if (Nflag) return; + done = 0; + if (wc_end == 0 && size <= WCSIZE) { + wc_sect = bno; + bcopy(bf, wc, size); + wc_end = size; + if (wc_end < WCSIZE) + return; + done = 1; + } + if (wc_sect * sectorsize + wc_end == bno * sectorsize && + wc_end + size <= WCSIZE) { + bcopy(bf, wc + wc_end, size); + wc_end += size; + if (wc_end < WCSIZE) + return; + done = 1; + } + if (wc_end) { + if (lseek(fso, (off_t)wc_sect * sectorsize, SEEK_SET) < 0) { + printf("seek error: %ld\n", (long)wc_sect); + err(35, "wtfs - writecombine"); + } + n = write(fso, wc, wc_end); + if (n != wc_end) { + printf("write error: %ld\n", (long)wc_sect); + err(36, "wtfs - writecombine"); + } + wc_end = 0; + } + if (done) + return; if (lseek(fso, (off_t)bno * sectorsize, SEEK_SET) < 0) { printf("seek error: %ld\n", (long)bno); err(35, "wtfs");