Skip to contentSkip to conversation

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

PATCH New Gao Xiang 1 participant 1 message Sep 15, 2023 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: mkfs: pop up most recently used dentries for tarerofs

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%.

---
 include/erofs/rebuild.h | 2 +-
 lib/rebuild.c           | 9 +++++++--
 lib/tar.c               | 5 +++--
 3 files changed, 11 insertions(+), 5 deletions(-)
include/erofs/rebuild.h +1 -1
index 3ac074c..e99ce74 100644
@@ -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);
 
lib/rebuild.c +7 -2
index 27a1df4..9751f0e 100644
@@ -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;
lib/tar.c +3 -2
index 0f0e7c5..9685fe5 100644
@@ -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;
Signature · 1 line
2.39.3