X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filehash.c;h=edeeab4863c8ff831391f539e53492f1c78df5c7;hp=1df7db0c2f2d754fd4ae7bbc674ac408d7ea7848;hb=84e893fd54a0895b9eadd8b4c62243faf19c9305;hpb=d6aed795f2e3e403828abf60874dd2d6e8342a1b diff --git a/filehash.c b/filehash.c index 1df7db0c..edeeab48 100644 --- a/filehash.c +++ b/filehash.c @@ -3,19 +3,37 @@ #include "fio.h" #include "flist.h" -#include "crc/crc16.h" +#include "hash.h" +#include "filehash.h" +#include "smalloc.h" +#include "lib/bloom.h" #define HASH_BUCKETS 512 #define HASH_MASK (HASH_BUCKETS - 1) -unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); +#define BLOOM_SIZE 16*1024*1024 + +static unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); static struct flist_head *file_hash; static struct fio_mutex *hash_lock; +static struct bloom *file_bloom; static unsigned short hash(const char *name) { - return crc16((const unsigned char *) name, strlen(name)) & HASH_MASK; + return jhash(name, strlen(name), 0) & HASH_MASK; +} + +void fio_file_hash_lock(void) +{ + if (hash_lock) + fio_mutex_down(hash_lock); +} + +void fio_file_hash_unlock(void) +{ + if (hash_lock) + fio_mutex_up(hash_lock); } void remove_file_hash(struct fio_file *f) @@ -82,6 +100,11 @@ struct fio_file *add_file_hash(struct fio_file *f) return alias; } +bool file_bloom_exists(const char *fname, bool set) +{ + return bloom_string(file_bloom, fname, strlen(fname), set); +} + void file_hash_exit(void) { unsigned int i, has_entries = 0; @@ -94,18 +117,23 @@ void file_hash_exit(void) if (has_entries) log_err("fio: file hash not empty on exit\n"); + sfree(file_hash); file_hash = NULL; fio_mutex_remove(hash_lock); hash_lock = NULL; + bloom_free(file_bloom); + file_bloom = NULL; } -void file_hash_init(void *ptr) +void file_hash_init(void) { unsigned int i; - file_hash = ptr; + file_hash = smalloc(file_hash_size); + for (i = 0; i < HASH_BUCKETS; i++) INIT_FLIST_HEAD(&file_hash[i]); - hash_lock = fio_mutex_init(1); + hash_lock = fio_mutex_init(FIO_MUTEX_UNLOCKED); + file_bloom = bloom_new(BLOOM_SIZE); }