]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Instrumentation of new cache code.
authorMadan Valluri <mvalluri@sgi.com>
Wed, 24 May 2006 01:37:54 +0000 (01:37 +0000)
committerMadan Valluri <mvalluri@sgi.com>
Wed, 24 May 2006 01:37:54 +0000 (01:37 +0000)
Adjust cache hash bucket size from command line.
1) Added additional fields to cache struct
2) Added cache_report function prototype.

include/cache.h
include/libxfs.h
libxfs/cache.c
libxfs/init.c
repair/xfs_repair.c

index 3cccbd831a87f47e251637f21055354be27455f5..0515163cd47badd9dec6410e55e5ea1201469d22 100644 (file)
@@ -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__ */
index fc855bcac33db888f508df44a93f8739c2057aa4..b17b79f86bce6221d156ef494b164646c85ed2d5 100644 (file)
@@ -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
index 587ab1a711acdff660cdaadf6e2f64939dc8a44b..66ae9b7f8bbaafda41702974d17bcad3cdfd1525 100644 (file)
@@ -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))
+       );
+}
index acee677d07a553b98a311d0e673347687aef4c47..2dfdeeb618c0a04fd8fac1b4bdf883d3004424e3 100644 (file)
 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);
+}
index 0acb2a0d36b51ae0888752b6f4da3fdbcd1d75ac..38a6c440f607ddcbc59b98abfcdc881c8dc587fc 100644 (file)
@@ -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"));