Reworking IO Ring pipeline to fully support multiple infilght files

Reworking the filequeue, the buffer chaining logic and the error
handling.
Renaming functions.
Fix bug in arena.
This commit is contained in:
2026-04-23 14:13:48 +01:00
parent b8e577b5bb
commit ab31776658
7 changed files with 365 additions and 383 deletions

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@ temp_code.c
/.cache/clangd/index /.cache/clangd/index
/file_hasher /file_hasher
/io_uring_test /io_uring_test
/file_hasher

View File

@@ -437,12 +437,14 @@ void *arena_push(mem_arena **arena_ptr, u64 size, bool zero) { // mk push
Commit memory if needed Commit memory if needed
------------------------------------------------------------ */ ------------------------------------------------------------ */
if (local_post > selected->commit_pos) { if (local_post > selected->commit_pos -
u64 new_commit = ALIGN_UP_POW2(local_post, arena_pagesize()); ALIGN_UP_POW2(sizeof(mem_arena), selected->align)) {
u64 new_commit = ALIGN_UP_POW2(local_post + ALIGN_UP_POW2(sizeof(mem_arena), selected->align), arena_pagesize());
new_commit = MIN(new_commit, selected->reserve_size); new_commit = MIN(new_commit, selected->reserve_size);
if (!plat_mem_commit((u8 *)selected + selected->commit_pos, if (!plat_mem_commit((u8 *)selected + selected->commit_pos,
new_commit - selected->commit_pos)) { new_commit - selected->commit_pos)) {
printf("ERROR: Could not commit memory!\n");
return NULL; return NULL;
} }

1
base.h
View File

@@ -46,6 +46,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <limits.h>
/* ------------------------------------------------------------ /* ------------------------------------------------------------
Base types Base types

View File

@@ -50,7 +50,7 @@ Fixing user prompt parsing
Reorganising the code Reorganising the code
Improving the scan function Improving the scan function
5.0: Implementing the IO Ring for windows and ui_uring for linux instead of buffered hashing, huge performance gains. The IO Ring is event driven, thread local, uses DMA and direct disk I/O, bypassing the OS cash completely, registred buffers, it supports bashing multiple submissions and can handle multiple files at the same time. 5.0: Implementing the IO Ring for windows and ui_uring for linux instead of buffered hashing, huge performance gains. The IO Ring is event driven, thread local, uses DMA and direct disk I/O, bypassing the OS cache completely, registred buffers, it supports bashing multiple submissions and can handle multiple files at the same time.
Hashing small files using XXH3_128bits() instead of the streaming pipeline(XXH3_128bits_reset(), XXH3_128bits_update(), XXH3_128bits_digest()), this reduses the overhead of creating a state and digest, coupled with the IO Ring it improves the hashing of small files whose size is inferior to the size of IO Ring buffers Hashing small files using XXH3_128bits() instead of the streaming pipeline(XXH3_128bits_reset(), XXH3_128bits_update(), XXH3_128bits_digest()), this reduses the overhead of creating a state and digest, coupled with the IO Ring it improves the hashing of small files whose size is inferior to the size of IO Ring buffers
fixing the xxh_x86dispatch warnings fixing the xxh_x86dispatch warnings
Updating the progress printing function Updating the progress printing function

Binary file not shown.

View File

@@ -77,14 +77,19 @@ int main(int argc, char **argv) {
// Detect hardware // Detect hardware
// ------------------------------- // -------------------------------
// --- Windows: detect PHYSICAL cores (not logical threads) --- // --- Windows: detect PHYSICAL cores (not logical threads) ---
size_t hw_threads = platform_physical_cores(); uint32_t cpu_cores = platform_physical_cores();
// Logical threads = CPU cores * 2 // Logical threads = CPU cores * 2
size_t num_threads = hw_threads * 2; uint32_t cpu_threads = cpu_cores * 2;
printf("Starting thread pool: %zu threads (CPU cores: %zu)\n", num_threads, uint32_t num_scan_threads = cpu_threads;
hw_threads); uint32_t num_hash_threads = cpu_threads;
printf(" Selected instruction set: %s\n", get_xxhash_instruction_set()); // uint32_t num_hash_threads = 1;
printf("%d cores %d threads CPU detected with %s instruction set\n"
"Starting thread pool: %d scanning and %d hashing threads\n",
cpu_cores, cpu_threads, get_xxhash_instruction_set(), num_scan_threads,
num_hash_threads);
// Align IO Ring block size to the system page size // Align IO Ring block size to the system page size
g_ioring_buffer_size = ALIGN_UP_POW2(g_ioring_buffer_size, g_pagesize); g_ioring_buffer_size = ALIGN_UP_POW2(g_ioring_buffer_size, g_pagesize);
@@ -119,9 +124,6 @@ int main(int argc, char **argv) {
// } // }
// Starting hash threads // Starting hash threads
size_t num_hash_threads = num_threads;
// size_t num_hash_threads = 1;
WorkerContext workers[num_hash_threads]; WorkerContext workers[num_hash_threads];
Thread *hash_threads = Thread *hash_threads =
arena_push(&gp_arena, sizeof(Thread) * num_hash_threads, true); arena_push(&gp_arena, sizeof(Thread) * num_hash_threads, true);
@@ -130,7 +132,7 @@ int main(int argc, char **argv) {
workers[i].arena = arena_create(&params); workers[i].arena = arena_create(&params);
workers[i].file_queue = &file_queue; workers[i].file_queue = &file_queue;
if (thread_create(&hash_threads[i], (ThreadFunc)hash_worker_io_ring, if (thread_create(&hash_threads[i], (ThreadFunc)hash_worker_ioring,
&workers[i]) != 0) { &workers[i]) != 0) {
fprintf(stderr, "Failed to create hash thread %zu\n", i); fprintf(stderr, "Failed to create hash thread %zu\n", i);
exit(1); exit(1);
@@ -178,8 +180,6 @@ int main(int argc, char **argv) {
} }
// Starting scan threads // Starting scan threads
size_t num_scan_threads = num_threads;
ScannerContext scanners[num_scan_threads]; ScannerContext scanners[num_scan_threads];
Thread *scan_threads = Thread *scan_threads =
arena_push(&gp_arena, sizeof(Thread) * num_scan_threads, true); arena_push(&gp_arena, sizeof(Thread) * num_scan_threads, true);

File diff suppressed because it is too large Load Diff