Skip to content

Commit 98206a6

Browse files
committed
main: fix performance issue with large dirs
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 <gscrivan@redhat.com>
1 parent 6452d53 commit 98206a6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

fuse-overlayfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct ovl_node
5454
struct ovl_node *next_link;
5555
unsigned int in_readdir;
5656

57+
size_t n_links;
58+
5759
unsigned int do_unlink : 1;
5860
unsigned int do_rmdir : 1;
5961
unsigned int hidden : 1;

main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,9 +941,13 @@ rpl_stat (fuse_req_t req, struct ovl_node *node, int fd, const char *path, struc
941941
st->st_ino = node->tmp_ino;
942942
st->st_dev = node->tmp_dev;
943943

944-
if (node_dirp (node))
944+
if (node->loaded && node->n_links > 0)
945+
st->st_nlink = node->n_links;
946+
else if (node_dirp (node))
945947
{
946-
if (!data->static_nlink)
948+
if (data->static_nlink)
949+
st->st_nlink = 1;
950+
else
947951
{
948952
struct ovl_node *it;
949953

@@ -955,8 +959,8 @@ rpl_stat (fuse_req_t req, struct ovl_node *node, int fd, const char *path, struc
955959
st->st_nlink++;
956960
}
957961
}
958-
else
959-
st->st_nlink = 1;
962+
963+
node->n_links = st->st_nlink;
960964
}
961965
else
962966
{
@@ -5157,6 +5161,7 @@ ovl_mkdir (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode)
51575161
e.attr_timeout = get_timeout (lo);
51585162
e.entry_timeout = get_timeout (lo);
51595163
node->ino->lookups++;
5164+
pnode->n_links++;
51605165
fuse_reply_entry (req, &e);
51615166
}
51625167

0 commit comments

Comments
 (0)