From: Madan Valluri Date: Wed, 24 May 2006 01:37:54 +0000 (+0000) Subject: Instrumentation of new cache code. X-Git-Tag: v2.9.0~92 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f38f08d5ebcd8bacd52c9d08a7800b8c53cc7dd;p=thirdparty%2Fxfsprogs-dev.git Instrumentation of new cache code. Adjust cache hash bucket size from command line. 1) Added additional fields to cache struct 2) Added cache_report function prototype. --- diff --git a/include/cache.h b/include/cache.h index 3cccbd831..0515163cd 100644 --- a/include/cache.h +++ b/include/cache.h @@ -54,6 +54,9 @@ struct cache { cache_bulk_relse_t bulkrelse; /* bulk release routine */ unsigned int c_hashsize; /* hash bucket count */ struct cache_hash *c_hash; /* hash table buckets */ + unsigned long long c_misses; /* cache misses */ + unsigned long long c_hits; /* cache hits */ + unsigned int c_max; /* max nodes ever used */ }; struct cache_hash { @@ -75,5 +78,6 @@ void cache_purge(struct cache *); int cache_node_get(struct cache *, cache_key_t, struct cache_node **); void cache_node_put(struct cache_node *); int cache_node_purge(struct cache *, cache_key_t, struct cache_node *); +void cache_report(const char *, struct cache *); #endif /* __CACHE_H__ */ diff --git a/include/libxfs.h b/include/libxfs.h index fc855bcac..b17b79f86 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -106,6 +106,7 @@ extern int libxfs_device_to_fd (dev_t); extern dev_t libxfs_device_open (char *, int, int, int); extern void libxfs_device_zero (dev_t, xfs_daddr_t, uint); extern void libxfs_device_close (dev_t); +extern void libxfs_report(void); /* check or write log footer: specify device, log size in blocks & uuid */ typedef xfs_caddr_t (libxfs_get_block_t)(xfs_caddr_t, int, void *); @@ -223,7 +224,7 @@ enum xfs_buf_flags_t { /* b_flags bits */ LIBXFS_B_EXIT = 0x0001, /* ==LIBXFS_EXIT_ON_FAILURE */ LIBXFS_B_DIRTY = 0x0002, /* buffer has been modified */ LIBXFS_B_STALE = 0x0004, /* buffer marked as invalid */ - LIBXFS_B_UPTODATE = 0x0008, /* buffer is sync'd to disk */ + LIBXFS_B_UPTODATE = 0x0008 /* buffer is sync'd to disk */ }; #define XFS_BUF_PTR(bp) ((bp)->b_addr) @@ -259,6 +260,9 @@ extern xfs_buf_t *libxfs_getbuf (dev_t, xfs_daddr_t, int); extern void libxfs_putbuf (xfs_buf_t *); extern void libxfs_purgebuf (xfs_buf_t *); +extern int libxfs_bhash_size; +extern int libxfs_ihash_size; + #define LIBXFS_BREAD 0x1 #define LIBXFS_BWRITE 0x2 #define LIBXFS_BZERO 0x4 diff --git a/libxfs/cache.c b/libxfs/cache.c index 587ab1a71..66ae9b7f8 100644 --- a/libxfs/cache.c +++ b/libxfs/cache.c @@ -48,6 +48,9 @@ cache_init( } cache->c_count = 0; + cache->c_max = 0; + cache->c_hits = 0; + cache->c_misses = 0; cache->c_maxcount = maxcount; cache->c_hashsize = hashsize; cache->hash = cache_operations->hash; @@ -262,8 +265,12 @@ cache_node_allocate( struct cache_node * node; pthread_mutex_lock(&cache->c_mutex); - if ((nodesfree = (cache->c_count < cache->c_maxcount))) + if ((nodesfree = (cache->c_count < cache->c_maxcount))) { cache->c_count++; + if (cache->c_count > cache->c_max) + cache->c_max = cache->c_count; + } + cache->c_misses++; pthread_mutex_unlock(&cache->c_mutex); if (!nodesfree) return NULL; @@ -312,6 +319,9 @@ cache_node_get( pthread_mutex_lock(&node->cn_mutex); node->cn_count++; pthread_mutex_unlock(&node->cn_mutex); + pthread_mutex_lock(&cache->c_mutex); + cache->c_hits++; + pthread_mutex_unlock(&cache->c_mutex); break; } if (pos == head) { @@ -397,3 +407,25 @@ cache_purge( } #endif } + +void +cache_report(const char *name, struct cache * cache) +{ + fprintf(stderr, "%s: %p\n" + "Max supported entries = %u\n" + "Max utilized entries = %u\n" + "Active entries = %u\n" + "Hash table size = %u\n" + "Hits = %llu\n" + "Misses = %llu\n" + "Hit ratio = %5.2f\n", + name, cache, + cache->c_maxcount, + cache->c_max, + cache->c_count, + cache->c_hashsize, + cache->c_hits, + cache->c_misses, + (double) (cache->c_hits*100/(cache->c_hits+cache->c_misses)) + ); +} diff --git a/libxfs/init.c b/libxfs/init.c index acee677d0..2dfdeeb61 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -26,10 +26,10 @@ char *progname = "libxfs"; /* default, changed by each tool */ struct cache *libxfs_icache; /* global inode cache */ -int libxfs_icache_size; /* #buckets in icache */ +int libxfs_ihash_size; /* #buckets in icache */ struct cache *libxfs_bcache; /* global buffer cache */ -int libxfs_bcache_size; /* #buckets in bcache */ +int libxfs_bhash_size; /* #buckets in bcache */ static void manage_zones(int); /* setup global zones */ @@ -390,12 +390,12 @@ voldone: } if (needcd) chdir(curdir); - if (!libxfs_icache_size) - libxfs_icache_size = LIBXFS_IHASHSIZE(sbp); - libxfs_icache = cache_init(libxfs_icache_size,&libxfs_icache_operations); - if (!libxfs_bcache_size) - libxfs_bcache_size = LIBXFS_BHASHSIZE(sbp); - libxfs_bcache = cache_init(libxfs_bcache_size,&libxfs_bcache_operations); + if (!libxfs_ihash_size) + libxfs_ihash_size = LIBXFS_IHASHSIZE(sbp); + libxfs_icache = cache_init(libxfs_ihash_size, &libxfs_icache_operations); + if (!libxfs_bhash_size) + libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp); + libxfs_bcache = cache_init(libxfs_bhash_size, &libxfs_bcache_operations); manage_zones(0); rval = 1; done: @@ -752,3 +752,10 @@ libxfs_destroy(void) cache_destroy(libxfs_icache); cache_destroy(libxfs_bcache); } + +void +libxfs_report(void) +{ + cache_report("libxfs_icache", libxfs_icache); + cache_report("libxfs_bcache", libxfs_bcache); +} diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 0acb2a0d3..38a6c440f 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -52,6 +52,10 @@ char *o_opts[] = { "assume_xfs", #define PRE_65_BETA 1 "fs_is_pre_65_beta", +#define IHASH_SIZE 2 + "ihash", +#define BHASH_SIZE 3 + "bhash", NULL }; @@ -202,6 +206,12 @@ process_args(int argc, char **argv) PRE_65_BETA); pre_65_beta = 1; break; + case IHASH_SIZE: + libxfs_ihash_size = (int) strtol(val, 0, 0); + break; + case BHASH_SIZE: + libxfs_bhash_size = (int) strtol(val, 0, 0); + break; default: unknown('o', val); break; @@ -572,6 +582,9 @@ _("Warning: project quota information would be cleared.\n" } } + if (verbose) + libxfs_report(); + if (no_modify) { do_log( _("No modify flag set, skipping filesystem flush and exiting.\n"));