filehash: move to separate allocation
authorJens Axboe <axboe@fb.com>
Mon, 26 Sep 2016 07:40:52 +0000 (01:40 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 26 Sep 2016 07:40:52 +0000 (01:40 -0600)
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 <axboe@fb.com>
filehash.c
filehash.h
init.c

index 61aa6da32e570666bfe61108341222190bb61793..edeeab4863c8ff831391f539e53492f1c78df5c7 100644 (file)
@@ -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]);
 
index b037bd7f736164f6f229e6709847e4942ee48941..5fecc3b100b31db7340c1a955b33c45fa2f49299 100644 (file)
@@ -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 f7cb46d33ee7933bac51a10cad4e40212f456cec..5151ff132f2f3357285eaa80a22664e7f3b2b2ad 100644 (file)
--- 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;