* [PATCH] erofs: support metadata compression
@ 2025-07-08 12:01 Bo Liu
2025-07-10 5:18 ` Gao Xiang
0 siblings, 1 reply; 3+ messages in thread
From: Bo Liu @ 2025-07-08 12:01 UTC (permalink / raw)
To: xiang, chao; +Cc: linux-erofs, linux-kernel, Bo Liu
Filesystem metadata has a high degree of redundancy, so
should compress well in the general case.
To implement this feature, we make a special on-disk inode
which keeps all metadata as its data, and then compress the
special on-disk inode with the given algorithm.
Signed-off-by: Bo Liu <liubo03@inspur.com>
---
fs/erofs/data.c | 4 +++-
fs/erofs/erofs_fs.h | 2 +-
fs/erofs/internal.h | 7 +++++++
fs/erofs/super.c | 10 ++++++++++
4 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 6a329c329f43..34c82421af4c 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -55,7 +55,9 @@ void erofs_init_metabuf(struct erofs_buf *buf, struct super_block *sb)
buf->file = NULL;
buf->off = sbi->dif0.fsoff;
- if (erofs_is_fileio_mode(sbi)) {
+ if (erofs_is_metadata_comp_mode(sbi))
+ buf->mapping = sbi->meta_inode->i_mapping;
+ else if (erofs_is_fileio_mode(sbi)) {
buf->file = sbi->dif0.file; /* some fs like FUSE needs it */
buf->mapping = buf->file->f_mapping;
} else if (erofs_is_fscache_mode(sb))
diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h
index 767fb4acdc93..bf1ef306ca3c 100644
--- a/fs/erofs/erofs_fs.h
+++ b/fs/erofs/erofs_fs.h
@@ -82,7 +82,7 @@ struct erofs_super_block {
__u8 reserved[3];
__le32 build_time; /* seconds added to epoch for mkfs time */
__le64 rootnid_8b; /* (48BIT on) nid of root directory */
- __u8 reserved2[8];
+ __le64 meta_nid; /* meta data nid */
};
/*
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index a32c03a80c70..a2437e5eada2 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -125,6 +125,7 @@ struct erofs_sb_info {
struct erofs_sb_lz4_info lz4;
#endif /* CONFIG_EROFS_FS_ZIP */
struct inode *packed_inode;
+ struct inode *meta_inode;
struct erofs_dev_context *devs;
u64 total_blocks;
@@ -148,6 +149,7 @@ struct erofs_sb_info {
/* what we really care is nid, rather than ino.. */
erofs_nid_t root_nid;
erofs_nid_t packed_nid;
+ erofs_nid_t meta_nid;
/* used for statfs, f_files - f_favail */
u64 inos;
@@ -190,6 +192,11 @@ static inline bool erofs_is_fscache_mode(struct super_block *sb)
!erofs_is_fileio_mode(EROFS_SB(sb)) && !sb->s_bdev;
}
+static inline bool erofs_is_metadata_comp_mode(struct erofs_sb_info *sbi)
+{
+ return sbi->meta_inode;
+}
+
enum {
EROFS_ZIP_CACHE_DISABLED,
EROFS_ZIP_CACHE_READAHEAD,
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index e1e9f06e8342..9bc40083cd00 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -324,6 +324,7 @@ static int erofs_read_superblock(struct super_block *sb)
sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
+ sbi->meta_nid = le64_to_cpu(dsb->meta_nid);
/* parse on-disk compression configurations */
ret = z_erofs_parse_cfgs(sb, dsb);
@@ -691,6 +692,13 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
sbi->packed_inode = inode;
}
+ if (sbi->meta_nid) {
+ inode = erofs_iget(sb, sbi->meta_nid);
+ if (IS_ERR(inode))
+ return PTR_ERR(inode);
+ sbi->meta_inode = inode;
+ }
+
inode = erofs_iget(sb, sbi->root_nid);
if (IS_ERR(inode))
return PTR_ERR(inode);
@@ -845,6 +853,8 @@ static void erofs_drop_internal_inodes(struct erofs_sb_info *sbi)
{
iput(sbi->packed_inode);
sbi->packed_inode = NULL;
+ iput(sbi->meta_inode);
+ sbi->meta_inode = NULL;
#ifdef CONFIG_EROFS_FS_ZIP
iput(sbi->managed_cache);
sbi->managed_cache = NULL;
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] erofs: support metadata compression
2025-07-08 12:01 [PATCH] erofs: support metadata compression Bo Liu
@ 2025-07-10 5:18 ` Gao Xiang
2025-07-10 11:35 ` Bo Liu (刘波)-浪潮信息
0 siblings, 1 reply; 3+ messages in thread
From: Gao Xiang @ 2025-07-10 5:18 UTC (permalink / raw)
To: Bo Liu, xiang, chao; +Cc: linux-erofs, linux-kernel
Hi Bo,
On 2025/7/8 20:01, Bo Liu wrote:
> Filesystem metadata has a high degree of redundancy, so
> should compress well in the general case.
> To implement this feature, we make a special on-disk inode
> which keeps all metadata as its data, and then compress the
> special on-disk inode with the given algorithm.
>
> Signed-off-by: Bo Liu <liubo03@inspur.com>
I'm working on erofs-utils support for this feature, but
before that I tend to support optional metadata compression,
which means
if the bit 63 of nid is set, the inode itself metadata compressed.
if not, just uses the current way.
Because that we could enable image incremental builds so that
we don't have to rewrite the base inodes again.
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] erofs: support metadata compression
2025-07-10 5:18 ` Gao Xiang
@ 2025-07-10 11:35 ` Bo Liu (刘波)-浪潮信息
0 siblings, 0 replies; 3+ messages in thread
From: Bo Liu (刘波)-浪潮信息 @ 2025-07-10 11:35 UTC (permalink / raw)
To: hsiangkao@linux.alibaba.com, xiang@kernel.org, chao@kernel.org
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org
[-- Attachment #1: smime.p7m --]
[-- Type: application/pkcs7-mime, Size: 4811 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-10 11:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-08 12:01 [PATCH] erofs: support metadata compression Bo Liu
2025-07-10 5:18 ` Gao Xiang
2025-07-10 11:35 ` Bo Liu (刘波)-浪潮信息
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).