summaryrefslogtreecommitdiffstats
path: root/src/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-10-02 13:09:41 -0400
committerTavian Barnes <tavianator@tavianator.com>2023-10-02 13:09:41 -0400
commit1c775d0128a797370bbc0bbd527b4bbbc9d0b83d (patch)
treedba15bad6c144786f462c0fed7ba727d4823b93e /src/bftw.c
parentfed31013ebfa6b0c5165f015da5b96ce524224eb (diff)
parent1afa241472709b32baf5e3e1fd3ba6ebd5fd1bf6 (diff)
downloadbfs-1c775d0128a797370bbc0bbd527b4bbbc9d0b83d.tar.xz
Merge branch 'io-uring'
Diffstat (limited to 'src/bftw.c')
-rw-r--r--src/bftw.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/bftw.c b/src/bftw.c
index 5e5f4a5..902a3fa 100644
--- a/src/bftw.c
+++ b/src/bftw.c
@@ -470,21 +470,34 @@ static int bftw_state_init(struct bftw_state *state, const struct bftw_args *arg
state->error = 0;
- if (args->nopenfd < 1) {
+ if (args->nopenfd < 2) {
errno = EMFILE;
return -1;
}
- bftw_cache_init(&state->cache, args->nopenfd);
- state->nthreads = args->nthreads;
- if (state->nthreads > 0) {
- state->ioq = ioq_create(4096, state->nthreads);
+ size_t nopenfd = args->nopenfd;
+ size_t qdepth = 4096;
+ size_t nthreads = args->nthreads;
+
+#if BFS_USE_LIBURING
+ // io_uring uses one fd per ring, ioq uses one ring per thread
+ if (nthreads >= nopenfd - 1) {
+ nthreads = nopenfd - 2;
+ }
+ nopenfd -= nthreads;
+#endif
+
+ bftw_cache_init(&state->cache, nopenfd);
+
+ if (nthreads > 0) {
+ state->ioq = ioq_create(qdepth, nthreads);
if (!state->ioq) {
return -1;
}
} else {
state->ioq = NULL;
}
+ state->nthreads = nthreads;
SLIST_INIT(&state->to_open);
SLIST_INIT(&state->to_read);