Skip to content

Commit

Permalink
ioq: Use io_uring
Browse files Browse the repository at this point in the history
Closes #65.
  • Loading branch information
tavianator committed Aug 23, 2023
1 parent 3d2858f commit 14354eb
Show file tree
Hide file tree
Showing 2 changed files with 289 additions and 43 deletions.
25 changes: 19 additions & 6 deletions src/bftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,27 +452,40 @@ 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);
SLIST_INIT(&state->to_close);

size_t dirlimit = args->nopenfd - 1;
size_t dirlimit = nopenfd - 1;
if (dirlimit > 1024) {
dirlimit = 1024;
}
Expand Down
Loading

0 comments on commit 14354eb

Please sign in to comment.