From 710c083ff02eb1cc5b8daa6778784f3d1cd3c08d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 1 Feb 2024 09:46:04 -0500 Subject: bftw: Don't immediately pin open directories It is undesirable to close a directory that we haven't read yet to free up cache capacity, but it's worse to fail to open the next directory because too many upcoming directories are pinned. This could happen when sorting, because then we can't prioritize the already-opened ones. --- src/bftw.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/bftw.c') diff --git a/src/bftw.c b/src/bftw.c index b3c0ba7..e29bd27 100644 --- a/src/bftw.c +++ b/src/bftw.c @@ -659,8 +659,6 @@ static void bftw_file_set_dir(struct bftw_cache *cache, struct bftw_file *file, file->fd = bfs_dirfd(dir); bftw_cache_add(cache, file); } - - bftw_cache_pin(cache, file); } /** Free a bftw_file. */ @@ -1318,7 +1316,7 @@ static int bftw_opendir(struct bftw_state *state) { struct bftw_file *file = state->file; state->dir = file->dir; if (state->dir) { - return 0; + goto pin; } if (bftw_build_path(state, NULL) != 0) { @@ -1328,8 +1326,11 @@ static int bftw_opendir(struct bftw_state *state) { state->dir = bftw_file_opendir(state, file, state->path); if (!state->dir) { state->direrror = errno; + return 0; } +pin: + bftw_cache_pin(&state->cache, file); return 0; } @@ -1577,7 +1578,7 @@ static int bftw_gc(struct bftw_state *state, enum bftw_gc_flags flags) { int ret = 0; struct bftw_file *file = state->file; - if (file && file->dir) { + if (file && state->dir) { bftw_unpin_dir(state, file, true); } state->dir = NULL; -- cgit v1.2.3