From 1c4110bd10e8ba8adfba69c15de91365965582d9 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Thu, 18 May 2006 15:52:48 +0000 Subject: [PATCH] Provide a mechanism for batch writeout of buffer cache nodes. Merge of master-melb:xfs-cmds:25968a by kenmcd. --- include/cache.h | 3 +++ libxfs/cache.c | 24 +++++++++++++++++++++--- libxfs/rdwr.c | 2 ++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/cache.h b/include/cache.h index 85dce63a6..3cccbd831 100644 --- a/include/cache.h +++ b/include/cache.h @@ -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 */ }; diff --git a/libxfs/cache.c b/libxfs/cache.c index 93bb0e644..587ab1a71 100644 --- a/libxfs/cache.c +++ b/libxfs/cache.c @@ -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); diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index 501efff1b..0d0f9d83c 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -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 }; -- 2.47.2