diff --git a/TODO b/TODO index a80faa6d..592fee0a 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,8 @@ This is the list of TODO items for SnapRAID. - Next +* Use a memory mapped file to read the content file + * Integration with MergeFS ? * Evaluate use of syscall getdents64() instead of readdir(): https://linux.die.net/man/2/getdents64 diff --git a/cmdline/elem.c b/cmdline/elem.c index 8ae5418d..bd92de0a 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -765,6 +765,7 @@ struct snapraid_disk* disk_alloc(const char* name, const char* dir, uint64_t dev pathslash(disk->dir, sizeof(disk->dir)); #if HAVE_THREAD + disk->single_thread = 0; thread_mutex_init(&disk->fs_mutex); #endif @@ -856,7 +857,8 @@ void extra_free(struct snapraid_extra* extra) static inline void fs_lock(struct snapraid_disk* disk) { #if HAVE_THREAD - thread_mutex_lock(&disk->fs_mutex); + if (!disk->single_thread) + thread_mutex_lock(&disk->fs_mutex); #else (void)disk; #endif @@ -865,7 +867,8 @@ static inline void fs_lock(struct snapraid_disk* disk) static inline void fs_unlock(struct snapraid_disk* disk) { #if HAVE_THREAD - thread_mutex_unlock(&disk->fs_mutex); + if (!disk->single_thread) + thread_mutex_unlock(&disk->fs_mutex); #else (void)disk; #endif diff --git a/cmdline/elem.h b/cmdline/elem.h index 1152df5b..18d8e213 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -388,6 +388,8 @@ struct snapraid_disk { int skip_access; /**< If the disk is inaccessible and it should be skipped. */ #if HAVE_THREAD + int single_thread; /**< Running in single thread, and then not needing the mutex */ + /** * Mutex for protecting the filesystem structure. * diff --git a/cmdline/state.c b/cmdline/state.c index abb5fc0c..a6ed0887 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2133,6 +2133,12 @@ static void state_read_content(struct snapraid_state* state, const char* path, S tommy_array_init(&disk_mapping); tommy_hashdyn_init(&bucket_hash); + /* mark all disks as single threads */ + for (tommy_node* i = state->disklist; i != 0; i = i->next) { + struct snapraid_disk* disk = i->data; + disk->single_thread = 1; + } + ret = sread(f, buffer, 12); if (ret < 0) { /* LCOV_EXCL_START */ @@ -3231,6 +3237,12 @@ static void state_read_content(struct snapraid_state* state, const char* path, S } } + /* mark all disks as multi threads */ + for (tommy_node* i = state->disklist; i != 0; i = i->next) { + struct snapraid_disk* disk = i->data; + disk->single_thread = 0; + } + tommy_array_done(&disk_mapping); if (serror(f)) {