Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/dump Implement a read cache, as announced on tech-userl...



details:   https://anonhg.NetBSD.org/src/rev/7a6ba0835134
branches:  trunk
changeset: 467346:7a6ba0835134
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Mar 23 14:22:59 1999 +0000

description:
Implement a read cache, as announced on tech-userlevel. Default is 32k
read buffer size, 512 buffer or 15% of the user memory. Can be changed
with the -k and -s options.

diffstat:

 sbin/dump/Makefile   |    6 +-
 sbin/dump/dump.8     |   15 +-
 sbin/dump/dump.h     |    9 +-
 sbin/dump/main.c     |   25 ++-
 sbin/dump/rcache.c   |  445 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sbin/dump/tape.c     |    9 +-
 sbin/dump/traverse.c |   77 +--------
 7 files changed, 495 insertions(+), 91 deletions(-)

diffs (truncated from 768 to 300 lines):

diff -r a5527f396756 -r 7a6ba0835134 sbin/dump/Makefile
--- a/sbin/dump/Makefile        Tue Mar 23 13:52:48 1999 +0000
+++ b/sbin/dump/Makefile        Tue Mar 23 14:22:59 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.21 1999/03/09 17:25:52 bouyer Exp $
+#      $NetBSD: Makefile,v 1.22 1999/03/23 14:22:59 bouyer Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/5/93
 
 #      dump.h                  header file
@@ -16,8 +16,8 @@
 PROG=  dump
 LINKS= ${BINDIR}/dump ${BINDIR}/rdump
 CPPFLAGS+=-DRDUMP
-# CPPFLAGS+= -DDEBUG -DTDEBUG -DFDEBUG -DWRITEDEBUG
-SRCS=  itime.c main.c optr.c dumprmt.c tape.c traverse.c unctime.c \
+# CPPFLAGS+= -DDEBUG -DTDEBUG -DFDEBUG -DWRITEDEBUG -DSTATS -DDIAGNOSTICS
+SRCS=  itime.c main.c optr.c dumprmt.c rcache.c tape.c traverse.c unctime.c \
        ffs_bswap.c
 BINGRP=        tty
 BINMODE=2555
diff -r a5527f396756 -r 7a6ba0835134 sbin/dump/dump.8
--- a/sbin/dump/dump.8  Tue Mar 23 13:52:48 1999 +0000
+++ b/sbin/dump/dump.8  Tue Mar 23 14:22:59 1999 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: dump.8,v 1.31 1999/03/09 17:25:52 bouyer Exp $
+.\"    $NetBSD: dump.8,v 1.32 1999/03/23 14:22:59 bouyer Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"     Regents of the University of California.
@@ -49,7 +49,9 @@
 .Op Fl d Ar density
 .Op Fl f Ar file
 .Op Fl h Ar level
+.Op Fl k Ar read blocksize
 .Op Fl L Ar label
+.Op Fl r Ar cachesize
 .Op Fl s Ar feet
 .Op Fl T Ar date
 .Ar files-to-dump
@@ -170,6 +172,9 @@
 The default honor level is 1,
 so that incremental backups omit such files
 but full backups retain them.
+.It Fl k Ar read blocksize
+The size in kilobyte of the read buffers, rounded up to a multiple of the
+filesystem block size. Default is 32k.
 .It Fl L Ar label
 The user-supplied text string
 .Ar label
@@ -190,6 +195,14 @@
 .Qq operator
 by means similar to a
 .Xr wall 1 .
+.It Fl r Ar cachesize
+Use that many buffers for read cache operations. 
+A value of zero disables the read cache altogether, higher values
+improve read performance by reading larger data blocks from the
+disk and maintaining them in an LRU cache. See the 
+.Fl k
+option for the size of the buffers. Maximum is 512, the size of the cache is
+limited to 15% of the avail RAM by default.
 .It Fl s Ar feet
 Attempt to calculate the amount of tape needed
 at a particular density.
diff -r a5527f396756 -r 7a6ba0835134 sbin/dump/dump.h
--- a/sbin/dump/dump.h  Tue Mar 23 13:52:48 1999 +0000
+++ b/sbin/dump/dump.h  Tue Mar 23 14:22:59 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dump.h,v 1.15 1999/01/15 13:32:06 bouyer Exp $ */
+/*     $NetBSD: dump.h,v 1.16 1999/03/23 14:22:59 bouyer Exp $ */
 
 /*-
  * Copyright (c) 1980, 1993
@@ -146,11 +146,16 @@
 
 /* file dumping routines */
 void   blksout __P((daddr_t *blkp, int frags, ino_t ino));
-void   bread __P((daddr_t blkno, char *buf, int size));        
 void   dumpino __P((struct dinode *dp, ino_t ino));
 void   dumpmap __P((char *map, int type, ino_t ino));
 void   writeheader __P((ino_t ino));
 
+/* data block caching */
+void   bread __P((daddr_t blkno, char *buf, int size));        
+void   rawread __P((daddr_t, char *, int));
+void   initcache __P((int, int));
+void   printcachestats __P((void));
+
 /* tape writing routines */
 int    alloctape __P((void));
 void   close_rewind __P((void));
