erofs-utils: mkfs: pop up most recently used dentries for tarerofs
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 15 Sep 2023 08:26:19 +0000 (16:26 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Wed, 20 Sep 2023 11:34:47 +0000 (19:34 +0800)
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@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230915082619.3533530-1-hsiangkao@linux.alibaba.com
include/erofs/rebuild.h
lib/rebuild.c
lib/tar.c

index 3ac074ce1969b615cb8576797ad4d0e36f975358..e99ce74cc23fe2ca9bf2731eec24b3aee51762d6 100644 (file)
@@ -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);
 
index 27a1df45eb94178ce9d1ad6842c92301f1e0fc8f..9751f0ef3c8df6e940bdab0e4fe390d7d1c45c9e 100644 (file)
@@ -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;
index 08a140d0a23ed5bfc2dc5c40306a7770763a92bf..f6320b0393d7071116e6fa9c27f5afca76b68b79 100644 (file)
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -671,7 +671,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;
@@ -704,7 +704,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;