From 0faa08a1442b9ebf0082dce5298b2f0a23604ba7 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Fri, 19 Jun 2009 10:25:12 -0700 Subject: [PATCH] HAMMER UTIL - Add -C cachesize option to improve the 'show' command. * Allows the default in-memory cache size of 16m to be changed. --- sbin/hammer/cache.c | 6 ++++++ sbin/hammer/hammer.8 | 8 ++++++++ sbin/hammer/hammer.c | 24 +++++++++++++++++++++++- sbin/hammer/hammer_util.h | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/sbin/hammer/cache.c b/sbin/hammer/cache.c index ee6637bada..1e9892e060 100644 --- a/sbin/hammer/cache.c +++ b/sbin/hammer/cache.c @@ -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) { diff --git a/sbin/hammer/hammer.8 b/sbin/hammer/hammer.8 index 45efe14513..ec3ea86868 100644 --- a/sbin/hammer/hammer.8 +++ b/sbin/hammer/hammer.8 @@ -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: diff --git a/sbin/hammer/hammer.c b/sbin/hammer/hammer.c index fa127c8ba5..8b7e1d7b45 100644 --- a/sbin/hammer/hammer.c +++ b/sbin/hammer/hammer.c @@ -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 */ diff --git a/sbin/hammer/hammer_util.h b/sbin/hammer/hammer_util.h index f5499e80ac..b4c767bebf 100644 --- a/sbin/hammer/hammer_util.h +++ b/sbin/hammer/hammer_util.h @@ -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); -- 2.41.0