From: Robert Read Date: Wed, 13 Jan 2010 02:25:03 +0000 (-0800) Subject: b=19557 actually make lustre_hash_for_each_empty() more efficient X-Git-Tag: 1.10.0.36~30 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=7b4d12e00699f1ec97e518e57b35b16d968d3315;p=fs%2Flustre-release.git b=19557 actually make lustre_hash_for_each_empty() more efficient a=johann i=adilger i=herring4 --- diff --git a/libcfs/include/libcfs/libcfs_hash.h b/libcfs/include/libcfs/libcfs_hash.h index 769854f..e195c24 100644 --- a/libcfs/include/libcfs/libcfs_hash.h +++ b/libcfs/include/libcfs/libcfs_hash.h @@ -407,8 +407,13 @@ cfs_hash_u64_hash(__u64 key, unsigned mask) #define cfs_hash_for_each_bucket(hs, hsb, pos) \ for (pos = 0; \ pos <= hs->hs_cur_mask && \ - ({ hsb = hs->hs_buckets[i]; 1; }); \ + (hsb = hs->hs_buckets[pos]); \ pos++) +#define cfs_hash_for_each_bucket_restart(hs, hsb, pos) \ + for (/* pos=0 done once by caller */; \ + pos <= hs->hs_cur_mask && \ + (hsb = hs->hs_buckets[pos]); \ + pos++) /* !__LIBCFS__HASH_H__ */ #endif diff --git a/libcfs/libcfs/hash.c b/libcfs/libcfs/hash.c index 56e2df5..4aca010 100644 --- a/libcfs/libcfs/hash.c +++ b/libcfs/libcfs/hash.c @@ -515,13 +515,20 @@ cfs_hash_for_each_empty(cfs_hash_t *hs, { cfs_hlist_node_t *hnode; cfs_hash_bucket_t *hsb; + cfs_hash_bucket_t **hsb_last = NULL; void *obj; - int i; + int i = 0; ENTRY; restart: cfs_hash_rlock(hs); - cfs_hash_for_each_bucket(hs, hsb, i) { + /* If the hash table has changed since we last held lh_rwlock, + * we need to start traversing the list from the start. */ + if (hs->hs_buckets != hsb_last) { + i = 0; + hsb_last = hs->hs_buckets; + } + cfs_hash_for_each_bucket_restart(hs, hsb, i) { cfs_write_lock(&hsb->hsb_rwlock); while (!cfs_hlist_empty(&hsb->hsb_head)) { hnode = hsb->hsb_head.first;