erofs: Introduce page cache sharing feature
Subsystems (5)
v11 cover erofs: Introduce page cache sharing feature
Enabling page cahe sharing in container scenarios has become increasingly crucial, as it can significantly reduce memory usage. In previous efforts, Hongzhen has done substantial work to push this feature into the EROFS mainline. Due to other commitments, he hasn't been able to continue his work recently, and I'm very pleased to build upon his work and continue to refine this implementation.
This patch series is based on Hongzhen's original EROFS shared pagecache implementation which was posted about half a year ago:
https://lore.kernel.org/all/[email protected]/T/#u
In addition to the forward-port, I have also fixed several bugs, resolved some prerequisite dependencies and performed some minor cleanup.
(A recap of Hongzhen's original cover letter is below, edited slightly for this serise:)
Background
==============
Currently, reading files with different paths (or names) but the same content can consume multiple copies of the page cache, even if the content of these caches is identical. For example, reading identical files (e.g., *.so files) from two different minor versions of container images can result in multiple copies of the same page cache, since different containers have different mount points. Therefore, sharing the page cache for files with the same content can save memory.
Proposal
==============
1. determining file identity
----------------------------
First, a way needs to be found to check whether the content of two files is the same. Here, the xattr values associated with the file fingerprints are assessed for consistency. When creating the EROFS image, users can specify the name of the xattr for file fingerprints, and the corresponding name will be stored in the packfile. The on-disk ishare_key_start indicates the index of the xattr name within the prefix xattrs:
```
struct erofs_super_block {
__u8 xattr_filter_reserved; /* reserved for xattr name filter */
- __u8 reserved[3];
+ __u8 ishare_xattr_prefix_id; /* indexes the ishare key in prefix xattres */
+ __u8 reserved[2];
};
```For example, users can specify the first long prefix as the name for the file fingerprint as follows:
``` mkfs.erofs --ishare_key=trusted.erofs.fingerprint erofs.img ./dir ```
In this way, trusted.erofs.fingerprint serves as the name of the xattr for the file fingerprint. The relevant patch for erofs-utils has been posted in:
v2: https://lore.kernel.org/all/[email protected]/
At the same time, we introduce a new mount option which is inode_share to enable the feature. For security reasons, we allow sharing page cache only within the same domain by adding "-o domain_id=xxxx" during the mounting process:
``` mount -t erofs -o inode_share,domain_id=trusted.erofs.fingerprint erofs.img /mnt ```
If no domain ID is specified, it will share page cache in default none domain.
2. Implementation
==================
2.1. file open & close
----------------------
When the file is opened, the ->private_data field of file A or file B is set to point to an internal deduplicated file. When the actual read occurs, the page cache of this deduplicated file will be accessed.
When the file is opened, if the corresponding erofs inode is newly created, then perform the following actions:
1. add the erofs inode to the backing list of the deduplicated inode;
2. increase the reference count of the deduplicated inode.
The purpose of step 1 above is to ensure that when a real I/O operation occurs, the deduplicated inode can locate one of the disk devices (as the deduplicated inode itself is not bound to a specific device). Step 2 is for managing the lifecycle of the deduplicated inode.
When the erofs inode is destroyed, the opposite actions mentioned above will be taken.
2.2. file reading
-----------------
Assuming the deduplication inode's page cache is PGCache_dedup, there are two possible scenarios when reading a file:
1) the content being read is already present in PGCache_dedup;
2) the content being read is not present in PGCache_dedup.
In the second scenario, it involves the iomap operation to read from the disk.
2.2.1. reading existing data in PGCache_dedup
-------------------------------------------
In this case, the overall read flowchart is as follows (take ksys_read() for example):
ksys_read
│
│
▼
...
│
│
▼
erofs_ishare_file_read_iter (switch to backing deduplicated file)
│
│▼
read PGCache_dedup & return
At this point, the content in PGCache_dedup will be read directly and returned.
2.2.2 reading non-existent content in PGCache_dedup
---------------------------------------------------
In this case, disk I/O operations will be involved. Taking the reading of an uncompressed file as an example, here is the reading process:
ksys_read
│
│
▼
...
│
│
▼
erofs_ishare_file_read_iter (switch to backing deduplicated file)
│
│ ▼
... (allocate pages)
│
│
▼
erofs_read_folio/erofs_readahead
│
│
▼
... (iomap)
│
│
▼
erofs_iomap_begin
│
│
▼
...Iomap and the layers below will involve disk I/O operations. As described in 2.1, the deduplicated inode itself is not bound to a specific device. The deduplicated inode will select an erofs inode from the backing list (by default, the first one) to complete the corresponding iomap operation.
2.3. release page cache
-----------------------
Similar to overlayfs, when dropping the page cache via .fadvise, erofs locates the deduplicated file and applies vfs_fadvise to that specific file.
Effect
==================
I conducted experiments on two aspects across two different minor versions of container images:
1. reading all files in two different minor versions of container images
2. run workloads or use the default entrypoint within the containers^[1]
Below is the memory usage for reading all files in two different minor versions of container images:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 241 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 163 | 33% | +-------------------+------------------+-------------+---------------+ | | No | 872 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 630 | 28% | +-------------------+------------------+-------------+---------------+ | | No | 2771 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 2340 | 16% | +-------------------+------------------+-------------+---------------+ | | No | 926 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 735 | 21% | +-------------------+------------------+-------------+---------------+ | | No | 390 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 219 | 44% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 924 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 474 | 49% | +-------------------+------------------+-------------+---------------+
Additionally, the table below shows the runtime memory usage of the container:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 34.9 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 33.6 | 4% | +-------------------+------------------+-------------+---------------+ | | No | 149.1 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 95 | 37% | +-------------------+------------------+-------------+---------------+ | | No | 1027.9 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 934.3 | 10% | +-------------------+------------------+-------------+---------------+ | | No | 155.0 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 139.1 | 11% | +-------------------+------------------+-------------+---------------+ | | No | 25.4 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 18.8 | 26% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 186 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 99 | 47% | +-------------------+------------------+-------------+---------------+
It can be observed that when reading all the files in the image, the reduced memory usage varies from 16% to 49%, depending on the specific image. Additionally, the container's runtime memory usage reduction ranges from 4% to 47%.
[1] Below are the workload for these images:
- redis: redis-benchmark
- postgres: sysbench
- tensorflow: app.py of tensorflow.python.platform
- mysql: sysbench
- nginx: wrk
- tomcat: default entrypoint
Changes from v10:
- add reviewed-by and acked-by.
- do some cleanup on typo, useless code and some helpers' name.
- use fingerprint struct and introduce inode_share mount option as suggested by Xiang.
Changes from v9:
- make shared page cache as a compatiable feature.
- refine code style as suggested by Xiang.
- init ishare mnt during the module init as suggested by Xiang.
- rebase the latest mainline and fix the comments in cover letter.
Changes from v8:
- add review-by in patch 1 and patch 10.
- do some clean up in patch 2 and patch 4,6,9 as suggested by Xiang.
- add new patch 3 to export alloc_empty_backing_file.
- patch 5 only use xattr prefix id to record the ishare info, changed config to EROFS_FS_PAGE_CACHE_SHARE and make it compatible.
- patch 7 use backing file helpers to alloc file when ishare file is opened as suggested by Xiang.
- patch 8 remove erofs_read_{begin,end} as suggested by Xiang.
v10: https://lore.kernel.org/all/[email protected]/
v9: https://lore.kernel.org/all/[email protected]/
v8: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
v6: https://lore.kernel.org/all/[email protected]/T/#u
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
Diffstat:
Documentation/filesystems/erofs.rst | 4 + fs/erofs/Kconfig | 9 ++ fs/erofs/Makefile | 1 + fs/erofs/data.c | 91 ++++++++---- fs/erofs/erofs_fs.h | 5 +- fs/erofs/fscache.c | 13 -- fs/erofs/inode.c | 4 + fs/erofs/internal.h | 37 +++++ fs/erofs/ishare.c | 210 ++++++++++++++++++++++++++++ fs/erofs/super.c | 70 +++++++++- fs/erofs/xattr.c | 53 ++++++- fs/erofs/xattr.h | 12 +- fs/erofs/zdata.c | 30 ++-- fs/file_table.c | 1 + fs/fuse/file.c | 4 +- fs/iomap/buffered-io.c | 6 +- include/linux/iomap.h | 8 +- 17 files changed, 492 insertions(+), 66 deletions(-) create mode 100644 fs/erofs/ishare.c
Signature · 1 line
2.22.0
PATCH v11 1/10 iomap: stash iomap read ctx in the private field of iomap_iter
It's useful to get filesystem-specific information using the existing private field in the @iomap_iter passed to iomap_{begin,end} for advanced usage for iomap buffered reads, which is much like the current iomap DIO.
For example, EROFS needs it to:
- implement an efficient page cache sharing feature, since iomap needs to apply to anon inode page cache but we'd like to get the backing inode/fs instead, so filesystem-specific private data is needed to keep such information;
- pass in both struct page * and void * for inline data to avoid kmap_to_page() usage (which is bogus).
--- fs/fuse/file.c | 4 ++-- fs/iomap/buffered-io.c | 6 ++++-- include/linux/iomap.h | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-)
fs/fuse/file.c +2 -2
@@ -979,7 +979,7 @@ static int fuse_read_folio(struct file *file, struct folio *folio)return -EIO ; } -iomap_read_folio (&fuse_iomap_ops, &ctx); +iomap_read_folio (&fuse_iomap_ops, &ctx,NULL );fuse_invalidate_atime (inode);return 0 ; }
@@ -1081,7 +1081,7 @@ static void fuse_readahead(struct readahead_control *rac)if (fuse_is_bad (inode))return ; -iomap_readahead (&fuse_iomap_ops, &ctx); +iomap_readahead (&fuse_iomap_ops, &ctx,NULL ); }static ssize_t fuse_cache_read_iter (struct kiocb *iocb,struct iov_iter *to)
fs/iomap/buffered-io.c +4 -2
@@ -555,13 +555,14 @@ static int iomap_read_folio_iter(struct iomap_iter *iter, }void iomap_read_folio (const struct iomap_ops *ops, -struct iomap_read_folio_ctx *ctx) +struct iomap_read_folio_ctx *ctx,void *private) {struct folio *folio = ctx->cur_folio;struct iomap_iter iter = { .inode = folio->mapping->host, .pos =folio_pos (folio), .len =folio_size (folio), + .private = private, };size_t bytes_submitted =0 ;int ret;
@@ -620,13 +621,14 @@ static int iomap_readahead_iter(struct iomap_iter *iter,* the filesystem to be reentered. */ void iomap_readahead (const struct iomap_ops *ops, -struct iomap_read_folio_ctx *ctx) +struct iomap_read_folio_ctx *ctx,void *private) {struct readahead_control *rac = ctx->rac;struct iomap_iter iter = { .inode = rac->mapping->host, .pos =readahead_pos (rac), .len =readahead_length (rac), + .private = private, };size_t cur_bytes_submitted;
include/linux/iomap.h +4 -4
@@ -341,9 +341,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,const struct iomap_ops *ops, const struct iomap_write_ops *write_ops, void *private);void iomap_read_folio (const struct iomap_ops *ops, -struct iomap_read_folio_ctx *ctx); +struct iomap_read_folio_ctx *ctx,void *private);void iomap_readahead (const struct iomap_ops *ops, -struct iomap_read_folio_ctx *ctx); +struct iomap_read_folio_ctx *ctx,void *private);bool iomap_is_partially_uptodate (struct folio *,size_t from,size_t count);struct folio *iomap_get_folio (struct iomap_iter *iter,loff_t pos,size_t len);bool iomap_release_folio (struct folio *folio,gfp_t gfp_flags);
@@ -595,7 +595,7 @@ static inline void iomap_bio_read_folio(struct folio *folio, .cur_folio = folio, }; -iomap_read_folio (ops, &ctx); +iomap_read_folio (ops, &ctx,NULL ); } static inline void iomap_bio_readahead(struct readahead_control *rac,
@@ -606,7 +606,7 @@ static inline void iomap_bio_readahead(struct readahead_control *rac, .rac = rac, }; -iomap_readahead (ops, &ctx); +iomap_readahead (ops, &ctx,NULL ); }#endif /* CONFIG_BLOCK */
Signature · 1 line
2.22.0
PATCH v11 2/10 erofs: hold read context in iomap_iter if needed
In reply to Hongbo LiIntroduce struct erofs_iomap_iter_ctx to hold both struct page * and void *base, avoiding bogus use of kmap_to_page() in erofs_iomap_end().
With this change, fiemap and bmap no longer need to read inline data.
Additionally, the upcoming page cache sharing mechanism requires passing the backing inode pointer to erofs_iomap_{begin,end}(), as I/O accesses must apply to backing inodes rather than anon inodes.
--- fs/erofs/data.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 21 deletions(-)
fs/erofs/data.c +46 -21
@@ -266,13 +266,20 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)folio_end_read (folio, !(v &BIT (EROFS_ONLINEFOLIO_EIO ))); } +struct erofs_iomap_iter_ctx { +struct page *page; +void *base; +}; +static int erofs_iomap_begin (struct inode *inode,loff_t offset,loff_t length,unsigned int flags,struct iomap *iomap,struct iomap *srcmap) { -int ret; + struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap); +struct erofs_iomap_iter_ctx *ctx = iter->private;struct super_block *sb = inode->i_sb;struct erofs_map_blocks map;struct erofs_map_dev mdev; +int ret; map.m_la = offset; map.m_llen = length;
@@ -283,7 +290,6 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, iomap->offset = map.m_la; iomap->length = map.m_llen; iomap->flags =0 ; - iomap->private =NULL ; iomap->addr =IOMAP_NULL_ADDR ;if (!(map.m_flags &EROFS_MAP_MAPPED )) { iomap->type =IOMAP_HOLE ;
@@ -309,16 +315,20 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, }if (map.m_flags &EROFS_MAP_META ) { -void *ptr; -struct erofs_buf buf = __EROFS_BUF_INITIALIZER; - iomap->type =IOMAP_INLINE ; - ptr =erofs_read_metabuf (&buf, sb, map.m_pa, -erofs_inode_in_metabox (inode)); -if (IS_ERR (ptr)) -return PTR_ERR (ptr); - iomap->inline_data = ptr; - iomap->private = buf.base; +/* read context should read the inlined data */ +if (ctx) { +struct erofs_buf buf = __EROFS_BUF_INITIALIZER; +void *ptr; + + ptr =erofs_read_metabuf (&buf, sb, map.m_pa, +erofs_inode_in_metabox (inode)); +if (IS_ERR (ptr)) +return PTR_ERR (ptr); + iomap->inline_data = ptr; + ctx->page = buf.page; + ctx->base = buf.base; + } }else { iomap->type =IOMAP_MAPPED ; }
@@ -328,18 +338,18 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,static int erofs_iomap_end (struct inode *inode,loff_t pos,loff_t length,ssize_t written,unsigned int flags,struct iomap *iomap) { -void *ptr = iomap->private; + struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap); +struct erofs_iomap_iter_ctx *ctx = iter->private; -if (ptr) { +if (ctx && ctx->base) {struct erofs_buf buf = { - .page =kmap_to_page (ptr), - .base = ptr, + .page = ctx->page, + .base = ctx->base, };DBG_BUGON (iomap->type !=IOMAP_INLINE );erofs_put_metabuf (&buf); - }else { -DBG_BUGON (iomap->type ==IOMAP_INLINE ); + ctx->base =NULL ; }return written; }
@@ -369,18 +379,30 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,*/ static int erofs_read_folio (struct file *file,struct folio *folio) { +struct iomap_read_folio_ctx read_ctx = { + .ops = &iomap_bio_read_ops, + .cur_folio = folio, + }; +struct erofs_iomap_iter_ctx iter_ctx = {}; +trace_erofs_read_folio (folio, true); -iomap_bio_read_folio (folio, &erofs_iomap_ops); +iomap_read_folio (&erofs_iomap_ops, &read_ctx, &iter_ctx);return 0 ; }static void erofs_readahead (struct readahead_control *rac) { +struct iomap_read_folio_ctx read_ctx = { + .ops = &iomap_bio_read_ops, + .rac = rac, + }; +struct erofs_iomap_iter_ctx iter_ctx = {}; +trace_erofs_readahead (rac->mapping->host,readahead_index (rac),readahead_count (rac), true); -iomap_bio_readahead (rac, &erofs_iomap_ops); +iomap_readahead (&erofs_iomap_ops, &read_ctx, &iter_ctx); }static sector_t erofs_bmap (struct address_space *mapping,sector_t block)
@@ -400,9 +422,12 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)if (IS_DAX (inode))return dax_iomap_rw (iocb, to, &erofs_iomap_ops);#endif -if ((iocb->ki_flags &IOCB_DIRECT ) && inode->i_sb->s_bdev) +if ((iocb->ki_flags &IOCB_DIRECT ) && inode->i_sb->s_bdev) { +struct erofs_iomap_iter_ctx iter_ctx = {}; +return iomap_dio_rw (iocb, to, &erofs_iomap_ops, -NULL ,0 ,NULL ,0 ); +NULL ,0 , &iter_ctx,0 ); + }return filemap_read (iocb, to,0 ); }
Signature · 1 line
2.22.0
PATCH v11 3/10 fs: Export alloc_empty_backing_file
In reply to Hongbo LiThere is no need to open nonexistent real files if backing files couldn't be backed by real files (e.g., EROFS page cache sharing doesn't need typical real files to open again).
Therefore, we export the alloc_empty_backing_file() helper, allowing filesystems to dynamically set the backing file without real file open. This is particularly useful for obtaining the correct @path and @inode when calling file_user_path() and file_user_inode().
--- fs/file_table.c | 1 + 1 file changed, 1 insertion(+)
fs/file_table.c +1 -0
@@ -308,6 +308,7 @@ struct file *alloc_empty_backing_file(int flags, const struct cred *cred) ff->file.f_mode |=FMODE_BACKING |FMODE_NOACCOUNT ;return &ff->file; } +EXPORT_SYMBOL_GPL (alloc_empty_backing_file);/** * file_init_path - initialize a 'struct file' based on path
Signature · 1 line
2.22.0
PATCH v11 4/10 erofs: move `struct erofs_anon_fs_type` to super.c
In reply to Hongbo LiFrom: Gao Xiang <[email protected]>
Move the struct erofs_anon_fs_type to the super.c and expose it in preparation for the upcoming page cache share feature.
--- fs/erofs/fscache.c | 13 ------------- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-)
fs/erofs/fscache.c +0 -13
@@ -3,7 +3,6 @@* Copyright (C) 2022, Alibaba Cloud * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ -#include <linux/pseudo_fs.h> #include <linux/fscache.h> #include "internal.h"
@@ -13,18 +12,6 @@ static LIST_HEAD(erofs_domain_list);static LIST_HEAD (erofs_domain_cookies_list);static struct vfsmount *erofs_pseudo_mnt; -static int erofs_anon_init_fs_context (struct fs_context *fc) -{ -return init_pseudo (fc,EROFS_SUPER_MAGIC ) ?0 : -ENOMEM ; -} - -static struct file_system_type erofs_anon_fs_type = { - .owner =THIS_MODULE , - .name ="pseudo_erofs" , - .init_fs_context = erofs_anon_init_fs_context, - .kill_sb = kill_anon_super, -}; -struct erofs_fscache_io {struct netfs_cache_resources cres;struct iov_iter iter;
fs/erofs/internal.h +2 -0
@@ -188,6 +188,8 @@ static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi)return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->dif0.file; } +extern struct file_system_type erofs_anon_fs_type; +static inline bool erofs_is_fscache_mode (struct super_block *sb) { return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) &&
fs/erofs/super.c +15 -0
@@ -11,6 +11,7 @@#include <linux/fs_parser.h> #include <linux/exportfs.h> #include <linux/backing-dev.h> +#include <linux/pseudo_fs.h> #include "xattr.h" #define CREATE_TRACE_POINTS
@@ -936,6 +937,20 @@ static struct file_system_type erofs_fs_type = { };MODULE_ALIAS_FS ("erofs" ); +#if defined(CONFIG_EROFS_FS_ONDEMAND ) +static int erofs_anon_init_fs_context (struct fs_context *fc) +{ +return init_pseudo (fc,EROFS_SUPER_MAGIC ) ?0 : -ENOMEM ; +} + +struct file_system_type erofs_anon_fs_type = { + .owner =THIS_MODULE , + .name ="pseudo_erofs" , + .init_fs_context = erofs_anon_init_fs_context, + .kill_sb = kill_anon_super, +}; +#endif +static int __init erofs_module_init (void ) {int err;
Signature · 1 line
2.22.0
Re: [PATCH v11 04/10] erofs: move `struct erofs_anon_fs_type` to super.c
Quoted 8 lines · Hongbo Li
From: Gao Xiang <[email protected]>
Move the
struct erofs_anon_fs_typeto thesuper.cand expose it in preparation for the upcoming page cache share feature.Signed-off-by Gao Xiang <[email protected]>Signed-off-by Hongbo Li <[email protected]>
Are you sure this is my previous version of this one?
Could you please check carefully before sending
out the next version?
Thanks,
Gao Xiang
Quoted 83 lines
--- fs/erofs/fscache.c | 13 ------------- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-)fs/erofs/fscache.c +0
-13@@ -3,7 +3,6 @@* Copyright (C) 2022, Alibaba Cloud * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ -#include <linux/pseudo_fs.h> #include <linux/fscache.h> #include "internal.h" @@ -13,18 +12,6 @@ static LIST_HEAD(erofs_domain_list);static LIST_HEAD (erofs_domain_cookies_list);static struct vfsmount *erofs_pseudo_mnt; -static int erofs_anon_init_fs_context (struct fs_context *fc) -{ -return init_pseudo (fc,EROFS_SUPER_MAGIC ) ?0 : -ENOMEM ; -} - -static struct file_system_type erofs_anon_fs_type = { - .owner =THIS_MODULE , - .name ="pseudo_erofs" , - .init_fs_context = erofs_anon_init_fs_context, - .kill_sb = kill_anon_super, -}; -struct erofs_fscache_io {struct netfs_cache_resources cres;struct iov_iter iter;fs/erofs/internal.h +2
-0@@ -188,6 +188,8 @@ static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi)return IS_ENABLED (CONFIG_EROFS_FS_BACKED_BY_FILE ) && sbi->dif0.file; } +extern struct file_system_type erofs_anon_fs_type; +static inline bool erofs_is_fscache_mode (struct super_block *sb) { return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) &&fs/erofs/super.c +15
-0@@ -11,6 +11,7 @@#include <linux/fs_parser.h> #include <linux/exportfs.h> #include <linux/backing-dev.h> +#include <linux/pseudo_fs.h> #include "xattr.h" #define CREATE_TRACE_POINTS @@ -936,6 +937,20 @@ static struct file_system_type erofs_fs_type = { };MODULE_ALIAS_FS ("erofs" ); +#if defined(CONFIG_EROFS_FS_ONDEMAND ) +static int erofs_anon_init_fs_context (struct fs_context *fc) +{ +return init_pseudo (fc,EROFS_SUPER_MAGIC ) ?0 : -ENOMEM ; +} + +struct file_system_type erofs_anon_fs_type = { + .owner =THIS_MODULE , + .name ="pseudo_erofs" , + .init_fs_context = erofs_anon_init_fs_context, + .kill_sb = kill_anon_super, +}; +#endif +static int __init erofs_module_init (void ) {int err;
Re: [PATCH v11 04/10] erofs: move `struct erofs_anon_fs_type` to super.c
Quoted 9 lines · Gao Xiang
Quoted 6 lines · Hongbo Li
From: Gao Xiang <[email protected]>
Move the
struct erofs_anon_fs_typeto thesuper.cand expose it in preparation for the upcoming page cache share feature.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Gao Xiang <[email protected]>Signed-off-by Hongbo Li <[email protected]>Are you sure this is my previous version of this one?
Could you please check carefully before sending
out the next version?
Sorry, I mixed up my local patches. I will check carefully in the next time.
Thanks,
Hongbo
Quoted 84 lines
Thanks,
Gao XiangQuoted 79 lines
---
fs/erofs/fscache.c | 13 -------------
fs/erofs/internal.h| 2 ++
fs/erofs/super.c | 15 +++++++++++++++3 files changed, 17 insertions(+), 13 deletions(-)fs/erofs/fscache.c +0
-13@@ -3,7 +3,6 @@* Copyright (C) 2022, Alibaba Cloud * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ -#include <linux/pseudo_fs.h> #include <linux/fscache.h> #include "internal.h"@@ -13,18 +12,6 @@ static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_cookies_list); static struct vfsmount *erofs_pseudo_mnt; -static int erofs_anon_init_fs_context (struct fs_context *fc) -{ - return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; -} - -static struct file_system_type erofs_anon_fs_type = { - .owner = THIS_MODULE, - .name = "pseudo_erofs", - .init_fs_context = erofs_anon_init_fs_context, - .kill_sb = kill_anon_super, -}; - struct erofs_fscache_io { struct netfs_cache_resources cres; struct iov_iter iter;fs/erofs/internal.h +2
-0@@ -188,6 +188,8 @@ static inline bool erofs_is_fileio_mode(struct erofs_sb_info *sbi) return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file; } +extern struct file_system_type erofs_anon_fs_type; + static inline bool erofs_is_fscache_mode(struct super_block *sb) {return
IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND)&&fs/erofs/super.c +15
-0@@ -11,6 +11,7 @@ #include <linux/fs_parser.h> #include <linux/exportfs.h> #include <linux/backing-dev.h> +#include <linux/pseudo_fs.h> #include "xattr.h" #define CREATE_TRACE_POINTS@@ -936,6 +937,20 @@ static struct file_system_type erofs_fs_type = { }; MODULE_ALIAS_FS("erofs"); +#if defined(CONFIG_EROFS_FS_ONDEMAND ) +static int erofs_anon_init_fs_context (struct fs_context *fc) +{ + return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; +} + +struct file_system_type erofs_anon_fs_type = { + .owner = THIS_MODULE, + .name = "pseudo_erofs", + .init_fs_context = erofs_anon_init_fs_context, + .kill_sb = kill_anon_super, +}; +#endif + static int __init erofs_module_init(void) { int err;
PATCH v11 5/10 erofs: support user-defined fingerprint name
In reply to Hongbo LiFrom: Hongzhen Luo <[email protected]>
When creating the EROFS image, users can specify the fingerprint name. This is to prepare for the upcoming inode page cache share.
--- fs/erofs/Kconfig | 9 +++++++++ fs/erofs/erofs_fs.h | 5 +++-- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 3 +++ fs/erofs/xattr.c | 13 +++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-)
fs/erofs/Kconfig +9 -0
@@ -194,3 +194,12 @@ config EROFS_FS_PCPU_KTHREAD_HIPRI at higher priority. If unsure, say N. + +config EROFS_FS_PAGE_CACHE_SHARE + bool "EROFS page cache share support (experimental)" + depends on EROFS_FS && EROFS_FS_XATTR && !EROFS_FS_ONDEMAND + help + This enables page cache sharing among inodes with identical + content fingerprints on the same machine. + + If unsure, say N.
fs/erofs/erofs_fs.h +3 -2
@@ -17,7 +17,7 @@#define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004#define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008#define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010 - +#define EROFS_FEATURE_COMPAT_ISHARE_XATTRS 0x00000020/* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
@@ -83,7 +83,8 @@ struct erofs_super_block {__le32 xattr_prefix_start;/* start of long xattr prefixes */ __le64 packed_nid;/* nid of the special packed inode */ __u8 xattr_filter_reserved;/* reserved for xattr name filter */ -__u8 reserved[3 ]; +__u8 ishare_xattr_prefix_id;/* indexes the ishare key in prefix xattres */ +__u8 reserved[2 ];__le32 build_time;/* seconds added to epoch for mkfs time */ __le64 rootnid_8b;/* (48BIT on) nid of root directory */ __le64 reserved2;
fs/erofs/internal.h +2 -0
@@ -134,6 +134,7 @@ struct erofs_sb_info {u32 xattr_blkaddr;u32 xattr_prefix_start;u8 xattr_prefix_count; +u8 ishare_xattr_pfx;struct erofs_xattr_prefix_item *xattr_prefixes;unsigned int xattr_filter_reserved;#endif
@@ -238,6 +239,7 @@ EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER) EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX) EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX) +EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS)static inline u64 erofs_nid_to_ino64 (struct erofs_sb_info *sbi,erofs_nid_t nid) {
fs/erofs/super.c +3 -0
@@ -298,6 +298,9 @@ static int erofs_read_superblock(struct super_block *sb)if (ret) goto out; } +if (erofs_sb_has_ishare_xattrs (sbi)) + sbi->ishare_xattr_pfx = + dsb->ishare_xattr_prefix_id &EROFS_XATTR_LONG_PREFIX_MASK ; ret = -EINVAL ; sbi->feature_incompat =le32_to_cpu (dsb->feature_incompat);
fs/erofs/xattr.c +13 -0
@@ -519,6 +519,19 @@ int erofs_xattr_prefixes_init(struct super_block *sb) }erofs_put_metabuf (&buf); +if (!ret &&erofs_sb_has_ishare_xattrs (sbi)) { +struct erofs_xattr_prefix_item *pf = pfs + sbi->ishare_xattr_pfx; +struct erofs_xattr_long_prefix *newpfx; + + newpfx =krealloc (pf->prefix, +sizeof (*newpfx) + pf->infix_len +1 ,GFP_KERNEL ); +if (newpfx) { + newpfx->infix[pf->infix_len] ='\0' ; + pf->prefix = newpfx; + }else { + ret = -ENOMEM ; + } + } sbi->xattr_prefixes = pfs;if (ret)erofs_xattr_prefixes_cleanup (sb);
Signature · 1 line
2.22.0
Re: [PATCH v11 05/10] erofs: support user-defined fingerprint name
Quoted 60 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
When creating the EROFS image, users can specify the fingerprint name. This is to prepare for the upcoming inode page cache share.
Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>--- fs/erofs/Kconfig | 9 +++++++++ fs/erofs/erofs_fs.h | 5 +++-- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 3 +++ fs/erofs/xattr.c | 13 +++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-)fs/erofs/Kconfig +9
-0@@ -194,3 +194,12 @@ config EROFS_FS_PCPU_KTHREAD_HIPRI at higher priority. If unsure, say N. + +config EROFS_FS_PAGE_CACHE_SHARE + bool "EROFS page cache share support (experimental)" + depends on EROFS_FS && EROFS_FS_XATTR && !EROFS_FS_ONDEMAND + help + This enables page cache sharing among inodes with identical + content fingerprints on the same machine. + + If unsure, say N.fs/erofs/erofs_fs.h +3
-2@@ -17,7 +17,7 @@#define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004#define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008#define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010 - +#define EROFS_FEATURE_COMPAT_ISHARE_XATTRS 0x00000020/* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should @@ -83,7 +83,8 @@ struct erofs_super_block {__le32 xattr_prefix_start;/* start of long xattr prefixes */ __le64 packed_nid;/* nid of the special packed inode */ __u8 xattr_filter_reserved;/* reserved for xattr name filter */ -__u8 reserved[3 ]; +__u8 ishare_xattr_prefix_id;/* indexes the ishare key in prefix xattres */ +__u8 reserved[2 ];__le32 build_time;/* seconds added to epoch for mkfs time */ __le64 rootnid_8b;/* (48BIT on) nid of root directory */ __le64 reserved2;fs/erofs/internal.h +0
-0
fs/erofs/internal.h struct erofs_sb_info { · line 137
Quoted 4 lines
fs/erofs/internal.h +1
-0@@ -134,6 +134,7 @@ struct erofs_sb_info {u32 xattr_blkaddr;u32 xattr_prefix_start;u8 xattr_prefix_count; +u8 ishare_xattr_pfx;
Could we use the same naming as ishare_xattr_prefix_id?
Quoted 16 lines
fs/erofs/internal.h +1
-0struct erofs_xattr_prefix_item *xattr_prefixes;unsigned int xattr_filter_reserved;#endif @@ -238,6 +239,7 @@ EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER) EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX) EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX) +EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS)static inline u64 erofs_nid_to_ino64 (struct erofs_sb_info *sbi,erofs_nid_t nid) {fs/erofs/super.c +0
-0
fs/erofs/super.c static int erofs_read_superblock(struct super_block *sb) · line 303
Quoted 6 lines
fs/erofs/super.c +3
-0@@ -298,6 +298,9 @@ static int erofs_read_superblock(struct super_block *sb)if (ret) goto out; } +if (erofs_sb_has_ishare_xattrs (sbi)) + sbi->ishare_xattr_pfx = + dsb->ishare_xattr_prefix_id &EROFS_XATTR_LONG_PREFIX_MASK ;
It seems this part is still unmodified.
But after checking the code just now, I agree it may need more work in order to pass dsb to erofs_xattr_prefixes_init(), so I can live with the current status.
Thanks,
Gao Xiang
Quoted 27 lines
fs/erofs/super.c +0
-0ret = -EINVAL ; sbi->feature_incompat =le32_to_cpu (dsb->feature_incompat);fs/erofs/xattr.c +13
-0@@ -519,6 +519,19 @@ int erofs_xattr_prefixes_init(struct super_block *sb) }erofs_put_metabuf (&buf); +if (!ret &&erofs_sb_has_ishare_xattrs (sbi)) { +struct erofs_xattr_prefix_item *pf = pfs + sbi->ishare_xattr_pfx; +struct erofs_xattr_long_prefix *newpfx; + + newpfx =krealloc (pf->prefix, +sizeof (*newpfx) + pf->infix_len +1 ,GFP_KERNEL ); +if (newpfx) { + newpfx->infix[pf->infix_len] ='\0' ; + pf->prefix = newpfx; + }else { + ret = -ENOMEM ; + } + } sbi->xattr_prefixes = pfs;if (ret)erofs_xattr_prefixes_cleanup (sb);
kernel test robot
build botRe: [PATCH v11 05/10] erofs: support user-defined fingerprint name
In reply to Hongbo Likernel test robot noticed the following build errors:
Hi Hongbo,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes brauner-vfs/vfs.all linus/master v6.19-rc2 next-20251219] [cannot apply to mszeredi-fuse/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/iomap-stash-iomap-read-ctx-in-the-private-field-of-iomap_iter/20251224-122950 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20251224040932.496478-6-lihongbo22%40huawei.com patch subject: [PATCH v11 05/10] erofs: support user-defined fingerprint name config: nios2-randconfig-r071-20251225 (https://download.01.org/0day-ci/archive/20251225/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251225/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
fs/erofs/super.c: In function 'erofs_read_superblock':
>> fs/erofs/super.c:302:20: error: 'struct erofs_sb_info' has no member named 'ishare_xattr_pfx'
302 | sbi->ishare_xattr_pfx =
| ^~Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for CAN_DEV Depends on [n]: NETDEVICES [=n] && CAN [=m] Selected by [m]:
- CAN [=m] && NET [=y]
vim +302 fs/erofs/super.c
263
264 static int erofs_read_superblock(struct super_block *sb)
265 {
266 struct erofs_sb_info *sbi = EROFS_SB(sb);
267 struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
268 struct erofs_super_block *dsb;
269 void *data;
270 int ret;
271
272 data = erofs_read_metabuf(&buf, sb, 0, false);
273 if (IS_ERR(data)) {
274 erofs_err(sb, "cannot read erofs superblock");
275 return PTR_ERR(data);
276 }
277
278 dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
279 ret = -EINVAL;
280 if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
281 erofs_err(sb, "cannot find valid erofs superblock");
282 goto out;
283 }
284
285 sbi->blkszbits = dsb->blkszbits;
286 if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) {
287 erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits);
288 goto out;
289 }
290 if (dsb->dirblkbits) {
291 erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits);
292 goto out;
293 }
294
295 sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
296 if (erofs_sb_has_sb_chksum(sbi)) {
297 ret = erofs_superblock_csum_verify(sb, data);
298 if (ret)
299 goto out;
300 }
301 if (erofs_sb_has_ishare_xattrs(sbi))
> 302 sbi->ishare_xattr_pfx =
303 dsb->ishare_xattr_prefix_id & EROFS_XATTR_LONG_PREFIX_MASK;
304
305 ret = -EINVAL;
306 sbi->feature_incompat = le32_to_cpu(dsb->feature_incompat);
307 if (sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT) {
308 erofs_err(sb, "unidentified incompatible feature %x, please upgrade kernel",
309 sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT);
310 goto out;
311 }
312
313 sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
314 if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) {
315 erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
316 sbi->sb_size);
317 goto out;
318 }
319 sbi->dif0.blocks = le32_to_cpu(dsb->blocks_lo);
320 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
321 #ifdef CONFIG_EROFS_FS_XATTR
322 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
323 sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
324 sbi->xattr_prefix_count = dsb->xattr_prefix_count;
325 sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
326 #endif
327 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
328 if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
329 sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
330 sbi->dif0.blocks = sbi->dif0.blocks |
331 ((u64)le16_to_cpu(dsb->rb.blocks_hi) << 32);
332 } else {
333 sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
334 }
335 sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
336 if (erofs_sb_has_metabox(sbi)) {
337 if (sbi->sb_size <= offsetof(struct erofs_super_block,
338 metabox_nid))
339 return -EFSCORRUPTED;
340 sbi->metabox_nid = le64_to_cpu(dsb->metabox_nid);
341 if (sbi->metabox_nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT))
342 return -EFSCORRUPTED; /* self-loop detection */
343 }
344 sbi->inos = le64_to_cpu(dsb->inos);
345
346 sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
347 sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
348 super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
349
350 if (dsb->volume_name[0]) {
351 sbi->volume_name = kstrndup(dsb->volume_name,
352 sizeof(dsb->volume_name), GFP_KERNEL);
353 if (!sbi->volume_name)
354 return -ENOMEM;
355 }
356
357 /* parse on-disk compression configurations */
358 ret = z_erofs_parse_cfgs(sb, dsb);
359 if (ret < 0)
360 goto out;
361
362 ret = erofs_scan_devices(sb, dsb);
363
364 if (erofs_sb_has_48bit(sbi))
365 erofs_info(sb, "EXPERIMENTAL 48-bit layout support in use. Use at your own risk!");
366 if (erofs_sb_has_metabox(sbi))
367 erofs_info(sb, "EXPERIMENTAL metadata compression support in use. Use at your own risk!");
368 if (erofs_is_fscache_mode(sb))
369 erofs_info(sb, "[deprecated] fscache-based on-demand read feature in use. Use at your own risk!");
370 out:
371 erofs_put_metabuf(&buf);
372 return ret;
373 }
374
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v11 05/10] erofs: support user-defined fingerprint name
In reply to Hongbo Likernel test robot noticed the following build errors:
Hi Hongbo,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes brauner-vfs/vfs.all linus/master v6.19-rc2 next-20251219] [cannot apply to mszeredi-fuse/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/iomap-stash-iomap-read-ctx-in-the-private-field-of-iomap_iter/20251224-122950 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20251224040932.496478-6-lihongbo22%40huawei.com patch subject: [PATCH v11 05/10] erofs: support user-defined fingerprint name config: powerpc-randconfig-001-20251225 (https://download.01.org/0day-ci/archive/20251225/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251225/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> fs/erofs/super.c:302:8: error: no member named 'ishare_xattr_pfx' in 'struct erofs_sb_info'
302 | sbi->ishare_xattr_pfx =
| ~~~ ^1 error generated.
vim +302 fs/erofs/super.c
263
264 static int erofs_read_superblock(struct super_block *sb)
265 {
266 struct erofs_sb_info *sbi = EROFS_SB(sb);
267 struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
268 struct erofs_super_block *dsb;
269 void *data;
270 int ret;
271
272 data = erofs_read_metabuf(&buf, sb, 0, false);
273 if (IS_ERR(data)) {
274 erofs_err(sb, "cannot read erofs superblock");
275 return PTR_ERR(data);
276 }
277
278 dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
279 ret = -EINVAL;
280 if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
281 erofs_err(sb, "cannot find valid erofs superblock");
282 goto out;
283 }
284
285 sbi->blkszbits = dsb->blkszbits;
286 if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) {
287 erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits);
288 goto out;
289 }
290 if (dsb->dirblkbits) {
291 erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits);
292 goto out;
293 }
294
295 sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
296 if (erofs_sb_has_sb_chksum(sbi)) {
297 ret = erofs_superblock_csum_verify(sb, data);
298 if (ret)
299 goto out;
300 }
301 if (erofs_sb_has_ishare_xattrs(sbi))
> 302 sbi->ishare_xattr_pfx =
303 dsb->ishare_xattr_prefix_id & EROFS_XATTR_LONG_PREFIX_MASK;
304
305 ret = -EINVAL;
306 sbi->feature_incompat = le32_to_cpu(dsb->feature_incompat);
307 if (sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT) {
308 erofs_err(sb, "unidentified incompatible feature %x, please upgrade kernel",
309 sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT);
310 goto out;
311 }
312
313 sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
314 if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) {
315 erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
316 sbi->sb_size);
317 goto out;
318 }
319 sbi->dif0.blocks = le32_to_cpu(dsb->blocks_lo);
320 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
321 #ifdef CONFIG_EROFS_FS_XATTR
322 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
323 sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
324 sbi->xattr_prefix_count = dsb->xattr_prefix_count;
325 sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
326 #endif
327 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
328 if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
329 sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
330 sbi->dif0.blocks = sbi->dif0.blocks |
331 ((u64)le16_to_cpu(dsb->rb.blocks_hi) << 32);
332 } else {
333 sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
334 }
335 sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
336 if (erofs_sb_has_metabox(sbi)) {
337 if (sbi->sb_size <= offsetof(struct erofs_super_block,
338 metabox_nid))
339 return -EFSCORRUPTED;
340 sbi->metabox_nid = le64_to_cpu(dsb->metabox_nid);
341 if (sbi->metabox_nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT))
342 return -EFSCORRUPTED; /* self-loop detection */
343 }
344 sbi->inos = le64_to_cpu(dsb->inos);
345
346 sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
347 sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
348 super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
349
350 if (dsb->volume_name[0]) {
351 sbi->volume_name = kstrndup(dsb->volume_name,
352 sizeof(dsb->volume_name), GFP_KERNEL);
353 if (!sbi->volume_name)
354 return -ENOMEM;
355 }
356
357 /* parse on-disk compression configurations */
358 ret = z_erofs_parse_cfgs(sb, dsb);
359 if (ret < 0)
360 goto out;
361
362 ret = erofs_scan_devices(sb, dsb);
363
364 if (erofs_sb_has_48bit(sbi))
365 erofs_info(sb, "EXPERIMENTAL 48-bit layout support in use. Use at your own risk!");
366 if (erofs_sb_has_metabox(sbi))
367 erofs_info(sb, "EXPERIMENTAL metadata compression support in use. Use at your own risk!");
368 if (erofs_is_fscache_mode(sb))
369 erofs_info(sb, "[deprecated] fscache-based on-demand read feature in use. Use at your own risk!");
370 out:
371 erofs_put_metabuf(&buf);
372 return ret;
373 }
374
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v11 05/10] erofs: support user-defined fingerprint name
Quoted 85 lines · kernel test robot
Hi Hongbo,
kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on xiang-erofs/dev xiang-erofs/fixes brauner-vfs/vfs.all linus/master v6.19-rc2 next-20251219] [cannot apply to mszeredi-fuse/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Hongbo-Li/iomap-stash-iomap-read-ctx-in-the-private-field-of-iomap_iter/20251224-122950 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20251224040932.496478-6-lihongbo22%40huawei.com patch subject: [PATCH v11 05/10] erofs: support user-defined fingerprint name config: powerpc-randconfig-001-20251225 (https://download.01.org/0day-ci/archive/20251225/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 4ef602d446057dabf5f61fb221669ecbeda49279) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251225/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
fs/erofs/super.c:302:8: error: no member named 'ishare_xattr_pfx' in 'structerofs_sb_info'302 | sbi->ishare_xattr_pfx = | ~~~ ^1 error generated.
vim +302
fs/erofs/super.c263 264 static int erofs_read_superblock(struct super_block *sb) 265 { 266 struct erofs_sb_info *sbi = EROFS_SB(sb); 267 struct erofs_buf buf = __EROFS_BUF_INITIALIZER; 268 struct erofs_super_block *dsb; 269 void *data; 270 int ret; 271 272 data = erofs_read_metabuf(&buf, sb, 0, false); 273 if (IS_ERR(data)) { 274 erofs_err(sb, "cannot read erofs superblock"); 275 return PTR_ERR(data); 276 } 277 278 dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET); 279 ret = -EINVAL; 280 if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) { 281 erofs_err(sb, "cannot find valid erofs superblock"); 282 goto out; 283 } 284 285 sbi->blkszbits = dsb->blkszbits; 286 if (sbi->blkszbits < 9 || sbi->blkszbits > PAGE_SHIFT) { 287 erofs_err(sb, "blkszbits %u isn't supported", sbi->blkszbits); 288 goto out; 289 } 290 if (dsb->dirblkbits) { 291 erofs_err(sb, "dirblkbits %u isn't supported", dsb->dirblkbits); 292 goto out; 293 } 294 295 sbi->feature_compat = le32_to_cpu(dsb->feature_compat); 296 if (erofs_sb_has_sb_chksum(sbi)) { 297 ret = erofs_superblock_csum_verify(sb, data); 298 if (ret) 299 goto out; 300 } 301 if (erofs_sb_has_ishare_xattrs(sbi))Quoted 1 line
302
sbi->ishare_xattr_pfx=303 dsb->ishare_xattr_prefix_id & EROFS_XATTR_LONG_PREFIX_MASK; 304 305 ret = -EINVAL; 306 sbi->feature_incompat = le32_to_cpu(dsb->feature_incompat); 307 if (sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT) { 308 erofs_err(sb, "unidentified incompatible feature %x, please upgrade kernel", 309 sbi->feature_incompat & ~EROFS_ALL_FEATURE_INCOMPAT); 310 goto out; 311 } 312 313 sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
Quoted 8 lines
314 if (sbi->sb_size > PAGE_SIZE - EROFS_SUPER_OFFSET) {
315 erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
316 sbi->sb_size);
317 goto out;
318 }
319 sbi->dif0.blocks = le32_to_cpu(dsb->blocks_lo);
320 sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
321 #ifdef CONFIG_EROFS_FS_XATTRThe EROFS_FS_XATTR is disabled, so should put in here.. I will fix it in next version.
Thanks,
Hongbo
Quoted 54 lines
322 sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
323 sbi->xattr_prefix_start = le32_to_cpu(dsb->xattr_prefix_start);
324 sbi->xattr_prefix_count = dsb->xattr_prefix_count;
325 sbi->xattr_filter_reserved = dsb->xattr_filter_reserved;
326 #endif
327 sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
328 if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) {
329 sbi->root_nid = le64_to_cpu(dsb->rootnid_8b);
330 sbi->dif0.blocks = sbi->dif0.blocks |
331 ((u64)le16_to_cpu(dsb->rb.blocks_hi) << 32);
332 } else {
333 sbi->root_nid = le16_to_cpu(dsb->rb.rootnid_2b);
334 }
335 sbi->packed_nid = le64_to_cpu(dsb->packed_nid);
336 if (erofs_sb_has_metabox(sbi)) {
337 if (sbi->sb_size <= offsetof(struct erofs_super_block,
338 metabox_nid))
339 return -EFSCORRUPTED;
340 sbi->metabox_nid = le64_to_cpu(dsb->metabox_nid);
341 if (sbi->metabox_nid & BIT_ULL(EROFS_DIRENT_NID_METABOX_BIT))
342 return -EFSCORRUPTED; /* self-loop detection */
343 }
344 sbi->inos = le64_to_cpu(dsb->inos);
345
346 sbi->epoch = (s64)le64_to_cpu(dsb->epoch);
347 sbi->fixed_nsec = le32_to_cpu(dsb->fixed_nsec);
348 super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid));
349
350 if (dsb->volume_name[0]) {
351 sbi->volume_name = kstrndup(dsb->volume_name,
352 sizeof(dsb->volume_name), GFP_KERNEL);
353 if (!sbi->volume_name)
354 return -ENOMEM;
355 }
356
357 /* parse on-disk compression configurations */
358 ret = z_erofs_parse_cfgs(sb, dsb);
359 if (ret < 0)
360 goto out;
361
362 ret = erofs_scan_devices(sb, dsb);
363
364 if (erofs_sb_has_48bit(sbi))
365 erofs_info(sb, "EXPERIMENTAL 48-bit layout support in use. Use at your own risk!");
366 if (erofs_sb_has_metabox(sbi))
367 erofs_info(sb, "EXPERIMENTAL metadata compression support in use. Use at your own risk!");
368 if (erofs_is_fscache_mode(sb))
369 erofs_info(sb, "[deprecated] fscache-based on-demand read feature in use. Use at your own risk!");
370 out:
371 erofs_put_metabuf(&buf);
372 return ret;
373 }
374 PATCH v11 6/10 erofs: support domain-specific page cache share
In reply to Hongbo LiFrom: Hongzhen Luo <[email protected]>
Only files in the same domain will share the page cache. Also modify the sysfs related content in preparation for the upcoming page cache share feature.
--- fs/erofs/super.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/erofs/super.c +3 -3
@@ -518,6 +518,8 @@ static int erofs_fc_parse_param(struct fs_context *fc,if (!sbi->fsid)return -ENOMEM ;break ; +#endif +#if defined(CONFIG_EROFS_FS_ONDEMAND ) || defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE )case Opt_domain_id:kfree (sbi->domain_id); sbi->domain_id =kstrdup (param->string,GFP_KERNEL );
@@ -618,7 +620,7 @@ static void erofs_set_sysfs_name(struct super_block *sb) {struct erofs_sb_info *sbi =EROFS_SB (sb); -if (sbi->domain_id) +if (sbi->domain_id && !erofs_sb_has_ishare_xattrs (sbi))super_set_sysfs_name_generic (sb,"%s,%s" , sbi->domain_id, sbi->fsid);else if (sbi->fsid)
@@ -1049,12 +1051,10 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)seq_puts (seq,",dax=never" );if (erofs_is_fileio_mode (sbi) &&test_opt (opt,DIRECT_IO ))seq_puts (seq,",directio" ); -#ifdef CONFIG_EROFS_FS_ONDEMAND if (sbi->fsid)seq_printf (seq,",fsid=%s" , sbi->fsid);if (sbi->domain_id)seq_printf (seq,",domain_id=%s" , sbi->domain_id); -#endif if (sbi->dif0.fsoff)seq_printf (seq,",fsoffset=%llu" , sbi->dif0.fsoff);return 0 ;
Signature · 1 line
2.22.0
Re: [PATCH v11 06/10] erofs: support domain-specific page cache share
Quoted 8 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
Only files in the same domain will share the page cache. Also modify the sysfs related content in preparation for the upcoming page cache share feature.
Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>
Thanks,
Gao Xiang
PATCH v11 7/10 erofs: introduce the page cache share feature
In reply to Hongbo LiFrom: Hongzhen Luo <[email protected]>
Currently, reading files with different paths (or names) but the same content will consume multiple copies of the page cache, even if the content of these page caches is the same. For example, reading identical files (e.g., *.so files) from two different minor versions of container images will cost multiple copies of the same page cache, since different containers have different mount points. Therefore, sharing the page cache for files with the same content can save memory.
This introduces the page cache share feature in erofs. It allocate a deduplicated inode and use its page cache as shared. Reads for files with identical content will ultimately be routed to the page cache of the deduplicated inode. In this way, a single page cache satisfies multiple read requests for different files with the same contents.
We introduce inode_share mount option to enable the page sharing mode during mounting.
--- Documentation/filesystems/erofs.rst | 4 + fs/erofs/Makefile | 1 + fs/erofs/internal.h | 31 +++++ fs/erofs/ishare.c | 171 ++++++++++++++++++++++++++++ fs/erofs/super.c | 52 ++++++++- fs/erofs/xattr.c | 40 ++++++- fs/erofs/xattr.h | 12 +- 7 files changed, 300 insertions(+), 11 deletions(-) create mode 100644 fs/erofs/ishare.c
Documentation/filesystems/erofs.rst +4 -0
@@ -128,7 +128,11 @@ device=%s Specify a path to an extra device to be used together. fsid=%s Specify a filesystem image ID for Fscache back-end. domain_id=%s Specify a domain ID in fscache mode so that different images with the same blobs under a given domain ID can share storage. + Also used for inode page sharing mode which defines a sharing + domain. fsoffset=%llu Specify block-aligned filesystem offset for the primary device. +inode_share Enable inode page sharing mode. Files with the same content + can reuse page cache under the same domain_id. =================== ========================================================= Sysfs Entries
fs/erofs/Makefile +1 -0
@@ -10,3 +10,4 @@ erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_ZIP_ACCEL) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o +erofs-$(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) += ishare.o
fs/erofs/internal.h +31 -0
@@ -179,6 +179,7 @@ struct erofs_sb_info {#define EROFS_MOUNT_DAX_ALWAYS 0x00000040#define EROFS_MOUNT_DAX_NEVER 0x00000080#define EROFS_MOUNT_DIRECT_IO 0x00000100 +#define EROFS_MOUNT_INODE_SHARE 0x00000200#define clear_opt (opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)
@@ -269,6 +270,13 @@ static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid)/* default readahead size of directories */ #define EROFS_DIR_RA_BYTES 16384 +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint { +u8 *opaque; +int size; +}; +#endif +struct erofs_inode {erofs_nid_t nid;
@@ -304,6 +312,16 @@ struct erofs_inode { };#endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct list_head ishare_list; +union { +struct { +struct erofs_inode_fingerprint fingerprint; +spinlock_t ishare_lock; + }; +struct inode *realinode; + }; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; };
@@ -410,6 +428,7 @@ extern const struct inode_operations erofs_dir_iops;extern const struct file_operations erofs_file_fops;extern const struct file_operations erofs_dir_fops; +extern const struct file_operations erofs_ishare_fops;extern const struct iomap_ops z_erofs_iomap_report_ops;
@@ -541,6 +560,18 @@ static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) {static inline void erofs_fscache_submit_bio (struct bio *bio) {}#endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +int __init erofs_init_ishare (void ); +void erofs_exit_ishare (void ); +bool erofs_ishare_fill_inode (struct inode *inode); +void erofs_ishare_free_inode (struct inode *inode); +#else +static inline int erofs_init_ishare (void ) {return 0 ; } +static inline void erofs_exit_ishare (void ) {} +static inline bool erofs_ishare_fill_inode (struct inode *inode) {return false; } +static inline void erofs_ishare_free_inode (struct inode *inode) {} +#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long erofs_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);
fs/erofs/ishare.c new file +171 -0
171 lines not on this page · raw message
fs/erofs/super.c +49 -3
117 lines not on this page · raw message
fs/erofs/xattr.c +39 -1
@@ -25,6 +25,9 @@ struct erofs_xattr_iter {struct dentry *dentry; }; +static int erofs_getxattr (struct inode *inode,int index,const char *name, +void *buffer,size_t buffer_size); +static int erofs_init_inode_xattrs (struct inode *inode) {struct erofs_inode *const vi =EROFS_I (inode);
@@ -391,7 +394,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it,return i ? ret : -ENODATA ; } -int erofs_getxattr (struct inode *inode,int index,const char *name, +static int erofs_getxattr (struct inode *inode,int index,const char *name,void *buffer,size_t buffer_size) {int ret;
@@ -577,3 +580,38 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)return acl; }#endif + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp (struct inode *inode, +const char *domain_id) +{ +struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb); +struct erofs_inode_fingerprint fp = {}; +struct erofs_xattr_prefix_item *prefix; +const char *infix; +int valuelen, base_index, domainlen; + +if (!erofs_sb_has_ishare_xattrs (sbi)) + goto out; + prefix = sbi->xattr_prefixes + sbi->ishare_xattr_pfx; + infix = prefix->prefix->infix; + base_index = prefix->prefix->base_index; + valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 ); +if (valuelen <=0 || valuelen > (1 << sbi->blkszbits)) + goto out; + domainlen = domain_id ?strlen (domain_id) :0 ; + fp.opaque =kmalloc (valuelen + domainlen,GFP_KERNEL ); +if (!fp.opaque) + goto out; +if (valuelen !=erofs_getxattr (inode, base_index, infix, + fp.opaque, valuelen)) { +kfree (fp.opaque); + fp.opaque =NULL ; + goto out; + } +memcpy (fp.opaque + valuelen, domain_id, domainlen); + fp.size = valuelen + domainlen; +out: +return fp; +} +#endif
fs/erofs/xattr.h +5 -7
@@ -45,17 +45,10 @@ extern const struct xattr_handler * const erofs_xattr_handlers[];int erofs_xattr_prefixes_init (struct super_block *sb);void erofs_xattr_prefixes_cleanup (struct super_block *sb); -int erofs_getxattr (struct inode *,int ,const char *,void *,size_t );ssize_t erofs_listxattr (struct dentry *,char *,size_t );#else static inline int erofs_xattr_prefixes_init (struct super_block *sb) {return 0 ; }static inline void erofs_xattr_prefixes_cleanup (struct super_block *sb) {} -static inline int erofs_getxattr (struct inode *inode,int index, -const char *name,void *buffer, -size_t buffer_size) -{ -return -EOPNOTSUPP ; -}#define erofs_listxattr (NULL)#define erofs_xattr_handlers (NULL)
@@ -67,4 +60,9 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);#define erofs_get_acl (NULL)#endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp (struct inode *inode, +const char *domain_id); +#endif +#endif
Signature · 1 line
2.22.0
Re: [PATCH v11 07/10] erofs: introduce the page cache share feature
Quoted 37 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
Currently, reading files with different paths (or names) but the same content will consume multiple copies of the page cache, even if the content of these page caches is the same. For example, reading identical files (e.g., *.so files) from two different minor versions of container images will cost multiple copies of the same page cache, since different containers have different mount points. Therefore, sharing the page cache for files with the same content can save memory.
This introduces the page cache share feature in erofs. It allocate a deduplicated inode and use its page cache as shared. Reads for files with identical content will ultimately be routed to the page cache of the deduplicated inode. In this way, a single page cache satisfies multiple read requests for different files with the same contents.
We introduce
inode_sharemount option to enable the page sharing mode during mounting.Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>--- Documentation/filesystems/erofs.rst | 4 + fs/erofs/Makefile | 1 + fs/erofs/internal.h | 31 +++++ fs/erofs/ishare.c | 171 ++++++++++++++++++++++++++++ fs/erofs/super.c | 52 ++++++++- fs/erofs/xattr.c | 40 ++++++- fs/erofs/xattr.h | 12 +- 7 files changed, 300 insertions(+), 11 deletions(-)create mode 100644
fs/erofs/ishare.cDocumentation/filesystems/erofs.rst +0
-0
Documentation/filesystems/erofs.rst device=%s Specify a path to an extra device to be used together. · line 135
Quoted 8 lines
Documentation/filesystems/erofs.rst +4
-0@@ -128,7 +128,11 @@ device=%s Specify a path to an extra device to be used together. fsid=%s Specify a filesystem image ID for Fscache back-end. domain_id=%s Specify a domain ID in fscache mode so that different images with the same blobs under a given domain ID can share storage. + Also used for inode page sharing mode which defines a sharing + domain. fsoffset=%llu Specify block-aligned filesystem offset for the primary device. +inode_share Enable inode page sharing mode. Files with the same content + can reuse page cache under the same domain_id.
Enable inode page sharing for this filesystem. Inodes with identical content within the same domain ID can share the page cache.
Quoted 39 lines
Documentation/filesystems/erofs.rst +0
-0=================== ========================================================= Sysfs Entriesfs/erofs/Makefile +1
-0@@ -10,3 +10,4 @@ erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_ZIP_ACCEL) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o +erofs-$(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) += ishare.ofs/erofs/internal.h +8
-0@@ -179,6 +179,7 @@ struct erofs_sb_info {#define EROFS_MOUNT_DAX_ALWAYS 0x00000040#define EROFS_MOUNT_DAX_NEVER 0x00000080#define EROFS_MOUNT_DIRECT_IO 0x00000100 +#define EROFS_MOUNT_INODE_SHARE 0x00000200#define clear_opt (opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option)#define set_opt (opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)@@ -269,6 +270,13 @@ static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid)/* default readahead size of directories */ #define EROFS_DIR_RA_BYTES 16384 +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint { +u8 *opaque; +int size; +}; +#endif +struct erofs_inode {erofs_nid_t nid;
fs/erofs/internal.h struct erofs_inode { · line 317
Quoted 6 lines
fs/erofs/internal.h +3
-0@@ -304,6 +312,16 @@ struct erofs_inode { };#endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct list_head ishare_list; + union {
/* for each anon shared inode */
fs/erofs/internal.h struct erofs_inode { · line 321
Quoted 4 lines
fs/erofs/internal.h +4
-0+struct { +struct erofs_inode_fingerprint fingerprint; +spinlock_t ishare_lock; + };
/* for each real inode */
fs/erofs/internal.h struct erofs_inode { · line 322
Quoted 1 line
fs/erofs/internal.h +1
-0+struct inode *realinode;
Sorry, I think this variable indicates the anon inode instead of some real inode, so it should be called
struct inode *sharedinode;
Quoted 66 lines
fs/erofs/internal.h +15
-0+ }; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; };@@ -410,6 +428,7 @@ extern const struct inode_operations erofs_dir_iops;extern const struct file_operations erofs_file_fops;extern const struct file_operations erofs_dir_fops; +extern const struct file_operations erofs_ishare_fops;extern const struct iomap_ops z_erofs_iomap_report_ops;@@ -541,6 +560,18 @@ static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) {static inline void erofs_fscache_submit_bio (struct bio *bio) {}#endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +int __init erofs_init_ishare (void ); +void erofs_exit_ishare (void ); +bool erofs_ishare_fill_inode (struct inode *inode); +void erofs_ishare_free_inode (struct inode *inode); +#else +static inline int erofs_init_ishare (void ) {return 0 ; } +static inline void erofs_exit_ishare (void ) {} +static inline bool erofs_ishare_fill_inode (struct inode *inode) {return false; } +static inline void erofs_ishare_free_inode (struct inode *inode) {} +#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE +long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);long erofs_compat_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);fs/erofs/ishare.c new file +28
-0@@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include <linux/xxhash.h> +#include <linux/mount.h> +#include "internal.h" +#include "xattr.h" + +#include "../internal.h" + +static struct vfsmount *erofs_ishare_mnt; + +static int erofs_ishare_iget5_eq (struct inode *inode,void *data) +{ +struct erofs_inode_fingerprint *fp1 = &EROFS_I (inode)->fingerprint; +struct erofs_inode_fingerprint *fp2 = data; + +return fp1->size == fp2->size && + !memcmp (fp1->opaque, fp2->opaque, fp2->size); +} + +static int erofs_ishare_iget5_set (struct inode *inode,void *data) +{ +struct erofs_inode *vi =EROFS_I (inode); + + vi->fingerprint = *(struct erofs_inode_fingerprint *)data; +INIT_LIST_HEAD (&vi->ishare_list);
fs/erofs/ishare.c line 38
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+spin_lock_init (&vi->ishare_lock); +return 0 ; +} + +bool erofs_ishare_fill_inode (struct inode *inode) +{ +struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb); +struct erofs_inode *vi =EROFS_I (inode); +struct erofs_inode_fingerprint fp; +struct inode *idedup;
maybe just aligned with the term above
struct inode *sharedinode;
Quoted 7 lines
fs/erofs/ishare.c new file +7
-0+unsigned long hash; + +if (!test_opt (&sbi->opt,INODE_SHARE )) +return false; + fp =erofs_xattr_get_ishare_fp (inode, sbi->domain_id); +if (!fp.size) +return false;
fs/erofs/ishare.c line 55
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+ hash =xxh32 (fp.opaque, fp.size,0 ); + idedup =iget5_locked (erofs_ishare_mnt->mnt_sb, hash, + erofs_ishare_iget5_eq, erofs_ishare_iget5_set, + &fp); +if (!idedup) { +kfree (fp.opaque); +return false; + } + +INIT_LIST_HEAD (&vi->ishare_list);
I think we could move this line after the following if block and just before spin_lock.
Quoted 11 lines
fs/erofs/ishare.c new file +11
-0+ vi->realinode = idedup; +if (inode_state_read_once (idedup) &I_NEW ) { +if (erofs_inode_is_data_compressed (vi->datalayout)) + idedup->i_mapping->a_ops = &z_erofs_aops; +else + idedup->i_mapping->a_ops = &erofs_aops; + idedup->i_mode = vi->vfs_inode.i_mode; + idedup->i_size = vi->vfs_inode.i_size; +unlock_new_inode (idedup); + }else { +kfree (fp.opaque);
fs/erofs/ishare.c line 77
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+ } + spin_lock(&EROFS_I(idedup)->ishare_lock);> + list_add(&vi->ishare_list, &EROFS_I(idedup)->ishare_list); +spin_unlock (&EROFS_I (idedup)->ishare_lock); +return true; +} + +void erofs_ishare_free_inode (struct inode *inode) +{ +struct erofs_inode *vi =EROFS_I (inode); +struct inode *idedup = vi->realinode;
struct inode *sharedinode = vi->sharedinode;
Quoted 4 lines
fs/erofs/ishare.c new file +4
-0+ +if (!idedup) +return ; +spin_lock (&EROFS_I (idedup)->ishare_lock);
fs/erofs/ishare.c line 91
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+list_del (&vi->ishare_list); +spin_unlock (&EROFS_I (idedup)->ishare_lock); +iput (idedup); + vi->realinode =NULL ; +} + +static int erofs_ishare_file_open (struct inode *inode,struct file *file) +{ +struct file *realfile; +struct inode *dedup;
same here, sharedinode;
Quoted 30 lines
fs/erofs/ishare.c new file +30
-0+ + dedup =EROFS_I (inode)->realinode; + realfile =alloc_empty_backing_file (O_RDONLY |O_NOATIME ,current_cred ()); +if (IS_ERR (realfile)) +return PTR_ERR (realfile); +ihold (dedup); + realfile->f_op = &erofs_file_fops; + realfile->f_inode = dedup; + realfile->f_mapping = dedup->i_mapping; +path_get (&file->f_path); +backing_file_set_user_path (realfile, &file->f_path); + +file_ra_state_init (&realfile->f_ra, file->f_mapping); + realfile->private_data =EROFS_I (inode); + file->private_data = realfile; +return 0 ; +} + +static int erofs_ishare_file_release (struct inode *inode,struct file *file) +{ +struct file *realfile = file->private_data; + +iput (realfile->f_inode); +fput (realfile); + file->private_data =NULL ; +return 0 ; +} + +static ssize_t erofs_ishare_file_read_iter (struct kiocb *iocb, +struct iov_iter *to)
fs/erofs/ishare.c line 131
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+{ +struct file *realfile = iocb->ki_filp->private_data; +struct inode *inode =file_inode (iocb->ki_filp); +struct kiocb dedup_iocb; +ssize_t nread; + +if (!iov_iter_count (to)) +return 0 ; + +/* fallback to the original file in DAX or DIRECT mode */
I think we should just disallow FSDAX if inode_share is on.
Quoted 176 lines
fs/erofs/ishare.c new file +40
-0+if (IS_DAX (inode) || (iocb->ki_flags &IOCB_DIRECT )) + realfile = iocb->ki_filp; + +kiocb_clone (&dedup_iocb, iocb, realfile); + nread =filemap_read (&dedup_iocb, to,0 ); + iocb->ki_pos = dedup_iocb.ki_pos; +file_accessed (iocb->ki_filp); +return nread; +} + +static int erofs_ishare_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct file *realfile = file->private_data; + +vma_set_file (vma, realfile); +return generic_file_readonly_mmap (file, vma); +} + +const struct file_operations erofs_ishare_fops = { + .open = erofs_ishare_file_open, + .llseek = generic_file_llseek, + .read_iter = erofs_ishare_file_read_iter, + .mmap = erofs_ishare_mmap, + .release = erofs_ishare_file_release, + .get_unmapped_area = thp_get_unmapped_area, + .splice_read = filemap_splice_read, +}; + +int __init erofs_init_ishare (void ) +{ + erofs_ishare_mnt =kern_mount (&erofs_anon_fs_type); +if (IS_ERR (erofs_ishare_mnt)) +return PTR_ERR (erofs_ishare_mnt); +return 0 ; +} + +void erofs_exit_ishare (void ) +{ +kern_unmount (erofs_ishare_mnt); +}fs/erofs/super.c +49
-3@@ -390,6 +390,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi)enum { Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum, Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_fsoffset, + Opt_inode_share, };static const struct constant_table erofs_param_cache_strategy[] = {@@ -417,6 +418,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = {fsparam_string ("domain_id" , Opt_domain_id),fsparam_flag_no ("directio" , Opt_directio),fsparam_u64 ("fsoffset" , Opt_fsoffset), + fsparam_flag("inode_share", Opt_inode_share), {} };@@ -545,6 +547,14 @@ static int erofs_fc_parse_param(struct fs_context *fc,case Opt_fsoffset: sbi->dif0.fsoff = result.uint_64;break ; +#if defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE ) +case Opt_inode_share: +set_opt (&sbi->opt,INODE_SHARE ); +#else +case Opt_inode_share: +errorfc (fc,"%s option not supported" , erofs_fs_parameters[opt].name); +#endif +break ; }return 0 ; }@@ -643,6 +653,12 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes =MAX_LFS_FILESIZE ; sb->s_op = &erofs_sops; +if (sbi->domain_id && + (!sbi->fsid && !test_opt (&sbi->opt,INODE_SHARE ))) { +errorfc (fc,"domain_id should be with fsid or inode_share option" ); +return -EINVAL ; + } + sbi->blkszbits =PAGE_SHIFT ;if (!sb->s_bdev) {/* @@ -942,14 +958,34 @@ static struct file_system_type erofs_fs_type = { };MODULE_ALIAS_FS ("erofs" ); -#if defined(CONFIG_EROFS_FS_ONDEMAND ) +#if defined(CONFIG_EROFS_FS_ONDEMAND ) || defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE ) +static void erofs_free_anon_inode (struct inode *inode) +{ +struct erofs_inode *vi =EROFS_I (inode); + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +kfree (vi->fingerprint.opaque); +#endif +kmem_cache_free (erofs_inode_cachep, vi); +} + +static const struct super_operations erofs_anon_sops = { + .alloc_inode = erofs_alloc_inode, + .free_inode = erofs_free_anon_inode, +}; +static int erofs_anon_init_fs_context (struct fs_context *fc) { -return init_pseudo (fc,EROFS_SUPER_MAGIC ) ?0 : -ENOMEM ; +struct pseudo_fs_context *ctx; + + ctx =init_pseudo (fc,EROFS_SUPER_MAGIC ); +if (ctx) + ctx->ops = &erofs_anon_sops; + +return ctx ?0 : -ENOMEM ; }struct file_system_type erofs_anon_fs_type = { - .owner =THIS_MODULE , .name ="pseudo_erofs" , .init_fs_context = erofs_anon_init_fs_context, .kill_sb = kill_anon_super,@@ -981,6 +1017,10 @@ static int __init erofs_module_init(void)if (err) goto sysfs_err; + err =erofs_init_ishare (); +if (err) + goto ishare_err; + err =register_filesystem (&erofs_fs_type);if (err) goto fs_err;@@ -988,6 +1028,8 @@ static int __init erofs_module_init(void)return 0 ; fs_err: +erofs_exit_ishare (); +ishare_err:erofs_exit_sysfs (); sysfs_err:z_erofs_exit_subsystem ();@@ -1005,6 +1047,7 @@ static void __exit erofs_module_exit(void)/* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ rcu_barrier (); +erofs_exit_ishare ();erofs_exit_sysfs ();z_erofs_exit_subsystem ();erofs_exit_shrinker ();@@ -1057,6 +1100,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)seq_printf (seq,",domain_id=%s" , sbi->domain_id);if (sbi->dif0.fsoff)seq_printf (seq,",fsoffset=%llu" , sbi->dif0.fsoff); +if (test_opt (opt,INODE_SHARE )) +seq_puts (seq,",inode_share" );return 0 ; }@@ -1067,6 +1112,7 @@ static void erofs_evict_inode(struct inode *inode)dax_break_layout_final (inode);#endif +erofs_ishare_free_inode (inode);truncate_inode_pages_final (&inode->i_data);clear_inode (inode); }fs/erofs/xattr.c +0
-0
fs/erofs/xattr.c struct erofs_xattr_iter { · line 29
Quoted 5 lines
fs/erofs/xattr.c +2
-0@@ -25,6 +25,9 @@ struct erofs_xattr_iter {struct dentry *dentry; }; +static int erofs_getxattr (struct inode *inode,int index,const char *name, +void *buffer,size_t buffer_size);
could we clean it up in a seperate patch? It can be an independent patch against this series.
Quoted 14 lines
fs/erofs/xattr.c +2
-1+static int erofs_init_inode_xattrs (struct inode *inode) {struct erofs_inode *const vi =EROFS_I (inode);@@ -391,7 +394,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it,return i ? ret : -ENODATA ; } -int erofs_getxattr (struct inode *inode,int index,const char *name, +static int erofs_getxattr (struct inode *inode,int index,const char *name,void *buffer,size_t buffer_size) {int ret;
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 585
Quoted 6 lines
fs/erofs/xattr.c +3
-0@@ -577,3 +580,38 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu)return acl; }#endif + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp(struct inode *inode,
why return struct erofs_inode_fingerprint instead of:
int erofs_xattr_get_ishare_fp(struct erofs_inode_fingerprint *fp,
struct inode *inode, const char *domain_id)
instead?
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 595
Quoted 10 lines
fs/erofs/xattr.c +10
-0+ const char *domain_id) +{ +struct erofs_sb_info *sbi =EROFS_SB (inode->i_sb); +struct erofs_inode_fingerprint fp = {}; +struct erofs_xattr_prefix_item *prefix; +const char *infix; +int valuelen, base_index, domainlen; + +if (!erofs_sb_has_ishare_xattrs (sbi)) + goto out;
Just use return 0; instead?
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 601
Quoted 6 lines
fs/erofs/xattr.c +6
-0+ prefix = sbi->xattr_prefixes + sbi->ishare_xattr_pfx; + infix = prefix->prefix->infix; + base_index = prefix->prefix->base_index; + valuelen =erofs_getxattr (inode, base_index, infix,NULL ,0 ); +if (valuelen <=0 || valuelen > (1 << sbi->blkszbits)) + goto out;
return -EFSCORRUPTED here.
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 605
Quoted 4 lines
fs/erofs/xattr.c +4
-0+ domainlen = domain_id ?strlen (domain_id) :0 ; + fp.opaque =kmalloc (valuelen + domainlen,GFP_KERNEL ); +if (!fp.opaque) + goto out;
return -ENOMEM; here.
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 610
Quoted 5 lines
fs/erofs/xattr.c +5
-0+if (valuelen !=erofs_getxattr (inode, base_index, infix, + fp.opaque, valuelen)) { +kfree (fp.opaque); + fp.opaque =NULL ; + goto out;
return -EFSCORRUPTED;
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 615
Quoted 5 lines
fs/erofs/xattr.c +5
-0+ } +memcpy (fp.opaque + valuelen, domain_id, domainlen); + fp.size = valuelen + domainlen; +out: +return fp;
return 0;
Quoted 11 lines
fs/erofs/xattr.c +2
-0+} +#endif fs/erofs/xattr.h +0
-1@@ -45,17 +45,10 @@ extern const struct xattr_handler * const erofs_xattr_handlers[];int erofs_xattr_prefixes_init (struct super_block *sb);void erofs_xattr_prefixes_cleanup (struct super_block *sb); -int erofs_getxattr (struct inode *,int ,const char *,void *,size_t );
fs/erofs/xattr.h extern const struct xattr_handler * const erofs_xattr_handlers[]; · line 58
Quoted 10 lines
fs/erofs/xattr.h +0
-6ssize_t erofs_listxattr (struct dentry *,char *,size_t );#else static inline int erofs_xattr_prefixes_init (struct super_block *sb) {return 0 ; }static inline void erofs_xattr_prefixes_cleanup (struct super_block *sb) {} -static inline int erofs_getxattr (struct inode *inode,int index, -const char *name,void *buffer, -size_t buffer_size) -{ -return -EOPNOTSUPP ; -}
As I said earlier, I will clean this part in a seperate patch.
fs/erofs/xattr.h struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu); · line 63
Quoted 8 lines
fs/erofs/xattr.h +1
-0#define erofs_listxattr (NULL)#define erofs_xattr_handlers (NULL)@@ -67,4 +60,9 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu);#define erofs_get_acl (NULL)#endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE
No need to wrap it with a #ifdef.
Thanks,
Gao Xiang
Quoted 5 lines
fs/erofs/xattr.h +4
-0+struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp (struct inode *inode, +const char *domain_id); +#endif +#endif
Re: [PATCH v11 07/10] erofs: introduce the page cache share feature
Hi, Xiang
Quoted 514 lines · Gao Xiang
Quoted 40 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
Currently, reading files with different paths (or names) but the same content will consume multiple copies of the page cache, even if the content of these page caches is the same. For example, reading identical files (e.g., *.so files) from two different minor versions of container images will cost multiple copies of the same page cache, since different containers have different mount points. Therefore, sharing the page cache for files with the same content can save memory.
This introduces the page cache share feature in erofs. It allocate a deduplicated inode and use its page cache as shared. Reads for files with identical content will ultimately be routed to the page cache of the deduplicated inode. In this way, a single page cache satisfies multiple read requests for different files with the same contents.
We introduce
inode_sharemount option to enable the page sharing mode during mounting.Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>---
Documentation/filesystems/erofs.rst| 4 + fs/erofs/Makefile | 1 + fs/erofs/internal.h | 31 +++++ fs/erofs/ishare.c | 171 ++++++++++++++++++++++++++++fs/erofs/super.c | 52 ++++++++- fs/erofs/xattr.c | 40 ++++++- fs/erofs/xattr.h | 12 +- 7 files changed, 300 insertions(+), 11 deletions(-)create mode 100644
fs/erofs/ishare.cDocumentation/filesystems/erofs.rst +0
-0@@ -128,7 +128,11 @@ device=%s Specify a path to an extradevice to be used together.
fsid=%s Specify a filesystem image ID for Fscache back-end. domain_id=%s Specify a domain ID in fscache mode so that different imagesQuoted 8 lines
with the same blobs under a given domain ID can share storage. + Also used for inode page sharing mode which defines a sharing
+ domain.
fsoffset=%llu Specify block-aligned filesystem offset for the primary device. +inode_share Enable inode page sharing mode. Files with the same content
+ can reuse page cache under the samedomain_id.Enable inode page sharing for this filesystem. Inodes with identical content within the same domain ID can share the page cache.
Quoted 37 lines
=================== =========================================================
Sysfs Entriesfs/erofs/Makefile +0
-0@@ -10,3 +10,4 @@ erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) +=decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_ZIP_ACCEL) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
fs/erofs/Makefile +1
-0+erofs-$(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) += ishare.ofs/erofs/internal.h +8
-0@@ -179,6 +179,7 @@ struct erofs_sb_info { #define EROFS_MOUNT_DAX_ALWAYS 0x00000040 #define EROFS_MOUNT_DAX_NEVER 0x00000080 #define EROFS_MOUNT_DIRECT_IO 0x00000100 +#define EROFS_MOUNT_INODE_SHARE 0x00000200 #define clear_opt(opt, option) ((opt)->mount_opt &= ~EROFS_MOUNT_##option) #define set_opt(opt, option) ((opt)->mount_opt |= EROFS_MOUNT_##option)@@ -269,6 +270,13 @@ static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid) /* default readahead size of directories */ #define EROFS_DIR_RA_BYTES 16384 +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint { + u8 *opaque; + int size; +}; +#endif + struct erofs_inode { erofs_nid_t nid;fs/erofs/internal.h struct erofs_inode { · line 317
Quoted 6 lines
fs/erofs/internal.h +3
-0@@ -304,6 +312,16 @@ struct erofs_inode { }; #endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + struct list_head ishare_list; + union {/* for each anon shared inode */
fs/erofs/internal.h struct erofs_inode { · line 321
Quoted 4 lines
fs/erofs/internal.h +4
-0+ struct { + struct erofs_inode_fingerprint fingerprint; + spinlock_t ishare_lock; + };/* for each real inode */
fs/erofs/internal.h struct erofs_inode { · line 322
Quoted 1 line
fs/erofs/internal.h +1
-0+ struct inode *realinode;Sorry, I think this variable indicates the anon inode instead of some real inode, so it should be called
struct inode *sharedinode;
Quoted 64 lines
fs/erofs/internal.h +15
-0+ }; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; };@@ -410,6 +428,7 @@ extern const struct inode_operations erofs_dir_iops; extern const struct file_operations erofs_file_fops; extern const struct file_operations erofs_dir_fops; +extern const struct file_operations erofs_ishare_fops; extern const struct iomap_ops z_erofs_iomap_report_ops;@@ -541,6 +560,18 @@ static inline struct bio *erofs_fscache_bio_alloc(struct erofs_map_dev *mdev) { static inline void erofs_fscache_submit_bio(struct bio *bio) {} #endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +int __init erofs_init_ishare (void ); +void erofs_exit_ishare (void ); +bool erofs_ishare_fill_inode (struct inode *inode); +void erofs_ishare_free_inode (struct inode *inode); +#else +static inline int erofs_init_ishare (void ) {return 0 ; } +static inline void erofs_exit_ishare (void ) {} +static inline bool erofs_ishare_fill_inode (struct inode *inode) {return false; } +static inline void erofs_ishare_free_inode (struct inode *inode) {} +#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE + long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long erofs_compat_ioctl(struct file *filp, unsigned int cmd,unsigned long arg);
fs/erofs/ishare.c new file +28
-0@@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#include <linux/xxhash.h> +#include <linux/mount.h> +#include "internal.h" +#include "xattr.h" + +#include "../internal.h" + +static struct vfsmount *erofs_ishare_mnt; + +static int erofs_ishare_iget5_eq (struct inode *inode,void *data) +{ + struct erofs_inode_fingerprint *fp1 = &EROFS_I(inode)->fingerprint; + struct erofs_inode_fingerprint *fp2 = data; + + return fp1->size == fp2->size && + !memcmp(fp1->opaque, fp2->opaque, fp2->size); +} + +static int erofs_ishare_iget5_set (struct inode *inode,void *data) +{ + struct erofs_inode *vi = EROFS_I(inode); + + vi->fingerprint = *(struct erofs_inode_fingerprint *)data; + INIT_LIST_HEAD(&vi->ishare_list);fs/erofs/ishare.c line 38
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+ spin_lock_init(&vi->ishare_lock); + return 0; +} + +bool erofs_ishare_fill_inode (struct inode *inode) +{ + struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); + struct erofs_inode *vi = EROFS_I(inode); + struct erofs_inode_fingerprint fp; + struct inode *idedup;maybe just aligned with the term above
struct inode *sharedinode;
Quoted 7 lines
fs/erofs/ishare.c new file +7
-0+ unsigned long hash; + + if (!test_opt(&sbi->opt, INODE_SHARE)) + return false; + fp = erofs_xattr_get_ishare_fp(inode, sbi->domain_id); + if (!fp.size) + return false;fs/erofs/ishare.c line 55
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+ hash = xxh32(fp.opaque, fp.size, 0); + idedup = iget5_locked(erofs_ishare_mnt->mnt_sb, hash, + erofs_ishare_iget5_eq, erofs_ishare_iget5_set, + &fp); + if (!idedup) { + kfree(fp.opaque); + return false; + } + + INIT_LIST_HEAD(&vi->ishare_list);I think we could move this line after the following if block and just before
spin_lock.Quoted 16 lines
fs/erofs/ishare.c new file +13
-0+ vi->realinode = idedup; + if (inode_state_read_once(idedup) & I_NEW) { + if (erofs_inode_is_data_compressed(vi->datalayout)) + idedup->i_mapping->a_ops = &z_erofs_aops; + else + idedup->i_mapping->a_ops = &erofs_aops; + idedup->i_mode = vi->vfs_inode.i_mode; + idedup->i_size = vi->vfs_inode.i_size; + unlock_new_inode(idedup); + } else { + kfree(fp.opaque); + } + spin_lock(&EROFS_I(idedup)->ishare_lock);> +
list_add(&vi->ishare_list, &EROFS_I(idedup)->ishare_list); + spin_unlock(&EROFS_I(idedup)->ishare_lock); + return true;fs/erofs/ishare.c line 77
Quoted 6 lines
fs/erofs/ishare.c new file +6
-0+} + +void erofs_ishare_free_inode (struct inode *inode) +{ + struct erofs_inode *vi = EROFS_I(inode); + struct inode *idedup = vi->realinode;struct inode *sharedinode =
vi->sharedinode;Quoted 11 lines
fs/erofs/ishare.c new file +11
-0+ + if (!idedup) + return; + spin_lock(&EROFS_I(idedup)->ishare_lock); + list_del(&vi->ishare_list); + spin_unlock(&EROFS_I(idedup)->ishare_lock); + iput(idedup); + vi->realinode = NULL; +} + +static int erofs_ishare_file_open(struct inode *inode, struct fileQuoted 4 lines
*file)
+{
+ struct file *realfile;
+ struct inode *dedup;same here, sharedinode;
Quoted 32 lines
+
+ dedup = EROFS_I(inode)->realinode;
+ realfile =alloc_empty_backing_file(O_RDONLY|O_NOATIME, current_cred());
+ if (IS_ERR(realfile))
+ returnPTR_ERR(realfile);
+ ihold(dedup);
+realfile->f_op=&erofs_file_fops;
+realfile->f_inode= dedup;
+realfile->f_mapping=dedup->i_mapping;
+path_get(&file->f_path);
+backing_file_set_user_path(realfile, &file->f_path);fs/erofs/ishare.c new file +8
-0+ + file_ra_state_init(&realfile->f_ra, file->f_mapping); + realfile->private_data = EROFS_I(inode); + file->private_data = realfile; + return 0; +} + +static int erofs_ishare_file_release(struct inode *inode, struct file*file)
fs/erofs/ishare.c new file +11
-0+{ + struct file *realfile = file->private_data; + + iput(realfile->f_inode); + fput(realfile); + file->private_data = NULL; + return 0; +} + +static ssize_t erofs_ishare_file_read_iter (struct kiocb *iocb, + struct iov_iter *to)fs/erofs/ishare.c line 131
Quoted 10 lines
fs/erofs/ishare.c new file +10
-0+{ + struct file *realfile = iocb->ki_filp->private_data; + struct inode *inode = file_inode(iocb->ki_filp); + struct kiocb dedup_iocb; + ssize_t nread; + + if (!iov_iter_count(to)) + return 0; + + /* fallback to the original file in DAX or DIRECT mode */I think we should just disallow FSDAX if
inode_shareis on.Quoted 175 lines
+ if (
IS_DAX(inode)|| (iocb->ki_flags&IOCB_DIRECT)) + realfile =iocb->ki_filp;fs/erofs/ishare.c new file +9
-0+ + kiocb_clone(&dedup_iocb, iocb, realfile); + nread = filemap_read(&dedup_iocb, to, 0); + iocb->ki_pos = dedup_iocb.ki_pos; + file_accessed(iocb->ki_filp); + return nread; +} + +static int erofs_ishare_mmap(struct file *file, struct vm_area_struct*vma)
fs/erofs/ishare.c new file +29
-0+{ + struct file *realfile = file->private_data; + + vma_set_file(vma, realfile); + return generic_file_readonly_mmap(file, vma); +} + +const struct file_operations erofs_ishare_fops = { + .open = erofs_ishare_file_open, + .llseek = generic_file_llseek, + .read_iter = erofs_ishare_file_read_iter, + .mmap = erofs_ishare_mmap, + .release = erofs_ishare_file_release, + .get_unmapped_area = thp_get_unmapped_area, + .splice_read = filemap_splice_read, +}; + +int __init erofs_init_ishare (void ) +{ + erofs_ishare_mnt = kern_mount(&erofs_anon_fs_type); + if (IS_ERR(erofs_ishare_mnt)) + return PTR_ERR(erofs_ishare_mnt); + return 0; +} + +void erofs_exit_ishare (void ) +{ + kern_unmount(erofs_ishare_mnt); +}fs/erofs/super.c +2
-0@@ -390,6 +390,7 @@ static void erofs_default_options(struct erofs_sb_info *sbi) enum { Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum, Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_fsoffset, + Opt_inode_share, }; static const struct constant_table erofs_param_cache_strategy[] = {@@ -417,6 +418,7 @@ static const struct fs_parameter_spec erofs_fs_parameters[] = { fsparam_string("domain_id", Opt_domain_id), fsparam_flag_no("directio", Opt_directio), fsparam_u64("fsoffset", Opt_fsoffset), + fsparam_flag("inode_share", Opt_inode_share), {} };@@ -545,6 +547,14 @@ static int erofs_fc_parse_param(struct fs_context *fc,case
Opt_fsoffset:
sbi->dif0.fsoff= result.uint_64;
break;fs/erofs/super.c +6
-0+#if defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE ) + case Opt_inode_share: + set_opt(&sbi->opt, INODE_SHARE); +#else + case Opt_inode_share: + errorfc(fc, "%s option not supported",erofs_fs_parameters[opt].name);
+#endif
+ break;
}
return 0;
}fs/erofs/super.c +6
-0@@ -643,6 +653,12 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_op = &erofs_sops; + if (sbi->domain_id && + (!sbi->fsid && !test_opt(&sbi->opt, INODE_SHARE))) { + errorfc(fc, "domain_id should be with fsid or inode_share option"); + return -EINVAL; + } + sbi->blkszbits = PAGE_SHIFT; if (!sb->s_bdev) {/*
fs/erofs/super.c +27
-3@@ -942,14 +958,34 @@ static struct file_system_type erofs_fs_type = { }; MODULE_ALIAS_FS("erofs"); -#if defined(CONFIG_EROFS_FS_ONDEMAND ) +#if defined(CONFIG_EROFS_FS_ONDEMAND ) || defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE ) +static void erofs_free_anon_inode (struct inode *inode) +{ + struct erofs_inode *vi = EROFS_I(inode); + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + kfree(vi->fingerprint.opaque); +#endif + kmem_cache_free(erofs_inode_cachep, vi); +} + +static const struct super_operations erofs_anon_sops = { + .alloc_inode = erofs_alloc_inode, + .free_inode = erofs_free_anon_inode, +}; + static int erofs_anon_init_fs_context(struct fs_context *fc) { - return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; + struct pseudo_fs_context *ctx; + + ctx = init_pseudo(fc, EROFS_SUPER_MAGIC); + if (ctx) + ctx->ops = &erofs_anon_sops; + + return ctx ? 0 : -ENOMEM; } struct file_system_type erofs_anon_fs_type = { - .owner = THIS_MODULE, .name = "pseudo_erofs", .init_fs_context = erofs_anon_init_fs_context, .kill_sb = kill_anon_super,@@ -981,6 +1017,10 @@ static int __init erofs_module_init(void) if (err) goto sysfs_err; + err = erofs_init_ishare(); + if (err) + goto ishare_err; + err = register_filesystem(&erofs_fs_type); if (err) goto fs_err;@@ -988,6 +1028,8 @@ static int __init erofs_module_init(void) return 0;
fs_err:
+erofs_exit_ishare();
+ishare_err:
erofs_exit_sysfs();
sysfs_err:
z_erofs_exit_subsystem();fs/erofs/super.c +4
-0@@ -1005,6 +1047,7 @@ static void __exit erofs_module_exit(void) /* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ rcu_barrier(); + erofs_exit_ishare(); erofs_exit_sysfs(); z_erofs_exit_subsystem(); erofs_exit_shrinker();@@ -1057,6 +1100,8 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root) seq_printf(seq, ",domain_id=%s", sbi->domain_id); if (sbi->dif0.fsoff) seq_printf(seq, ",fsoffset=%llu", sbi->dif0.fsoff); + if (test_opt(opt, INODE_SHARE)) + seq_puts(seq, ",inode_share"); return 0; }@@ -1067,6 +1112,7 @@ static void erofs_evict_inode(struct inode *inode) dax_break_layout_final(inode); #endif + erofs_ishare_free_inode(inode); truncate_inode_pages_final(&inode->i_data); clear_inode(inode); }fs/erofs/xattr.c +0
-0fs/erofs/xattr.c struct erofs_xattr_iter { · line 29
Quoted 5 lines
fs/erofs/xattr.c +2
-0@@ -25,6 +25,9 @@ struct erofs_xattr_iter { struct dentry *dentry; }; +static int erofs_getxattr (struct inode *inode,int index,const char *name, + void *buffer, size_t buffer_size);could we clean it up in a seperate patch? It can be an independent patch against this series.
Quoted 22 lines
fs/erofs/xattr.c +2
-1+ static int erofs_init_inode_xattrs(struct inode *inode) { struct erofs_inode *const vi = EROFS_I(inode);@@ -391,7 +394,7 @@ static int erofs_xattr_iter_shared(struct erofs_xattr_iter *it, return i ? ret : -ENODATA; } -int erofs_getxattr (struct inode *inode,int index,const char *name, +static int erofs_getxattr (struct inode *inode,int index,const char *name, void *buffer, size_t buffer_size) {int ret;
fs/erofs/xattr.c +0
-0@@ -577,3 +580,38 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) return acl; }#endif
fs/erofs/xattr.c +3
-0+ +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp(struct inodeQuoted 1 line
*inode,
why return
struct erofs_inode_fingerprintinstead of:
Quoted 5 lines
int erofs_xattr_get_ishare_fp(struct
erofs_inode_fingerprint*fp,
struct inode *inode, const char*domain_id)instead?
How about declaring this as void erofs_xattr_fill_ishare_fp(struct erofs_inode_fingerprint *fp, struct inode *inode, const char *domain_id)? Because the return value seems useless.
Thanks,
Hongbo
Quoted 90 lines
fs/erofs/xattr.c struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu) · line 595
Quoted 10 lines
+ const char
*domain_id)fs/erofs/xattr.c +9
-0+{ + struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); + struct erofs_inode_fingerprint fp = {}; + struct erofs_xattr_prefix_item *prefix; + const char *infix; + int valuelen, base_index, domainlen; + + if (!erofs_sb_has_ishare_xattrs(sbi)) + goto out;Just use return 0; instead?
Quoted 6 lines
+ prefix =
sbi->xattr_prefixes+sbi->ishare_xattr_pfx; + infix =prefix->prefix->infix;
+base_index=prefix->prefix->base_index;
+ valuelen =erofs_getxattr(inode, base_index, infix, NULL, 0); + if (valuelen <= 0 || valuelen > (1 <<sbi->blkszbits)) + goto out;
return -EFSCORRUPTEDhere.Quoted 4 lines
+ domainlen =
domain_id?strlen(domain_id): 0; + fp.opaque =kmalloc(valuelen + domainlen, GFP_KERNEL); + if (!fp.opaque)
+ goto out;
return -ENOMEM;here.Quoted 5 lines
+ if (valuelen !=
erofs_getxattr(inode, base_index, infix, + fp.opaque, valuelen)) {
+ kfree(fp.opaque);
+ fp.opaque = NULL;
+ goto out;return
-EFSCORRUPTED;Quoted 5 lines
+ }
+memcpy(fp.opaque + valuelen, domain_id, domainlen); + fp.size = valuelen + domainlen;
+out:
+ return fp;return 0;
Quoted 11 lines
fs/erofs/xattr.c +2
-0+} +#endif fs/erofs/xattr.h +0
-1@@ -45,17 +45,10 @@ extern const struct xattr_handler * const erofs_xattr_handlers[]; int erofs_xattr_prefixes_init(struct super_block *sb); void erofs_xattr_prefixes_cleanup(struct super_block *sb); -int erofs_getxattr (struct inode *,int ,const char *,void *,size_t );fs/erofs/xattr.h extern const struct xattr_handler * const · line 58
Quoted 10 lines
fs/erofs/xattr.h +0
-6ssize_t erofs_listxattr(struct dentry *, char *, size_t); #else static inline int erofs_xattr_prefixes_init(struct super_block *sb) { return 0; } static inline void erofs_xattr_prefixes_cleanup(struct super_block *sb) {} -static inline int erofs_getxattr (struct inode *inode,int index, - const char *name, void *buffer, - size_t buffer_size) -{ - return -EOPNOTSUPP; -}As I said earlier, I will clean this part in a seperate patch.
fs/erofs/xattr.h struct posix_acl *erofs_get_acl(struct inode *inode, · line 63
Quoted 7 lines
fs/erofs/xattr.h +1
-0#define erofs_listxattr (NULL) #define erofs_xattr_handlers (NULL)@@ -67,4 +60,9 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int type, bool rcu); #define erofs_get_acl (NULL) #endif +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE No need to wrap it with a
#ifdef.Thanks,
Gao XiangQuoted 6 lines
fs/erofs/xattr.h +4
-0+struct erofs_inode_fingerprint erofs_xattr_get_ishare_fp (struct inode *inode, + const char *domain_id); +#endif +#endif
Re: [PATCH v11 07/10] erofs: introduce the page cache share feature
Quoted 4 lines · Hongbo Li
Hi, Xiang
Quoted 1 line · Gao Xiang
...
Quoted 10 lines
Quoted 8 lines
why return
struct erofs_inode_fingerprintinstead of:int
erofs_xattr_get_ishare_fp(struct erofs_inode_fingerprint *fp, struct inode *inode, const char *domain_id)instead?
How about declaring this as void
erofs_xattr_fill_ishare_fp(struct erofs_inode_fingerprint *fp, struct inode *inode, const char *domain_id)? Because the return value seems useless.
I still perfer to return different values for this helper even the final user doesn't use this.
Thanks,
Gao Xiang
Quoted 3 lines
Thanks,
Hongbo
PATCH v11 8/10 erofs: support unencoded inodes for page cache share
In reply to Hongbo LiThis patch adds inode page cache sharing functionality for unencoded files.
I conducted experiments in the container environment. Below is the memory usage for reading all files in two different minor versions of container images:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 241 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 163 | 33% | +-------------------+------------------+-------------+---------------+ | | No | 872 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 630 | 28% | +-------------------+------------------+-------------+---------------+ | | No | 2771 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 2340 | 16% | +-------------------+------------------+-------------+---------------+ | | No | 926 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 735 | 21% | +-------------------+------------------+-------------+---------------+ | | No | 390 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 219 | 44% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 924 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 474 | 49% | +-------------------+------------------+-------------+---------------+
Additionally, the table below shows the runtime memory usage of the container:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 35 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 28 | 20% | +-------------------+------------------+-------------+---------------+ | | No | 149 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 95 | 37% | +-------------------+------------------+-------------+---------------+ | | No | 1028 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 930 | 10% | +-------------------+------------------+-------------+---------------+ | | No | 155 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 132 | 15% | +-------------------+------------------+-------------+---------------+ | | No | 25 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 20 | 20% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 186 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 98 | 48% | +-------------------+------------------+-------------+---------------+
--- fs/erofs/data.c | 32 +++++++++++++++++++++++++------- fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 2 ++ fs/erofs/ishare.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-)
fs/erofs/data.c +25 -7
@@ -269,6 +269,7 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)struct erofs_iomap_iter_ctx {struct page *page;void *base; +struct inode *realinode; }; static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
@@ -276,14 +277,15 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, { struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);struct erofs_iomap_iter_ctx *ctx = iter->private; -struct super_block *sb = inode->i_sb; +struct inode *realinode = ctx ? ctx->realinode : inode; +struct super_block *sb = realinode->i_sb;struct erofs_map_blocks map;struct erofs_map_dev mdev;int ret; map.m_la = offset; map.m_llen = length; - ret =erofs_map_blocks (inode, &map); + ret =erofs_map_blocks (realinode, &map);if (ret <0 )return ret;
@@ -296,7 +298,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,return 0 ; } -if (!(map.m_flags &EROFS_MAP_META ) || !erofs_inode_in_metabox (inode)) { +if (!(map.m_flags &EROFS_MAP_META ) || !erofs_inode_in_metabox (realinode)) { mdev = (struct erofs_map_dev ) { .m_deviceid = map.m_deviceid, .m_pa = map.m_pa,
@@ -322,7 +324,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,void *ptr; ptr =erofs_read_metabuf (&buf, sb, map.m_pa, -erofs_inode_in_metabox (inode)); +erofs_inode_in_metabox (realinode));if (IS_ERR (ptr))return PTR_ERR (ptr); iomap->inline_data = ptr;
@@ -379,30 +381,44 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,*/ static int erofs_read_folio (struct file *file,struct folio *folio) { +struct inode *inode =folio_inode (folio);struct iomap_read_folio_ctx read_ctx = { .ops = &iomap_bio_read_ops, .cur_folio = folio, }; -struct erofs_iomap_iter_ctx iter_ctx = {}; +bool need_iput = false; +struct erofs_iomap_iter_ctx iter_ctx = { + .realinode =erofs_real_inode (inode, &need_iput), + }; +DBG_BUGON (!iter_ctx.realinode);trace_erofs_read_folio (folio, true);iomap_read_folio (&erofs_iomap_ops, &read_ctx, &iter_ctx); +if (need_iput) +iput (iter_ctx.realinode);return 0 ; }static void erofs_readahead (struct readahead_control *rac) { +struct inode *inode = rac->mapping->host;struct iomap_read_folio_ctx read_ctx = { .ops = &iomap_bio_read_ops, .rac = rac, }; -struct erofs_iomap_iter_ctx iter_ctx = {}; +bool need_iput = false; +struct erofs_iomap_iter_ctx iter_ctx = { + .realinode =erofs_real_inode (inode, &need_iput), + }; +DBG_BUGON (!iter_ctx.realinode);trace_erofs_readahead (rac->mapping->host,readahead_index (rac),readahead_count (rac), true);iomap_readahead (&erofs_iomap_ops, &read_ctx, &iter_ctx); +if (need_iput) +iput (iter_ctx.realinode); }static sector_t erofs_bmap (struct address_space *mapping,sector_t block)
@@ -423,7 +439,9 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return dax_iomap_rw (iocb, to, &erofs_iomap_ops);#endif if ((iocb->ki_flags &IOCB_DIRECT ) && inode->i_sb->s_bdev) { -struct erofs_iomap_iter_ctx iter_ctx = {}; +struct erofs_iomap_iter_ctx iter_ctx = { + .realinode = inode, + };return iomap_dio_rw (iocb, to, &erofs_iomap_ops,NULL ,0 , &iter_ctx,0 );
fs/erofs/inode.c +4 -0
@@ -215,6 +215,10 @@ static int erofs_fill_inode(struct inode *inode)case S_IFREG : inode->i_op = &erofs_generic_iops; inode->i_fop = &erofs_file_fops; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +if (erofs_ishare_fill_inode (inode)) + inode->i_fop = &erofs_ishare_fops; +#endif break ;case S_IFDIR : inode->i_op = &erofs_dir_iops;
fs/erofs/internal.h +2 -0
@@ -565,11 +565,13 @@ int __init erofs_init_ishare(void);void erofs_exit_ishare (void );bool erofs_ishare_fill_inode (struct inode *inode);void erofs_ishare_free_inode (struct inode *inode); +struct inode *erofs_real_inode (struct inode *inode,bool *need_iput);#else static inline int erofs_init_ishare (void ) {return 0 ; }static inline void erofs_exit_ishare (void ) {}static inline bool erofs_ishare_fill_inode (struct inode *inode) {return false; }static inline void erofs_ishare_free_inode (struct inode *inode) {} +static inline struct inode *erofs_real_inode (struct inode *inode,bool *need_iput) {return inode; }#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);
fs/erofs/ishare.c +31 -0
@@ -11,6 +11,12 @@static struct vfsmount *erofs_ishare_mnt; +static inline bool erofs_is_ishare_inode (struct inode *inode) +{ +/* assumed FS_ONDEMAND is excluded with FS_PAGE_CACHE_SHARE feature */ +return inode->i_sb->s_type == &erofs_anon_fs_type; +} +static int erofs_ishare_iget5_eq (struct inode *inode,void *data) {struct erofs_inode_fingerprint *fp1 = &EROFS_I (inode)->fingerprint;
@@ -157,6 +163,31 @@ const struct file_operations erofs_ishare_fops = { .splice_read = filemap_splice_read, }; +struct inode *erofs_real_inode (struct inode *inode,bool *need_iput) +{ +struct erofs_inode *vi, *vi_dedup; +struct inode *realinode; + +if (!erofs_is_ishare_inode (inode)) +return inode; + + vi_dedup =EROFS_I (inode); +spin_lock (&vi_dedup->ishare_lock); +/* fetch any one as real inode */ +DBG_BUGON (list_empty (&vi_dedup->ishare_list)); +list_for_each_entry (vi, &vi_dedup->ishare_list, ishare_list) { + realinode =igrab (&vi->vfs_inode); +if (realinode) { + *need_iput = true; +break ; + } + } +spin_unlock (&vi_dedup->ishare_lock); + +DBG_BUGON (!realinode); +return realinode; +} +int __init erofs_init_ishare (void ) { erofs_ishare_mnt =kern_mount (&erofs_anon_fs_type);
Signature · 1 line
2.22.0
Re: [PATCH v11 08/10] erofs: support unencoded inodes for page cache share
Quoted 127 lines · Hongbo Li
This patch adds inode page cache sharing functionality for unencoded files.
I conducted experiments in the container environment. Below is the memory usage for reading all files in two different minor versions of container images:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 241 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 163 | 33% | +-------------------+------------------+-------------+---------------+ | | No | 872 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 630 | 28% | +-------------------+------------------+-------------+---------------+ | | No | 2771 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 2340 | 16% | +-------------------+------------------+-------------+---------------+ | | No | 926 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 735 | 21% | +-------------------+------------------+-------------+---------------+ | | No | 390 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 219 | 44% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 924 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 474 | 49% | +-------------------+------------------+-------------+---------------+Additionally, the table below shows the runtime memory usage of the container:
+-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 35 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 28 | 20% | +-------------------+------------------+-------------+---------------+ | | No | 149 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 95 | 37% | +-------------------+------------------+-------------+---------------+ | | No | 1028 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 930 | 10% | +-------------------+------------------+-------------+---------------+ | | No | 155 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 132 | 15% | +-------------------+------------------+-------------+---------------+ | | No | 25 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 20 | 20% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 186 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 98 | 48% | +-------------------+------------------+-------------+---------------+Co-developed-by Hongzhen Luo <[email protected]>Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>--- fs/erofs/data.c | 32 +++++++++++++++++++++++++------- fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 2 ++ fs/erofs/ishare.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-)fs/erofs/data.c +6
-4@@ -269,6 +269,7 @@ void erofs_onlinefolio_end(struct folio *folio, int err, bool dirty)struct erofs_iomap_iter_ctx {struct page *page;void *base; +struct inode *realinode; }; static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,@@ -276,14 +277,15 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, { struct iomap_iter *iter = container_of(iomap, struct iomap_iter, iomap);struct erofs_iomap_iter_ctx *ctx = iter->private; -struct super_block *sb = inode->i_sb; +struct inode *realinode = ctx ? ctx->realinode : inode; +struct super_block *sb = realinode->i_sb;struct erofs_map_blocks map;struct erofs_map_dev mdev;int ret; map.m_la = offset; map.m_llen = length; - ret =erofs_map_blocks (inode, &map); + ret =erofs_map_blocks (realinode, &map);if (ret <0 )return ret;@@ -296,7 +298,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,return 0 ; } -if (!(map.m_flags &EROFS_MAP_META ) || !erofs_inode_in_metabox (inode)) { +if (!(map.m_flags &EROFS_MAP_META ) || !erofs_inode_in_metabox (realinode)) { mdev = (struct erofs_map_dev ) { .m_deviceid = map.m_deviceid, .m_pa = map.m_pa,@@ -322,7 +324,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,void *ptr; ptr =erofs_read_metabuf (&buf, sb, map.m_pa, -erofs_inode_in_metabox (inode)); +erofs_inode_in_metabox (realinode));if (IS_ERR (ptr))return PTR_ERR (ptr); iomap->inline_data = ptr;
fs/erofs/data.c int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 389
Quoted 10 lines
fs/erofs/data.c +2
-1@@ -379,30 +381,44 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,*/ static int erofs_read_folio (struct file *file,struct folio *folio) { +struct inode *inode =folio_inode (folio);struct iomap_read_folio_ctx read_ctx = { .ops = &iomap_bio_read_ops, .cur_folio = folio, }; -struct erofs_iomap_iter_ctx iter_ctx = {}; +bool need_iput = false;
bool need_iput is enough, see below.
fs/erofs/data.c int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 394
Quoted 4 lines
fs/erofs/data.c +3
-0+ struct erofs_iomap_iter_ctx iter_ctx = {> + .realinode = erofs_real_inode(inode, &need_iput), + }; +DBG_BUGON (!iter_ctx.realinode);
just remove this line, since erofs_real_inode() already has this check.
Quoted 7 lines
fs/erofs/data.c +2
-0trace_erofs_read_folio (folio, true);iomap_read_folio (&erofs_iomap_ops, &read_ctx, &iter_ctx); +if (need_iput) +iput (iter_ctx.realinode);return 0 ; }
fs/erofs/data.c int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 410
Quoted 10 lines
fs/erofs/data.c +2
-1static void erofs_readahead (struct readahead_control *rac) { +struct inode *inode = rac->mapping->host;struct iomap_read_folio_ctx read_ctx = { .ops = &iomap_bio_read_ops, .rac = rac, }; -struct erofs_iomap_iter_ctx iter_ctx = {}; +bool need_iput = false;
bool need_iput is enough, see below.
fs/erofs/data.c int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 394
Quoted 5 lines
fs/erofs/data.c +4
-0+struct erofs_iomap_iter_ctx iter_ctx = { + .realinode =erofs_real_inode (inode, &need_iput), + }; +DBG_BUGON (!iter_ctx.realinode);
just remove this line, since erofs_real_inode() already has this check.
Quoted 40 lines
fs/erofs/data.c +5
-1trace_erofs_readahead (rac->mapping->host,readahead_index (rac),readahead_count (rac), true);iomap_readahead (&erofs_iomap_ops, &read_ctx, &iter_ctx); +if (need_iput) +iput (iter_ctx.realinode); }static sector_t erofs_bmap (struct address_space *mapping,sector_t block)@@ -423,7 +439,9 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)return dax_iomap_rw (iocb, to, &erofs_iomap_ops);#endif if ((iocb->ki_flags &IOCB_DIRECT ) && inode->i_sb->s_bdev) { -struct erofs_iomap_iter_ctx iter_ctx = {}; +struct erofs_iomap_iter_ctx iter_ctx = { + .realinode = inode, + };return iomap_dio_rw (iocb, to, &erofs_iomap_ops,NULL ,0 , &iter_ctx,0 );fs/erofs/inode.c +4
-0@@ -215,6 +215,10 @@ static int erofs_fill_inode(struct inode *inode)case S_IFREG : inode->i_op = &erofs_generic_iops; inode->i_fop = &erofs_file_fops; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +if (erofs_ishare_fill_inode (inode)) + inode->i_fop = &erofs_ishare_fops; +#endif break ;case S_IFDIR : inode->i_op = &erofs_dir_iops;fs/erofs/internal.h +0
-0
fs/erofs/internal.h int __init erofs_init_ishare(void); · line 574
Quoted 10 lines
fs/erofs/internal.h +2
-0@@ -565,11 +565,13 @@ int __init erofs_init_ishare(void);void erofs_exit_ishare (void );bool erofs_ishare_fill_inode (struct inode *inode);void erofs_ishare_free_inode (struct inode *inode); +struct inode *erofs_real_inode (struct inode *inode,bool *need_iput);#else static inline int erofs_init_ishare (void ) {return 0 ; }static inline void erofs_exit_ishare (void ) {}static inline bool erofs_ishare_fill_inode (struct inode *inode) {return false; }static inline void erofs_ishare_free_inode (struct inode *inode) {} +static inline struct inode *erofs_real_inode (struct inode *inode,bool *need_iput) {return inode; }
static inline struct inode *erofs_real_inode(struct inode *inode, bool *need_iput)
{
*need_iput = false;
return inode;
}Quoted 21 lines
fs/erofs/internal.h +0
-0#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE long erofs_ioctl (struct file *filp,unsigned int cmd,unsigned long arg);fs/erofs/ishare.c +6
-0@@ -11,6 +11,12 @@static struct vfsmount *erofs_ishare_mnt; +static inline bool erofs_is_ishare_inode (struct inode *inode) +{ +/* assumed FS_ONDEMAND is excluded with FS_PAGE_CACHE_SHARE feature */ +return inode->i_sb->s_type == &erofs_anon_fs_type; +} +static int erofs_ishare_iget5_eq (struct inode *inode,void *data) {struct erofs_inode_fingerprint *fp1 = &EROFS_I (inode)->fingerprint;
fs/erofs/ishare.c const struct file_operations erofs_ishare_fops = { · line 169
Quoted 7 lines
fs/erofs/ishare.c +4
-0@@ -157,6 +163,31 @@ const struct file_operations erofs_ishare_fops = { .splice_read = filemap_splice_read, }; +struct inode *erofs_real_inode (struct inode *inode,bool *need_iput) +{ +struct erofs_inode *vi, *vi_dedup; +struct inode *realinode;
*need_iput = false;
here
Thanks,
Gao Xiang
Quoted 24 lines
fs/erofs/ishare.c +21
-0+ +if (!erofs_is_ishare_inode (inode)) +return inode; + + vi_dedup =EROFS_I (inode); +spin_lock (&vi_dedup->ishare_lock); +/* fetch any one as real inode */ +DBG_BUGON (list_empty (&vi_dedup->ishare_list)); +list_for_each_entry (vi, &vi_dedup->ishare_list, ishare_list) { + realinode =igrab (&vi->vfs_inode); +if (realinode) { + *need_iput = true; +break ; + } + } +spin_unlock (&vi_dedup->ishare_lock); + +DBG_BUGON (!realinode); +return realinode; +} +int __init erofs_init_ishare (void ) { erofs_ishare_mnt =kern_mount (&erofs_anon_fs_type);
PATCH v11 9/10 erofs: support compressed inodes for page cache share
In reply to Hongbo LiFrom: Hongzhen Luo <[email protected]>
This patch adds page cache sharing functionality for compressed inodes.
--- fs/erofs/zdata.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
fs/erofs/zdata.c +22 -8
@@ -493,7 +493,7 @@ enum z_erofs_pclustermode { };struct z_erofs_frontend { -struct inode *const inode; +struct inode *inode;struct erofs_map_blocks map;struct z_erofs_bvec_iter biter;
@@ -1884,9 +1884,13 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,static int z_erofs_read_folio (struct file *file,struct folio *folio) {struct inode *const inode = folio->mapping->host; -Z_EROFS_DEFINE_FRONTEND (f, inode,folio_pos (folio)); +bool need_iput = false; +struct inode *realinode =erofs_real_inode (inode, &need_iput); +Z_EROFS_DEFINE_FRONTEND (f,NULL ,folio_pos (folio));int err; +DBG_BUGON (!realinode); + f.inode = realinode;trace_erofs_read_folio (folio, false);z_erofs_pcluster_readmore (&f,NULL , true); err =z_erofs_scan_folio (&f, folio, false);
@@ -1896,23 +1900,30 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)/* if some pclusters are ready, need submit them anyway */ err =z_erofs_runqueue (&f,0 ) ?: err;if (err && err != -EINTR ) -erofs_err (inode->i_sb,"read error %d @ %lu of nid %llu" , - err, folio->index,EROFS_I (inode)->nid); +erofs_err (realinode->i_sb,"read error %d @ %lu of nid %llu" , + err, folio->index,EROFS_I (realinode)->nid);erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +if (need_iput) +iput (realinode);return err; }static void z_erofs_readahead (struct readahead_control *rac) {struct inode *const inode = rac->mapping->host; -Z_EROFS_DEFINE_FRONTEND (f, inode,readahead_pos (rac)); +bool need_iput; +struct inode *realinode =erofs_real_inode (inode, &need_iput); +Z_EROFS_DEFINE_FRONTEND (f,NULL ,readahead_pos (rac));unsigned int nrpages =readahead_count (rac);struct folio *head =NULL , *folio;int err; -trace_erofs_readahead (inode,readahead_index (rac), nrpages, false); +DBG_BUGON (!realinode); + f.inode = realinode; +trace_erofs_readahead (realinode,readahead_index (rac), nrpages, false);z_erofs_pcluster_readmore (&f, rac, true);while ((folio =readahead_folio (rac))) { folio->private = head;
@@ -1926,8 +1937,8 @@ static void z_erofs_readahead(struct readahead_control *rac) err =z_erofs_scan_folio (&f, folio, true);if (err && err != -EINTR ) -erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , - folio->index,EROFS_I (inode)->nid); +erofs_err (realinode->i_sb,"readahead error at folio %lu @ nid %llu" , + folio->index,EROFS_I (realinode)->nid); }z_erofs_pcluster_readmore (&f, rac, false);z_erofs_pcluster_end (&f);
@@ -1935,6 +1946,9 @@ static void z_erofs_readahead(struct readahead_control *rac) (void )z_erofs_runqueue (&f, nrpages);erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +if (need_iput) +iput (realinode); }const struct address_space_operations z_erofs_aops = {
Signature · 1 line
2.22.0
Re: [PATCH v11 09/10] erofs: support compressed inodes for page cache share
Quoted 24 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
This patch adds page cache sharing functionality for compressed inodes.
Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>--- fs/erofs/zdata.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)fs/erofs/zdata.c +1
-1@@ -493,7 +493,7 @@ enum z_erofs_pclustermode { };struct z_erofs_frontend { -struct inode *const inode; +struct inode *inode;struct erofs_map_blocks map;struct z_erofs_bvec_iter biter;
fs/erofs/zdata.c static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f, · line 1889
Quoted 7 lines
fs/erofs/zdata.c +3
-1@@ -1884,9 +1884,13 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,static int z_erofs_read_folio (struct file *file,struct folio *folio) {struct inode *const inode = folio->mapping->host; -Z_EROFS_DEFINE_FRONTEND (f, inode,folio_pos (folio)); +bool need_iput = false; +struct inode *realinode =erofs_real_inode (inode, &need_iput); +Z_EROFS_DEFINE_FRONTEND (f,NULL ,folio_pos (folio));
Why not just
Z_EROFS_DEFINE_FRONTEND(f, realinode, folio_pos(folio));
?
fs/erofs/zdata.c static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f, · line 1892
Quoted 3 lines
fs/erofs/zdata.c +1
-0int err; +DBG_BUGON (!realinode);
Remove this line
Quoted 18 lines
fs/erofs/zdata.c +6
-2+ f.inode = realinode;trace_erofs_read_folio (folio, false);z_erofs_pcluster_readmore (&f,NULL , true); err =z_erofs_scan_folio (&f, folio, false);@@ -1896,23 +1900,30 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)/* if some pclusters are ready, need submit them anyway */ err =z_erofs_runqueue (&f,0 ) ?: err;if (err && err != -EINTR ) -erofs_err (inode->i_sb,"read error %d @ %lu of nid %llu" , - err, folio->index,EROFS_I (inode)->nid); +erofs_err (realinode->i_sb,"read error %d @ %lu of nid %llu" , + err, folio->index,EROFS_I (realinode)->nid);erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +if (need_iput) +iput (realinode);
fs/erofs/zdata.c static int z_erofs_read_folio(struct file *file, struct folio *folio) · line 1919
Quoted 10 lines
fs/erofs/zdata.c +3
-1return err; }static void z_erofs_readahead (struct readahead_control *rac) {struct inode *const inode = rac->mapping->host; -Z_EROFS_DEFINE_FRONTEND (f, inode,readahead_pos (rac)); +bool need_iput; +struct inode *realinode =erofs_real_inode (inode, &need_iput); +Z_EROFS_DEFINE_FRONTEND (f,NULL ,readahead_pos (rac));
Why not just
Z_EROFS_DEFINE_FRONTEND(f, realinode, folio_pos(folio));
?
fs/erofs/zdata.c static int z_erofs_read_folio(struct file *file, struct folio *folio) · line 1924
Quoted 6 lines
fs/erofs/zdata.c +1
-1unsigned int nrpages =readahead_count (rac);struct folio *head =NULL , *folio;int err; -trace_erofs_readahead (inode,readahead_index (rac), nrpages, false); +DBG_BUGON (!realinode);
Remove this line.
Thanks,
Gao Xiang
Quoted 26 lines
fs/erofs/zdata.c +7
-2+ f.inode = realinode; +trace_erofs_readahead (realinode,readahead_index (rac), nrpages, false);z_erofs_pcluster_readmore (&f, rac, true);while ((folio =readahead_folio (rac))) { folio->private = head;@@ -1926,8 +1937,8 @@ static void z_erofs_readahead(struct readahead_control *rac) err =z_erofs_scan_folio (&f, folio, true);if (err && err != -EINTR ) -erofs_err (inode->i_sb,"readahead error at folio %lu @ nid %llu" , - folio->index,EROFS_I (inode)->nid); +erofs_err (realinode->i_sb,"readahead error at folio %lu @ nid %llu" , + folio->index,EROFS_I (realinode)->nid); }z_erofs_pcluster_readmore (&f, rac, false);z_erofs_pcluster_end (&f);@@ -1935,6 +1946,9 @@ static void z_erofs_readahead(struct readahead_control *rac) (void )z_erofs_runqueue (&f, nrpages);erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +if (need_iput) +iput (realinode); }const struct address_space_operations z_erofs_aops = {
PATCH v11 10/10 erofs: implement .fadvise for page cache share
In reply to Hongbo LiFrom: Hongzhen Luo <[email protected]>
This patch implements the .fadvise interface for page cache share. Similar to overlayfs, it drops those clean, unused pages through vfs_fadvise().
--- fs/erofs/ishare.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/erofs/ishare.c +8 -0
@@ -153,6 +153,13 @@ static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma)return generic_file_readonly_mmap (file, vma); } +static int erofs_ishare_fadvise (struct file *file,loff_t offset, +loff_t len,int advice) +{ +return vfs_fadvise ((struct file *)file->private_data, + offset, len, advice); +} +const struct file_operations erofs_ishare_fops = { .open = erofs_ishare_file_open, .llseek = generic_file_llseek,
@@ -161,6 +168,7 @@ const struct file_operations erofs_ishare_fops = { .release = erofs_ishare_file_release, .get_unmapped_area = thp_get_unmapped_area, .splice_read = filemap_splice_read, + .fadvise = erofs_ishare_fadvise, };struct inode *erofs_real_inode (struct inode *inode,bool *need_iput)
Signature · 1 line
2.22.0
Re: [PATCH v11 10/10] erofs: implement .fadvise for page cache share
Quoted 8 lines · Hongbo Li
From: Hongzhen Luo <[email protected]>
This patch implements the .fadvise interface for page cache share. Similar to overlayfs, it drops those clean, unused pages through
vfs_fadvise().Signed-off-by Hongzhen Luo <[email protected]>Signed-off-by Hongbo Li <[email protected]>
Thanks,
Gao Xiang