[PATCH] erofs-utils: mkfs: pop up most recently used dentries for tarerofs

Gao Xiang hsiangkao at linux.alibaba.com
Fri Sep 15 18:26:19 AEST 2023


Each tar header keeps the full file path.  It's useful to move most
recently used intermediate dirs to list heads.

User time of tarerofs index mode can be reduced by 19%.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 include/erofs/rebuild.h | 2 +-
 lib/rebuild.c           | 9 +++++++--
 lib/tar.c               | 5 +++--
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/include/erofs/rebuild.h b/include/erofs/rebuild.h
index 3ac074c..e99ce74 100644
--- a/include/erofs/rebuild.h
+++ b/include/erofs/rebuild.h
@@ -10,7 +10,7 @@ extern "C"
 #include "internal.h"
 
 struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
-		char *path, bool aufs, bool *whout, bool *opq);
+		char *path, bool aufs, bool *whout, bool *opq, bool to_head);
 
 int erofs_rebuild_load_tree(struct erofs_inode *root, struct erofs_sb_info *sbi);
 
diff --git a/lib/rebuild.c b/lib/rebuild.c
index 27a1df4..9751f0e 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -52,7 +52,7 @@ static struct erofs_dentry *erofs_rebuild_mkdir(struct erofs_inode *dir,
 }
 
 struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
-		char *path, bool aufs, bool *whout, bool *opq)
+		char *path, bool aufs, bool *whout, bool *opq, bool to_head)
 {
 	struct erofs_dentry *d = NULL;
 	unsigned int len = strlen(path);
@@ -100,6 +100,10 @@ struct erofs_dentry *erofs_rebuild_get_dentry(struct erofs_inode *pwd,
 			}
 
 			if (inode) {
+				if (to_head) {
+					list_del(&d->d_child);
+					list_add(&d->d_child, &pwd->i_subdirs);
+				}
 				pwd = inode;
 			} else if (!slash) {
 				d = erofs_d_alloc(pwd, s);
@@ -262,7 +266,8 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx)
 	erofs_dbg("parsing %s", path);
 	dname = path + strlen(parent->i_srcpath) + 1;
 
-	d = erofs_rebuild_get_dentry(parent, dname, false, &dumb, &dumb);
+	d = erofs_rebuild_get_dentry(parent, dname, false,
+				     &dumb, &dumb, false);
 	if (IS_ERR(d)) {
 		ret = PTR_ERR(d);
 		goto out;
diff --git a/lib/tar.c b/lib/tar.c
index 0f0e7c5..9685fe5 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -662,7 +662,7 @@ restart:
 
 	erofs_dbg("parsing %s (mode %05o)", eh.path, st.st_mode);
 
-	d = erofs_rebuild_get_dentry(root, eh.path, tar->aufs, &whout, &opq);
+	d = erofs_rebuild_get_dentry(root, eh.path, tar->aufs, &whout, &opq, true);
 	if (IS_ERR(d)) {
 		ret = PTR_ERR(d);
 		goto out;
@@ -695,7 +695,8 @@ restart:
 		}
 		d->inode = NULL;
 
-		d2 = erofs_rebuild_get_dentry(root, eh.link, tar->aufs, &dumb, &dumb);
+		d2 = erofs_rebuild_get_dentry(root, eh.link, tar->aufs,
+					      &dumb, &dumb, false);
 		if (IS_ERR(d2)) {
 			ret = PTR_ERR(d2);
 			goto out;
-- 
2.39.3



More information about the Linux-erofs mailing list