Skip to content

Commit

Permalink
main: fix performance issue with large dirs
Browse files Browse the repository at this point in the history
cache the number of links for a directory instead of calculating it on
every stat.  It makes a huge difference when the directory has a lot
of entries.

Closes: #401

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Aug 29, 2023
1 parent 6452d53 commit 98206a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions fuse-overlayfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct ovl_node
struct ovl_node *next_link;
unsigned int in_readdir;

size_t n_links;

unsigned int do_unlink : 1;
unsigned int do_rmdir : 1;
unsigned int hidden : 1;
Expand Down
13 changes: 9 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -941,9 +941,13 @@ rpl_stat (fuse_req_t req, struct ovl_node *node, int fd, const char *path, struc
st->st_ino = node->tmp_ino;
st->st_dev = node->tmp_dev;

if (node_dirp (node))
if (node->loaded && node->n_links > 0)
st->st_nlink = node->n_links;
else if (node_dirp (node))
{
if (!data->static_nlink)
if (data->static_nlink)
st->st_nlink = 1;
else
{
struct ovl_node *it;

Expand All @@ -955,8 +959,8 @@ rpl_stat (fuse_req_t req, struct ovl_node *node, int fd, const char *path, struc
st->st_nlink++;
}
}
else
st->st_nlink = 1;

node->n_links = st->st_nlink;
}
else
{
Expand Down Expand Up @@ -5157,6 +5161,7 @@ ovl_mkdir (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode)
e.attr_timeout = get_timeout (lo);
e.entry_timeout = get_timeout (lo);
node->ino->lookups++;
pnode->n_links++;
fuse_reply_entry (req, &e);
}

Expand Down

0 comments on commit 98206a6

Please sign in to comment.