]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
Provide a mechanism for batch writeout of buffer cache nodes.
authorNathan Scott <nathans@sgi.com>
Thu, 18 May 2006 15:52:48 +0000 (15:52 +0000)
committerNathan Scott <nathans@sgi.com>
Thu, 18 May 2006 15:52:48 +0000 (15:52 +0000)
Merge of master-melb:xfs-cmds:25968a by kenmcd.

include/cache.h
libxfs/cache.c
libxfs/rdwr.c

index 85dce63a608db0c8cf5122c62ce6f083e2fbb018..3cccbd831a87f47e251637f21055354be27455f5 100644 (file)
@@ -33,12 +33,14 @@ typedef struct cache_node * (*cache_node_alloc_t)(void);
 typedef void (*cache_node_relse_t)(struct cache_node *);
 typedef unsigned int (*cache_node_hash_t)(cache_key_t, unsigned int);
 typedef int (*cache_node_compare_t)(struct cache_node *, cache_key_t);
+typedef unsigned int (*cache_bulk_relse_t)(struct cache *, struct list_head *);
 
 struct cache_operations {
        cache_node_hash_t       hash;
        cache_node_alloc_t      alloc;
        cache_node_relse_t      relse;
        cache_node_compare_t    compare;
+       cache_bulk_relse_t      bulkrelse;      /* optional */
 };
 
 struct cache {
@@ -49,6 +51,7 @@ struct cache {
        cache_node_alloc_t      alloc;          /* allocation function */
        cache_node_relse_t      relse;          /* memory free function */
        cache_node_compare_t    compare;        /* comparison routine */
+       cache_bulk_relse_t      bulkrelse;      /* bulk release routine */
        unsigned int            c_hashsize;     /* hash bucket count */
        struct cache_hash       *c_hash;        /* hash table buckets */
 };
index 93bb0e644ab258e4b557b69768f9a9cb805b7a89..587ab1a711acdff660cdaadf6e2f64939dc8a44b 100644 (file)
@@ -28,6 +28,8 @@
 
 #define CACHE_DEBUG 1
 
+static unsigned int cache_generic_bulkrelse(struct cache *, struct list_head *);
+
 struct cache *
 cache_init(
        unsigned int            hashsize,
@@ -52,6 +54,8 @@ cache_init(
        cache->alloc = cache_operations->alloc;
        cache->relse = cache_operations->relse;
        cache->compare = cache_operations->compare;
+       cache->bulkrelse = cache_operations->bulkrelse ?
+               cache_operations->bulkrelse : cache_generic_bulkrelse;
        pthread_mutex_init(&cache->c_mutex, NULL);
 
        for (i = 0; i < hashsize; i++) {
@@ -170,7 +174,6 @@ cache_shake_hash(
        struct list_head *      n;
        struct cache_node *     node;
        unsigned int            inuse = 0;
-       unsigned int            count = 0;
 
        list_head_init(&temp);
        head = &hash->ch_list;
@@ -186,8 +189,23 @@ cache_shake_hash(
                        break;
        }
        pthread_mutex_unlock(&hash->ch_mutex);
-       while (!list_empty(&temp)) {
-               node = (struct cache_node *)temp.next;
+       return cache->bulkrelse(cache, &temp);
+}
+
+/*
+ * Generic implementation of bulk release, which just iterates over
+ * the list calling the single node relse routine for each node.
+ */
+static unsigned int
+cache_generic_bulkrelse(
+       struct cache *          cache,
+       struct list_head *      list)
+{
+       struct cache_node *     node;
+       unsigned int            count = 0;
+
+       while (!list_empty(list)) {
+               node = (struct cache_node *)list->next;
                pthread_mutex_destroy(&node->cn_mutex);
                list_del_init(&node->cn_list);
                cache->relse(node);
index 501efff1b274b1249c013f9133fc9fd23b7aa9b2..0d0f9d83c371c5f6e274fd31ab75a25acb96df25 100644 (file)
@@ -447,6 +447,7 @@ struct cache_operations libxfs_bcache_operations = {
        /* .alloc */    libxfs_balloc,
        /* .relse */    libxfs_brelse,
        /* .compare */  libxfs_bcompare,
+       /* .bulkrelse */ NULL   /* TODO: lio_listio64 interface? */
 };
 
 
@@ -650,4 +651,5 @@ struct cache_operations libxfs_icache_operations = {
        /* .alloc */    libxfs_ialloc,
        /* .relse */    libxfs_irelse,
        /* .compare */  libxfs_icompare,
+       /* .bulkrelse */ NULL
 };