HAMMER UTIL - Add -C cachesize option to improve the 'show' command.
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 19 Jun 2009 17:25:12 +0000 (10:25 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 19 Jun 2009 17:25:12 +0000 (10:25 -0700)
* Allows the default in-memory cache size of 16m to be changed.

sbin/hammer/cache.c
sbin/hammer/hammer.8
sbin/hammer/hammer.c
sbin/hammer/hammer_util.h

index ee6637b..1e9892e 100644 (file)
@@ -50,6 +50,12 @@ static int CacheMax = 16 * 1024 * 1024;
 static int NCache;
 static TAILQ_HEAD(, cache_info) CacheList = TAILQ_HEAD_INITIALIZER(CacheList);
 
+void
+hammer_cache_set(int bytes)
+{
+       CacheMax = bytes;
+}
+
 void
 hammer_cache_add(struct cache_info *cache, enum cache_type type)
 {
index 45efe14..ec3ea86 100644 (file)
@@ -47,6 +47,7 @@
 .\" .Op Fl s Ar linkpath
 .Op Fl i Ar delay
 .Op Fl t Ar seconds
+.Op Fl C Ar cachesize
 .Ar command
 .Op Ar argument ...
 .Sh DESCRIPTION
@@ -123,6 +124,13 @@ Increase verboseness.
 May be specified multiple times.
 .It Fl y
 Force "yes" for any interactive question.
+.It Fl C Ar cachesize
+Set the memory cache size for any raw I/O.  The default is 16m.
+A suffix of 'k' for kilobytes and 'm' for megabytes is allowed,
+else the cache size is specified in bytes.
+.Pp
+This option is typically only used with diagnostic commands
+as kernel-supported commands will use the kernel's buffer cache.
 .El
 .Pp
 The commands are as follows:
index fa127c8..8b7e1d7 100644 (file)
@@ -64,8 +64,9 @@ main(int ac, char **av)
        char *ptr;
        u_int32_t status;
        int ch;
+       int cacheSize = 0;
 
-       while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2y")) != -1) {
+       while ((ch = getopt(ac, av, "b:c:dhf:i:qrs:t:v2yC:")) != -1) {
                switch(ch) {
                case '2':
                        TwoWayPipeOpt = 1;
@@ -131,6 +132,27 @@ main(int ac, char **av)
                        else
                                ++QuietOpt;
                        break;
+               case 'C':
+                       cacheSize = strtol(optarg, &ptr, 0);
+                       switch(*ptr) {
+                       case 'm':
+                       case 'M':
+                               cacheSize *= 1024;
+                               /* fall through */
+                       case 'k':
+                       case 'K':
+                               cacheSize *= 1024;
+                               break;
+                       case '\0':
+                               /* bytes if no suffix */
+                               break;
+                       default:
+                               usage(1);
+                       }
+                       if (cacheSize < 1024 * 1024)
+                               cacheSize = 1024 * 1024;
+                       hammer_cache_set(cacheSize);
+                       break;
                default:
                        usage(1);
                        /* not reached */
index f5499e8..b4c767b 100644 (file)
@@ -143,6 +143,7 @@ void flush_all_volumes(void);
 void flush_volume(struct volume_info *vol);
 void flush_buffer(struct buffer_info *buf);
 
+void hammer_cache_set(int bytes);
 void hammer_cache_add(struct cache_info *cache, enum cache_type type);
 void hammer_cache_del(struct cache_info *cache);
 void hammer_cache_flush(void);