Minor optimisations and bug fixes
Fix bug in mt_mpmc.c, in Linux mutexes are not recursive. Add arena_trim_string() to the arena API Removing arena->path, now paths are pushed to arena->metadata Replacing fe->owner[128] with char *owner; the owner is not pushed as a string to arena->metadata and trimed with arena_trim_string() Improving cache locality in arena->metadata, the memory layout is not fe; fe->path; fe->owner. Cache aligning all arenas except HasherContext->arena to sizeof(void *). Pushing elements one by one instead of snprintf() in finalize_file() and hash_worker(). Getting the full path of current directory instead of "." Fixing bug in path formating, this allow us to remove normalize_path() from the hot loop.
This commit is contained in:
@@ -32,7 +32,11 @@ int main(int argc, char **argv) {
|
||||
buf[strcspn(buf, "\r\n")] = 0;
|
||||
|
||||
if (buf[0] == 0) {
|
||||
strcpy(folders[0], ".");
|
||||
if (!platform_get_current_directory(folders[0], sizeof(folders[0]))) {
|
||||
fprintf(stderr, "Failed to get current directory\n");
|
||||
return 1;
|
||||
}
|
||||
normalize_path(folders[0]);
|
||||
folder_count = 1;
|
||||
} else {
|
||||
folder_count = parse_paths(buf, folders, 64);
|
||||
@@ -71,7 +75,18 @@ int main(int argc, char **argv) {
|
||||
.max_nbre_blocks = 1,
|
||||
};
|
||||
|
||||
mem_arena *gp_arena = arena_create(¶ms);
|
||||
arena_params params_caligned = {
|
||||
.reserve_size = GiB(1),
|
||||
.commit_size = MiB(16),
|
||||
.align = ARENA_CACHE_ALIGN,
|
||||
.push_size = 0,
|
||||
.allow_free_list = true,
|
||||
.allow_swapback = false,
|
||||
.growth_policy = ARENA_GROWTH_NORMAL,
|
||||
.commit_policy = ARENA_COMMIT_LAZY,
|
||||
.max_nbre_blocks = 1,
|
||||
};
|
||||
mem_arena *gp_arena = arena_create(¶ms_caligned);
|
||||
|
||||
// -------------------------------
|
||||
// Detect hardware
|
||||
@@ -119,7 +134,7 @@ int main(int argc, char **argv) {
|
||||
mpmc_init(&file_queue, MiB(1));
|
||||
|
||||
// Starting hash threads
|
||||
WorkerContext workers[num_hash_threads];
|
||||
HasherContext workers[num_hash_threads];
|
||||
Thread *hash_threads =
|
||||
arena_push(&gp_arena, sizeof(Thread) * num_hash_threads, true);
|
||||
|
||||
@@ -155,8 +170,7 @@ int main(int argc, char **argv) {
|
||||
|
||||
for (uint8_t i = 0; i < num_scan_threads; i++) {
|
||||
scanners[i].num_threads = num_scan_threads;
|
||||
scanners[i].path_arena = arena_create(¶ms);
|
||||
scanners[i].meta_arena = arena_create(¶ms);
|
||||
scanners[i].meta_arena = arena_create(¶ms_caligned);
|
||||
scanners[i].dir_queue = &dir_queue;
|
||||
scanners[i].file_queue = &file_queue;
|
||||
|
||||
@@ -170,7 +184,7 @@ int main(int argc, char **argv) {
|
||||
// Initial folder push
|
||||
for (int i = 0; i < folder_count; i++) {
|
||||
size_t len = strlen(folders[i]) + 1;
|
||||
char *path = arena_push(&scanners[0].path_arena, len, false);
|
||||
char *path = arena_push(&scanners[0].meta_arena, len, false);
|
||||
memcpy(path, folders[i], len);
|
||||
mpmc_push_work(&dir_queue, path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user