From 98206a6a90912f79a487d53bf90bc6255713da5a Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 29 Aug 2023 16:03:45 +0200 Subject: [PATCH 1/2] 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: https://github.com/containers/fuse-overlayfs/issues/401 Signed-off-by: Giuseppe Scrivano --- fuse-overlayfs.h | 2 ++ main.c | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fuse-overlayfs.h b/fuse-overlayfs.h index 49bace9..695446f 100644 --- a/fuse-overlayfs.h +++ b/fuse-overlayfs.h @@ -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; diff --git a/main.c b/main.c index 2a8db29..a69ea48 100644 --- a/main.c +++ b/main.c @@ -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; @@ -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 { @@ -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); } From 6931a9c088d0b110f41021e89073d6db83871a05 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 29 Aug 2023 16:07:22 +0200 Subject: [PATCH 2/2] NEWS: tag 1.13 Signed-off-by: Giuseppe Scrivano --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index 26fcf48..575336c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +* fuse-overlayfs-1.13 + +- fix a performance issue when dealing with big directories. + * fuse-overlayfs-1.12 - change license to GPL-2.0-or-later.