]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Improve repair cache hit efficiency reporting.
authorMadan Valluri <mvalluri@sgi.com>
Tue, 6 Jun 2006 00:53:42 +0000 (00:53 +0000)
committerMadan Valluri <mvalluri@sgi.com>
Tue, 6 Jun 2006 00:53:42 +0000 (00:53 +0000)
1) added ch_count field to struct cache_hash.
2) Added FILE *fp, to cache_report proto.

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

index 0515163cd47badd9dec6410e55e5ea1201469d22..63eb273242b4db5a9a3e006ad4898148f1688044 100644 (file)
@@ -61,6 +61,7 @@ struct cache {
 
 struct cache_hash {
        struct list_head        ch_list;        /* hash chain head */
+       unsigned int            ch_count;       /* hash chain length */
        pthread_mutex_t         ch_mutex;       /* hash chain mutex */
 };
 
@@ -78,6 +79,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 *);
+void cache_report(FILE *fp, const char *, struct cache *);
 
 #endif /* __CACHE_H__ */
index b17b79f86bce6221d156ef494b164646c85ed2d5..4dbe3ae493d4ec6a06276c7b7f7eb54f98ae2c8c 100644 (file)
@@ -106,7 +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);
+extern void    libxfs_report(FILE *);
 
 /* 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 *);
index 66ae9b7f8bbaafda41702974d17bcad3cdfd1525..72d8d50f91b260b32b05e087ad64919a8454d4b2 100644 (file)
@@ -27,6 +27,7 @@
 #include <xfs/cache.h>
 
 #define CACHE_DEBUG 1
+#define        HASH_CACHE_RATIO        8
 
 static unsigned int cache_generic_bulkrelse(struct cache *, struct list_head *);
 
@@ -38,7 +39,7 @@ cache_init(
        struct cache *          cache;
        unsigned int            i, maxcount;
 
-       maxcount = hashsize << 3;       /* 8 nodes per hash bucket */
+       maxcount = hashsize * HASH_CACHE_RATIO;
 
        if (!(cache = malloc(sizeof(struct cache))))
                return NULL;
@@ -63,6 +64,7 @@ cache_init(
 
        for (i = 0; i < hashsize; i++) {
                list_head_init(&cache->c_hash[i].ch_list);
+               cache->c_hash[i].ch_count = 0;
                pthread_mutex_init(&cache->c_hash[i].ch_mutex, NULL);
        }
        return cache;
@@ -147,6 +149,7 @@ cache_shake_node(
                        break;
                pthread_mutex_destroy(&node->cn_mutex);
                list_del_init(&node->cn_list);
+               hash->ch_count--;
                cache->relse(node);
                break;
        }
@@ -185,8 +188,10 @@ cache_shake_hash(
             pos = n, n = pos->prev) {
                node = (struct cache_node *)pos;
                pthread_mutex_lock(&node->cn_mutex);
-               if (!(inuse = (node->cn_count > 0)))
+               if (!(inuse = (node->cn_count > 0))) {
+                       hash->ch_count--;
                        list_move(&node->cn_list, &temp);
+               }
                pthread_mutex_unlock(&node->cn_mutex);
                if (inuse && !priority)
                        break;
@@ -331,6 +336,7 @@ cache_node_get(
                        goto restart;
                }
                allocated = 1;
+               hash->ch_count++;       /* new entry */
        }
        /* looked at it, move to hash list head */
        list_move(&node->cn_list, &hash->ch_list);
@@ -408,10 +414,19 @@ cache_purge(
 #endif
 }
 
+#define        HASH_REPORT     (3*HASH_CACHE_RATIO)
 void
-cache_report(const char *name, struct cache * cache)
+cache_report(FILE *fp, const char *name, struct cache * cache)
 {
-       fprintf(stderr, "%s: %p\n"
+       int i;
+       unsigned long count, index, total;
+       unsigned long hash_bucket_lengths[HASH_REPORT+2];
+
+       if ((cache->c_hits+cache->c_misses) == 0)
+               return;
+
+       /* report cache summary */
+       fprintf(fp, "%s: %p\n"
                        "Max supported entries = %u\n"
                        "Max utilized entries = %u\n"
                        "Active entries = %u\n"
@@ -428,4 +443,28 @@ cache_report(const char *name, struct cache * cache)
                        cache->c_misses,
                        (double) (cache->c_hits*100/(cache->c_hits+cache->c_misses))
        );
+
+       /* report hash bucket lengths */
+       bzero(hash_bucket_lengths, sizeof(hash_bucket_lengths));
+
+       for (i = 0; i < cache->c_hashsize; i++) {
+               count = cache->c_hash[i].ch_count;
+               if (count > HASH_REPORT)
+                       index = HASH_REPORT + 1;
+               else
+                       index = count;
+               hash_bucket_lengths[index]++;
+       }
+
+       total = 0;
+       for (i = 0; i < HASH_REPORT+1; i++) {
+               total += i*hash_bucket_lengths[i];
+               if (hash_bucket_lengths[i] == 0)
+                       continue;
+               fprintf(fp, "Hash buckets with  %2d entries %5ld (%3ld%%)\n", 
+                       i, hash_bucket_lengths[i], (i*hash_bucket_lengths[i]*100)/cache->c_count);
+       }
+       if (hash_bucket_lengths[i])     /* last report bucket is the overflow bucket */
+               fprintf(fp, "Hash buckets with >%2d entries %5ld (%3ld%%)\n", 
+                       i-1, hash_bucket_lengths[i], ((cache->c_count-total)*100)/cache->c_count);
 }
index 2dfdeeb618c0a04fd8fac1b4bdf883d3004424e3..1e6e9bf46f5e4907ce8bbf394847ca6514f2fb2e 100644 (file)
@@ -754,8 +754,8 @@ libxfs_destroy(void)
 }
 
 void
-libxfs_report(void)
+libxfs_report(FILE *fp)
 {
-       cache_report("libxfs_icache", libxfs_icache);
-       cache_report("libxfs_bcache", libxfs_bcache);
+       cache_report(fp, "libxfs_icache", libxfs_icache);
+       cache_report(fp, "libxfs_bcache", libxfs_bcache);
 }