diff -r a5527f396756 -r 7a6ba0835134 sbin/dump/main.c
--- a/sbin/dump/main.c  Tue Mar 23 13:52:48 1999 +0000
+++ b/sbin/dump/main.c  Tue Mar 23 14:22:59 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.21 1999/01/03 02:17:46 lukem Exp $  */
+/*     $NetBSD: main.c,v 1.22 1999/03/23 14:22:59 bouyer Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.21 1999/01/03 02:17:46 lukem Exp $");
+__RCSID("$NetBSD: main.c,v 1.22 1999/03/23 14:22:59 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -93,6 +93,8 @@
 long   dev_bsize = 1;          /* recalculated below */
 long   blocksperfile = 0;      /* output blocks per file */
 char   *host = NULL;           /* remote host (if any) */
+int    readcache = -1;         /* read cache size (in readblksize blks) */
+int    readblksize = 32 * 1024; /* read block size */
 
 int    main __P((int, char *[]));
 static long numarg __P((char *, long, long));
@@ -136,7 +138,7 @@
 
        obsolete(&argc, &argv);
        while ((ch = getopt(argc, argv,
-           "0123456789B:b:cd:f:h:L:ns:ST:uWw")) != -1)
+           "0123456789B:b:cd:f:h:k:L:nr:s:ST:uWw")) != -1)
                switch (ch) {
                /* dump level */
                case '0': case '1': case '2': case '3': case '4':
@@ -171,6 +173,10 @@
                        honorlevel = numarg("honor level", 0L, 10L);
                        break;
 
+               case 'k':
+                       readblksize = numarg("read block size", 0, 64) * 1024;
+                       break;
+
                case 'L':
                        /*
                         * Note that although there are LBLSIZE characters,
@@ -191,6 +197,10 @@
                        notify = 1;
                        break;
 
+               case 'r':               /* read cache size */
+                       readcache = numarg("read cache size", 0, 512);
+                       break;
+               
                case 's':               /* tape size, feet */
                        tsize = numarg("tape size", 1L, 0L) * 12 * 10;
                        break;
@@ -379,7 +389,7 @@
        }
        sync();
        sblock = (struct fs *)sblock_buf;
-       bread(SBOFF, (char *) sblock, SBSIZE);
+       rawread(SBOFF, (char *) sblock, SBSIZE);
        if (sblock->fs_magic != FS_MAGIC) {
                if (sblock->fs_magic == bswap32(FS_MAGIC)) {
                        ffs_sb_swap(sblock, sblock, 0);
@@ -442,6 +452,8 @@
 
        nonodump = iswap32(spcl.c_level) < honorlevel;
 
+       initcache(readcache, readblksize);
+       
        (void)signal(SIGINFO, statussig);
 
        msg("mapping (Pass I) [regular files]\n");
@@ -582,9 +594,10 @@
 usage()
 {
 
-       (void)fprintf(stderr, "%s\n%s\n%s\n",
+       (void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
 "usage: dump [-0123456789cnu] [-B records] [-b blocksize] [-d density]",
-"            [-f file] [-h level] [-L label] [-s feet] [-T date] filesystem",
+"            [-f file] [-h level] [-k read block size] [-L label]",
+"            [-r read cache size] [-s feet] [-T date] filesystem",
 "       dump [-W | -w]");
        exit(1);
 }
diff -r a5527f396756 -r 7a6ba0835134 sbin/dump/rcache.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/dump/rcache.c        Tue Mar 23 14:22:59 1999 +0000
@@ -0,0 +1,445 @@
+/*      $NetBSD: rcache.c,v 1.1 1999/03/23 14:22:59 bouyer Exp $       */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Martin J. Laubach <mjl%emsi.priv.at@localhost> and 
+ *    Manuel Bouyer <Manuel.Bouyer%lip6.fr@localhost>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the NetBSD
+ *      Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/*-----------------------------------------------------------------------*/
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+
+#include "dump.h"
+
+/*-----------------------------------------------------------------------*/
+#define MAXCACHEBUFS   512     /* max 512 buffers */
+#define MAXMEMPART     6       /* max 15% of the user mem */
+
+/*-----------------------------------------------------------------------*/
+struct cheader {
+       volatile size_t count;
+};
+
+struct cdesc {
+       volatile daddr_t blkstart;
+       volatile daddr_t blkend;/* start + nblksread */
+       volatile daddr_t blocksRead;
+       volatile size_t time;
+#ifdef DIAGNOSTICS
+       volatile pid_t owner;
+#endif
+};
+
+static int findlru __P((void));
+
+static void *shareBuffer = NULL;
+static struct cheader *cheader;
+static struct cdesc *cdesc;
+static char *cdata;
+static int cachebufs;
+static int nblksread;
+
+#ifdef STATS
+static int nreads;
+static int nphysread;
+static int64_t readsize;
+static int64_t physreadsize;
+#endif
+
+#define CDATA(i)       (cdata + ((i) * nblksread * dev_bsize))
+
+/*-----------------------------------------------------------------------*/
+void 
+initcache(cachesize, readblksize)
+       int cachesize;
+       int readblksize;
+{
+       size_t len;
+       size_t  sharedSize;
+
+       nblksread = (readblksize + sblock->fs_bsize - 1) / sblock->fs_bsize;
+       if(cachesize == -1) {   /* Compute from memory available */
+               int usermem;
+               int mib[2] = { CTL_HW, HW_USERMEM };
+               
+               len = sizeof(usermem);
+               if (sysctl(mib, 2, &usermem, &len, NULL, 0) < 0) {
+                       msg("sysctl(hw.usermem) failed: %s\n", strerror(errno));
+                       return;
+               }
+               cachebufs = (usermem / MAXMEMPART) / (nblksread * dev_bsize);
+       } else {                /* User specified */
+               cachebufs = cachesize;
+       }



Home | Main Index | Thread Index | Old Index