diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-06-09 16:34:41 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-06-13 11:06:47 -0400 |
commit | c023cceb3f50d92ed565ea3f085883f86de0f3f0 (patch) | |
tree | afa4b05301e7c339a78e65d4c7a0c3443f553a93 /src/eval.c | |
parent | 0cca5b64e1355af5d2c3d935da4e110982273703 (diff) | |
download | bfs-c023cceb3f50d92ed565ea3f085883f86de0f3f0.tar.xz |
bftw: Use an I/O queue to open directories
Parallelism is controlled by the new -j flag.
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -1505,6 +1505,19 @@ static int infer_fdlimit(const struct bfs_ctx *ctx, int limit) { return ret; } +static int infer_nproc(void) { + long nproc = sysconf(_SC_NPROCESSORS_ONLN); + + if (nproc < 0) { + nproc = 0; + } else if (nproc > 8) { + // Not much speedup after 8 threads + nproc = 8; + } + + return nproc; +} + /** * Dump the bftw() flags for -D search. */ @@ -1593,12 +1606,20 @@ int bfs_eval(const struct bfs_ctx *ctx) { int fdlimit = raise_fdlimit(ctx); fdlimit = infer_fdlimit(ctx, fdlimit); + int nthreads; + if (ctx->threads > 0) { + nthreads = ctx->threads - 1; + } else { + nthreads = infer_nproc(); + } + struct bftw_args bftw_args = { .paths = ctx->paths, .npaths = darray_length(ctx->paths), .callback = eval_callback, .ptr = &args, .nopenfd = fdlimit, + .nthreads = nthreads, .flags = ctx->flags, .strategy = ctx->strategy, .mtab = bfs_ctx_mtab(ctx), @@ -1618,6 +1639,7 @@ int bfs_eval(const struct bfs_ctx *ctx) { fprintf(stderr, "\t.callback = eval_callback,\n"); fprintf(stderr, "\t.ptr = &args,\n"); fprintf(stderr, "\t.nopenfd = %d,\n", bftw_args.nopenfd); + fprintf(stderr, "\t.nthreads = %d,\n", bftw_args.nthreads); fprintf(stderr, "\t.flags = "); dump_bftw_flags(bftw_args.flags); fprintf(stderr, ",\n\t.strategy = %s,\n", dump_bftw_strategy(bftw_args.strategy)); |