Skip to content

Commit

Permalink
bftw: Don't immediately pin open directories
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tavianator committed Feb 1, 2024
1 parent 76ffc8d commit 710c083
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/bftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 710c083

Please sign in to comment.