Speed up reading of content file disabling mutexes
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-03-11 15:50:49 +01:00
parent 34ee2bf2a6
commit b8b1d38781
4 changed files with 21 additions and 2 deletions

2
TODO
View file

@ -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

View file

@ -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

View file

@ -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.
*

View file

@ -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)) {