Skip to content

Commit 710c083

Browse files
committed
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.
1 parent 76ffc8d commit 710c083

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/bftw.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,6 @@ static void bftw_file_set_dir(struct bftw_cache *cache, struct bftw_file *file,
659659
file->fd = bfs_dirfd(dir);
660660
bftw_cache_add(cache, file);
661661
}
662-
663-
bftw_cache_pin(cache, file);
664662
}
665663

666664
/** Free a bftw_file. */
@@ -1318,7 +1316,7 @@ static int bftw_opendir(struct bftw_state *state) {
13181316
struct bftw_file *file = state->file;
13191317
state->dir = file->dir;
13201318
if (state->dir) {
1321-
return 0;
1319+
goto pin;
13221320
}
13231321

13241322
if (bftw_build_path(state, NULL) != 0) {
@@ -1328,8 +1326,11 @@ static int bftw_opendir(struct bftw_state *state) {
13281326
state->dir = bftw_file_opendir(state, file, state->path);
13291327
if (!state->dir) {
13301328
state->direrror = errno;
1329+
return 0;
13311330
}
13321331

1332+
pin:
1333+
bftw_cache_pin(&state->cache, file);
13331334
return 0;
13341335
}
13351336

@@ -1577,7 +1578,7 @@ static int bftw_gc(struct bftw_state *state, enum bftw_gc_flags flags) {
15771578
int ret = 0;
15781579

15791580
struct bftw_file *file = state->file;
1580-
if (file && file->dir) {
1581+
if (file && state->dir) {
15811582
bftw_unpin_dir(state, file, true);
15821583
}
15831584
state->dir = NULL;

0 commit comments

Comments
 (0)