projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'evelu-fix-engines' of https://github.com/ErwanAliasr1/fio
[fio.git]
/
filehash.c
diff --git
a/filehash.c
b/filehash.c
index 54cea990f927c158c3987bca29904e9e2bc47b98..71ec7b18c3345cfabdd2a7f48c0ce20c1c2579d3 100644
(file)
--- a/
filehash.c
+++ b/
filehash.c
@@
-2,47
+2,66
@@
#include <assert.h>
#include "fio.h"
#include <assert.h>
#include "fio.h"
-#include "list.h"
-#include "crc/crc16.h"
+#include "flist.h"
+#include "hash.h"
+#include "filehash.h"
+#include "smalloc.h"
+#include "lib/bloom.h"
#define HASH_BUCKETS 512
#define HASH_MASK (HASH_BUCKETS - 1)
#define HASH_BUCKETS 512
#define HASH_MASK (HASH_BUCKETS - 1)
-unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct list_head);
+#define BLOOM_SIZE 16*1024*1024
-static struct list_head *file_hash;
-static struct fio_mutex *hash_lock;
+static unsigned int file_hash_size = HASH_BUCKETS * sizeof(struct flist_head);
+
+static struct flist_head *file_hash;
+static struct fio_sem *hash_lock;
+static struct bloom *file_bloom;
static unsigned short hash(const char *name)
{
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_sem_down(hash_lock);
+}
+
+void fio_file_hash_unlock(void)
+{
+ if (hash_lock)
+ fio_sem_up(hash_lock);
}
void remove_file_hash(struct fio_file *f)
{
}
void remove_file_hash(struct fio_file *f)
{
- fio_
mutex
_down(hash_lock);
+ fio_
sem
_down(hash_lock);
- if (f
->flags & FIO_FILE_HASHED
) {
- assert(!list_empty(&f->hash_list));
- list_del_init(&f->hash_list);
- f
->flags &= ~FIO_FILE_HASHED
;
+ if (f
io_file_hashed(f)
) {
+ assert(!
f
list_empty(&f->hash_list));
+
f
list_del_init(&f->hash_list);
+ f
io_file_clear_hashed(f)
;
}
}
- fio_
mutex
_up(hash_lock);
+ fio_
sem
_up(hash_lock);
}
static struct fio_file *__lookup_file_hash(const char *name)
{
}
static struct fio_file *__lookup_file_hash(const char *name)
{
- struct list_head *bucket = &file_hash[hash(name)];
- struct list_head *n;
+ struct flist_head *bucket = &file_hash[hash(name)];
+ struct flist_head *n;
+
+ flist_for_each(n, bucket) {
+ struct fio_file *f = flist_entry(n, struct fio_file, hash_list);
- list_for_each(n, bucket) {
-
struct fio_file *f = list_entry(n, struct fio_file, hash_list)
;
+ if (!f->file_name)
+
continue
;
- if (!strcmp(f->file_name, name)) {
- assert(f->fd != -1);
+ if (!strcmp(f->file_name, name))
return f;
return f;
- }
}
return NULL;
}
return NULL;
@@
-52,9
+71,9
@@
struct fio_file *lookup_file_hash(const char *name)
{
struct fio_file *f;
{
struct fio_file *f;
- fio_
mutex
_down(hash_lock);
+ fio_
sem
_down(hash_lock);
f = __lookup_file_hash(name);
f = __lookup_file_hash(name);
- fio_
mutex
_up(hash_lock);
+ fio_
sem
_up(hash_lock);
return f;
}
return f;
}
@@
-62,47
+81,57
@@
struct fio_file *add_file_hash(struct fio_file *f)
{
struct fio_file *alias;
{
struct fio_file *alias;
- if (f
->flags & FIO_FILE_HASHED
)
+ if (f
io_file_hashed(f)
)
return NULL;
return NULL;
- INIT_LIST_HEAD(&f->hash_list);
+ INIT_
F
LIST_HEAD(&f->hash_list);
- fio_
mutex
_down(hash_lock);
+ fio_
sem
_down(hash_lock);
alias = __lookup_file_hash(f->file_name);
if (!alias) {
alias = __lookup_file_hash(f->file_name);
if (!alias) {
- f
->flags |= FIO_FILE_HASHED
;
- list_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
+ f
io_file_set_hashed(f)
;
+
f
list_add_tail(&f->hash_list, &file_hash[hash(f->file_name)]);
}
}
- fio_
mutex
_up(hash_lock);
+ fio_
sem
_up(hash_lock);
return alias;
}
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;
void file_hash_exit(void)
{
unsigned int i, has_entries = 0;
- fio_
mutex
_down(hash_lock);
+ fio_
sem
_down(hash_lock);
for (i = 0; i < HASH_BUCKETS; i++)
for (i = 0; i < HASH_BUCKETS; i++)
- has_entries += !list_empty(&file_hash[i]);
- fio_
mutex
_up(hash_lock);
+ has_entries += !
f
list_empty(&file_hash[i]);
+ fio_
sem
_up(hash_lock);
if (has_entries)
log_err("fio: file hash not empty on exit\n");
if (has_entries)
log_err("fio: file hash not empty on exit\n");
+ sfree(file_hash);
file_hash = NULL;
file_hash = NULL;
- fio_
mutex
_remove(hash_lock);
+ fio_
sem
_remove(hash_lock);
hash_lock = NULL;
hash_lock = NULL;
+ bloom_free(file_bloom);
+ file_bloom = NULL;
}
}
-void file_hash_init(void
*ptr
)
+void file_hash_init(void)
{
unsigned int i;
{
unsigned int i;
- file_hash = ptr;
+ file_hash = smalloc(file_hash_size);
+
for (i = 0; i < HASH_BUCKETS; i++)
for (i = 0; i < HASH_BUCKETS; i++)
- INIT_LIST_HEAD(&file_hash[i]);
+ INIT_
F
LIST_HEAD(&file_hash[i]);
- hash_lock = fio_mutex_init(1);
+ hash_lock = fio_sem_init(FIO_SEM_UNLOCKED);
+ file_bloom = bloom_new(BLOOM_SIZE);
}
}