From 63a26e05622b0ced2cc685f545f493e794ccc325 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 26 Sep 2016 01:40:52 -0600 Subject: [PATCH] filehash: move to separate allocation We currently make it part of the thread structure allocation, but there's no need to do that since we have smalloc available. Signed-off-by: Jens Axboe --- filehash.c | 9 ++++++--- filehash.h | 4 +--- init.c | 6 ++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/filehash.c b/filehash.c index 61aa6da3..edeeab48 100644 --- a/filehash.c +++ b/filehash.c @@ -5,6 +5,7 @@ #include "flist.h" #include "hash.h" #include "filehash.h" +#include "smalloc.h" #include "lib/bloom.h" #define HASH_BUCKETS 512 @@ -12,7 +13,7 @@ #define BLOOM_SIZE 16*1024*1024 -unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); +static unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head); static struct flist_head *file_hash; static struct fio_mutex *hash_lock; @@ -116,6 +117,7 @@ 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; @@ -123,11 +125,12 @@ void file_hash_exit(void) 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]); diff --git a/filehash.h b/filehash.h index b037bd7f..5fecc3b1 100644 --- a/filehash.h +++ b/filehash.h @@ -3,9 +3,7 @@ #include "lib/types.h" -extern unsigned int file_hash_size; - -extern void file_hash_init(void *); +extern void file_hash_init(void); extern void file_hash_exit(void); extern struct fio_file *lookup_file_hash(const char *); extern struct fio_file *add_file_hash(struct fio_file *); diff --git a/init.c b/init.c index f7cb46d3..5151ff13 100644 --- a/init.c +++ b/init.c @@ -334,7 +334,6 @@ static int setup_thread_area(void) do { size_t size = max_jobs * sizeof(struct thread_data); - size += file_hash_size; size += sizeof(unsigned int); #ifndef CONFIG_NO_SHM @@ -366,11 +365,10 @@ static int setup_thread_area(void) #endif memset(threads, 0, max_jobs * sizeof(struct thread_data)); - hash = (void *) threads + max_jobs * sizeof(struct thread_data); - fio_debug_jobp = (void *) hash + file_hash_size; + fio_debug_jobp = (void *) threads + max_jobs * sizeof(struct thread_data); *fio_debug_jobp = -1; - file_hash_init(hash); + file_hash_init(); flow_init(); return 0; -- 2.25.1