erofs: introduce page cache share feature
v4 cover erofs: introduce page cache share feature
v4:
Changes since v3:
- Implemented .fadvise
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
[Background]
================
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.
[Implementation]
================
This introduces the page cache share feature in erofs. During the mkfs phase, the file content is hashed and the hash value is stored in the trusted.erofs.fingerprint extended attribute. Inodes of files with the same trusted.erofs.fingerprint are mapped to the same anonymous inode (indicated by the ano_inode field). When a read request occurs, the anonymous inode serves as a "container" whose page cache is shared. The actual operations involving the iomap are carried out by the original inode which is mapped to the anonymous inode.
[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 +------------------+-------------+---------------+ | 1.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 +------------------+-------------+---------------+ | 1.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% | +-------------------+------------------+-------------+---------------+
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 10% to 48%.
[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
Hongzhen Luo (4):
erofs: move struct erofs_anon_fs_type to super.c
erofs: introduce page cache share feature
erofs: apply the page cache share feature
erofs: introduce .fadvise for page cache share
fs/erofs/Kconfig | 10 ++ fs/erofs/Makefile | 1 + fs/erofs/data.c | 68 ++++++++++- fs/erofs/fscache.c | 13 -- fs/erofs/inode.c | 12 ++ fs/erofs/internal.h | 11 ++ fs/erofs/pagecache_share.c | 239 +++++++++++++++++++++++++++++++++++++ fs/erofs/pagecache_share.h | 21 ++++ fs/erofs/super.c | 59 +++++++++ fs/erofs/zdata.c | 32 +++++ 10 files changed, 452 insertions(+), 14 deletions(-) create mode 100644 fs/erofs/pagecache_share.c create mode 100644 fs/erofs/pagecache_share.h
Signature · 1 line
2.43.5
RFC PATCH v4 1/4 erofs: move `struct erofs_anon_fs_type` to super.c
Move the struct erofs_anon_fs_type to the super.c and expose it in preparation for the upcoming page cache share feature.
---
v4: There are no changes compared to v3.
v3: https://lore.kernel.org/all/[email protected]/
v2: The patch set v2 does not move the struct erofs_anon_fs_type to super.c.
v1: https://lore.kernel.org/all/[email protected]/
--- fs/erofs/fscache.c | 13 ------------- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 21 +++++++++++++++++++++ 3 files changed, 23 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
@@ -387,6 +387,8 @@ extern const struct file_operations erofs_dir_fops;extern const struct iomap_ops z_erofs_iomap_report_ops; +extern struct file_system_type erofs_anon_fs_type; +/* flags for erofs_fscache_register_cookie() */ #define EROFS_REG_COOKIE_SHARE 0x0001#define EROFS_REG_COOKIE_NEED_NOEXIST 0x0002
fs/erofs/super.c +21 -0
@@ -10,6 +10,7 @@#include <linux/fs_context.h> #include <linux/fs_parser.h> #include <linux/exportfs.h> +#include <linux/pseudo_fs.h> #include "xattr.h" #define CREATE_TRACE_POINTS
@@ -834,6 +835,26 @@ static struct file_system_type erofs_fs_type = { };MODULE_ALIAS_FS ("erofs" ); +static const struct super_operations erofs_anon_sops = { + .statfs = simple_statfs, +}; + +static int erofs_anon_init_fs_context (struct fs_context *fc) +{ +struct pseudo_fs_context *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, +}; +static int __init erofs_module_init (void ) {int err;
Signature · 1 line
2.43.5
RFC PATCH v4 2/4 erofs: introduce page cache share feature
In reply to Hongzhen LuoCurrently, 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. During the mkfs phase, the file content is hashed and the hash value is stored in the trusted.erofs.fingerprint extended attribute. Inodes of files with the same trusted.erofs.fingerprint are mapped to the same anonymous inode (indicated by the ano_inode field). When a read request occurs, the anonymous inode serves as a "container" whose page cache is shared. The actual operations involving the iomap are carried out by the original inode which is mapped to the anonymous inode.
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 +------------------+-------------+---------------+ | 1.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 +------------------+-------------+---------------+ | 1.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% | +-------------------+------------------+-------------+---------------+
---
v4: There are no changes compared to v3.
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
--- fs/erofs/Kconfig | 10 +++ fs/erofs/Makefile | 1 + fs/erofs/internal.h | 4 + fs/erofs/pagecache_share.c | 171 +++++++++++++++++++++++++++++++++++++ fs/erofs/pagecache_share.h | 20 +++++ 5 files changed, 206 insertions(+) create mode 100644 fs/erofs/pagecache_share.c create mode 100644 fs/erofs/pagecache_share.h
fs/erofs/Kconfig +10 -0
@@ -158,3 +158,13 @@ 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" + depends on EROFS_FS + default n + help + This permits EROFS to share page cache for files with same + fingerprints. + + If unsure, say N.
fs/erofs/Makefile +1 -0
@@ -8,3 +8,4 @@ erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o +erofs-$(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) += pagecache_share.o
fs/erofs/internal.h +4 -0
@@ -288,6 +288,9 @@ struct erofs_inode { };#endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct inode *ano_inode; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; };
@@ -384,6 +387,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_pcs_file_fops;extern const struct iomap_ops z_erofs_iomap_report_ops;
fs/erofs/pagecache_share.c new file +171 -0
171 lines not on this page · raw message
fs/erofs/pagecache_share.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copyright (C) 2024, Alibaba Cloud +*/ +#ifndef __EROFS_PAGECACHE_SHARE_H +#define __EROFS_PAGECACHE_SHARE_H + +#include <linux/fs.h> +#include <linux/mount.h> +#include <linux/rwlock.h> +#include <linux/mutex.h> +#include "internal.h" + +int erofs_pcs_init_mnt (void ); +void erofs_pcs_free_mnt (void ); +void erofs_pcs_fill_inode (struct inode *inode); + +extern const struct vm_operations_struct generic_file_vm_ops; + +#endif
Signature · 1 line
2.43.5
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Hongzhen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on xiang-erofs/fixes]
[also build test WARNING on linus/master v6.11-rc6]
[cannot apply to xiang-erofs/dev-test xiang-erofs/dev next-20240904] [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/Hongzhen-Luo/erofs-move-struct-erofs_anon_fs_type-to-super-c/20240902-204137 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git fixes patch link: https://lore.kernel.org/r/20240902110620.2202586-3-hongzhen%40linux.alibaba.com patch subject: [PATCH RFC v4 2/4] erofs: introduce page cache share feature config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20240905/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240905/[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 warnings (new ones prefixed by >>):
fs/erofs/pagecache_share.c: In function 'erofs_pcs_file_read_iter':
>> fs/erofs/pagecache_share.c:127:23: warning: unused variable 'inode' [-Wunused-variable]
127 | struct inode *inode = file_inode(iocb->ki_filp);
| ^~~~~vim +/inode +127 fs/erofs/pagecache_share.c
123
124 static ssize_t erofs_pcs_file_read_iter(struct kiocb *iocb,
125 struct iov_iter *to)
126 {
> 127 struct inode *inode = file_inode(iocb->ki_filp);
128 struct file *file, *ano_file;
129 struct kiocb ano_iocb;
130 ssize_t res;
131
132 if (!iov_iter_count(to))
133 return 0;
134 #ifdef CONFIG_FS_DAX
135 if (IS_DAX(inode))
136 return erofs_file_fops.read_iter(iocb, to);
137 #endif
138 if (iocb->ki_flags & IOCB_DIRECT)
139 return erofs_file_fops.read_iter(iocb, to);
140
141 memcpy(&ano_iocb, iocb, sizeof(struct kiocb));
142 file = iocb->ki_filp;
143 ano_file = file->private_data;
144 if (!ano_file)
145 return -EINVAL;
146 ano_iocb.ki_filp = ano_file;
147 res = filemap_read(&ano_iocb, to, 0);
148 memcpy(iocb, &ano_iocb, sizeof(struct kiocb));
149 iocb->ki_filp = file;
150 file_accessed(file);
151 return res;
152 }
153
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Hongzhen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on xiang-erofs/fixes]
[also build test ERROR on linus/master v6.11-rc6]
[cannot apply to xiang-erofs/dev-test xiang-erofs/dev next-20240905] [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/Hongzhen-Luo/erofs-move-struct-erofs_anon_fs_type-to-super-c/20240902-204137 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git fixes patch link: https://lore.kernel.org/r/20240902110620.2202586-3-hongzhen%40linux.alibaba.com patch subject: [PATCH RFC v4 2/4] erofs: introduce page cache share feature config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20240906/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240906/[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 >>, old ones prefixed by <<):
WARNING: modpost: missing MODULE_DESCRIPTION() in arch/x86/mm/testmmiotrace.o
WARNING: modpost: missing MODULE_DESCRIPTION() in kernel/locking/test-ww_mutex.o
WARNING: modpost: missing MODULE_DESCRIPTION() in lib/test_objpool.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/imx/mxc-clk.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/clk/imx/clk-imxrt1050.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_simpleondemand.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_performance.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_powersave.o
WARNING: modpost: missing MODULE_DESCRIPTION() in drivers/devfreq/governor_userspace.o
>> ERROR: modpost: "generic_file_vm_ops" [fs/erofs/erofs.ko] undefined!
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC PATCH v4 3/4 erofs: apply the page cache share feature
In reply to Hongzhen LuoThis modifies relevant functions to apply the page cache share feature.
---
v4: There are no changes compared to v3.
v3: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
--- fs/erofs/data.c | 34 +++++++++++++++++++++++++++++++++- fs/erofs/inode.c | 12 ++++++++++++ fs/erofs/super.c | 29 +++++++++++++++++++++++++++++ fs/erofs/zdata.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 1 deletion(-)
fs/erofs/data.c +33 -1
@@ -347,12 +347,44 @@ int erofs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,*/ static int erofs_read_folio (struct file *file,struct folio *folio) { +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode *vi =NULL ; +int ret; + +if (file && file->private_data) { + vi = file->private_data; +if (vi->ano_inode ==file_inode (file)) + folio->mapping->host = &vi->vfs_inode; +else + vi =NULL ; + } + ret =iomap_read_folio (folio, &erofs_iomap_ops); +if (vi) + folio->mapping->host =file_inode (file); +return ret; +#else return iomap_read_folio (folio, &erofs_iomap_ops); +#endif } -static void erofs_readahead (struct readahead_control *rac) { +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode *vi =NULL ; +struct file *file = rac->file; + +if (file && file->private_data) { + vi = file->private_data; +if (vi->ano_inode ==file_inode (file)) + rac->mapping->host = &vi->vfs_inode; +else + vi =NULL ; + } +iomap_readahead (rac, &erofs_iomap_ops); +if (vi) + rac->mapping->host =file_inode (file); +#else return iomap_readahead (rac, &erofs_iomap_ops); +#endif }static sector_t erofs_bmap (struct address_space *mapping,sector_t block)
fs/erofs/inode.c +12 -0
@@ -5,6 +5,7 @@* Copyright (C) 2021, Alibaba Cloud */ #include "xattr.h" +#include "pagecache_share.h" #include <trace/events/erofs.h>
@@ -229,10 +230,21 @@ static int erofs_fill_inode(struct inode *inode)switch (inode->i_mode &S_IFMT ) {case S_IFREG : inode->i_op = &erofs_generic_iops; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +erofs_pcs_fill_inode (inode); +if (vi->ano_inode) + inode->i_fop = &erofs_pcs_file_fops; +else if (erofs_inode_is_data_compressed (vi->datalayout)) + inode->i_fop = &generic_ro_fops; +else + inode->i_fop = &erofs_file_fops; +#else if (erofs_inode_is_data_compressed (vi->datalayout)) inode->i_fop = &generic_ro_fops;else inode->i_fop = &erofs_file_fops; +#endif +break ;case S_IFDIR : inode->i_op = &erofs_dir_iops;
fs/erofs/super.c +29 -0
@@ -12,6 +12,7 @@#include <linux/exportfs.h> #include <linux/pseudo_fs.h> #include "xattr.h" +#include "pagecache_share.h" #define CREATE_TRACE_POINTS #include <trace/events/erofs.h>
@@ -103,6 +104,12 @@ static void erofs_free_inode(struct inode *inode) {struct erofs_inode *vi =EROFS_I (inode); +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +if (S_ISREG (inode->i_mode) && vi->ano_inode) { +iput (vi->ano_inode); + vi->ano_inode =NULL ; + } +#endif if (inode->i_op == &erofs_fast_symlink_iops)kfree (inode->i_link);kfree (vi->xattr_shared_xattrs);
@@ -687,6 +694,12 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)if (err)return err; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + err =erofs_pcs_init_mnt (); +if (err) +return err; +#endif +erofs_info (sb,"mounted with root inode @ nid %llu." , sbi->root_nid);return 0 ; }
@@ -797,6 +810,9 @@ static void erofs_kill_sb(struct super_block *sb)else kill_block_super (sb); +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +erofs_pcs_free_mnt (); +#endif erofs_free_dev_context (sbi->devs);fs_put_dax (sbi->dax_dev,NULL );erofs_fscache_unregister_fs (sb);
@@ -835,8 +851,21 @@ static struct file_system_type erofs_fs_type = { };MODULE_ALIAS_FS ("erofs" ); +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +static void erofs_free_anon_inode (struct inode *inode) +{ +if (inode->i_private) { +kfree (inode->i_private); + inode->i_private =NULL ; + } +} +#endif +static const struct super_operations erofs_anon_sops = { .statfs = simple_statfs, +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + .free_inode = erofs_free_anon_inode, +#endif };static int erofs_anon_init_fs_context (struct fs_context *fc)
fs/erofs/zdata.c +32 -0
@@ -1802,6 +1802,17 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f,static int z_erofs_read_folio (struct file *file,struct folio *folio) { +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode *vi =NULL ; + +if (file && file->private_data) { + vi = file->private_data; +if (vi->ano_inode ==file_inode (file)) + folio->mapping->host = &vi->vfs_inode; +else + vi =NULL ; + } +#endif struct inode *const inode = folio->mapping->host;struct erofs_sb_info *const sbi =EROFS_I_SB (inode);struct z_erofs_decompress_frontend f =DECOMPRESS_FRONTEND_INIT (inode);
@@ -1824,11 +1835,27 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +if (vi) + folio->mapping->host =file_inode (file); +#endif return err; }static void z_erofs_readahead (struct readahead_control *rac) { +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct erofs_inode *vi =NULL ; + +if (rac->file && rac->file->private_data) { + vi = rac->file->private_data; +if (vi->ano_inode ==file_inode (rac->file)) + rac->mapping->host = &vi->vfs_inode; +else + vi =NULL ; + } +#endif struct inode *const inode = rac->mapping->host;struct erofs_sb_info *const sbi =EROFS_I_SB (inode);struct z_erofs_decompress_frontend f =DECOMPRESS_FRONTEND_INIT (inode);
@@ -1863,6 +1890,11 @@ static void z_erofs_readahead(struct readahead_control *rac)z_erofs_runqueue (&f,z_erofs_is_sync_decompress (sbi, nr_folios), true);erofs_put_metabuf (&f.map.buf);erofs_release_pages (&f.pagepool); + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +if (vi) + rac->mapping->host =file_inode (rac->file); +#endif }const struct address_space_operations z_erofs_aops = {
Signature · 1 line
2.43.5
RFC PATCH v4 4/4 erofs: introduce .fadvise for page cache share
In reply to Hongzhen LuoWhen using .fadvice to release a file's page cache, it frees those page caches that were firstly read by this file. To achieve this, an interval tree is added in the inode of that file to track the segments firstly read by that inode.
--- fs/erofs/data.c | 38 +++++++++++++++++++-- fs/erofs/internal.h | 5 +++ fs/erofs/pagecache_share.c | 68 ++++++++++++++++++++++++++++++++++++++ fs/erofs/pagecache_share.h | 3 +- fs/erofs/super.c | 9 +++++ 5 files changed, 120 insertions(+), 3 deletions(-)
fs/erofs/data.c +36 -2
@@ -7,6 +7,7 @@#include "internal.h" #include <linux/sched/mm.h> #include <trace/events/erofs.h> +#include "pagecache_share.h" void erofs_unmap_metabuf (struct erofs_buf *buf) {
@@ -349,6 +350,7 @@ static int erofs_read_folio(struct file *file, struct folio *folio) {#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE struct erofs_inode *vi =NULL ; +struct interval_tree_node *seg;int ret;if (file && file->private_data) {
@@ -359,8 +361,22 @@ static int erofs_read_folio(struct file *file, struct folio *folio) vi =NULL ; } ret =iomap_read_folio (folio, &erofs_iomap_ops); -if (vi) +if (vi) { folio->mapping->host =file_inode (file); + seg =erofs_pcs_alloc_seg (); +if (!seg) +return -ENOMEM ; + seg->start =folio_index (folio); + seg->last = seg->start + (folio_size (folio) >>PAGE_SHIFT ); +if (seg->last > (vi->vfs_inode.i_size >>PAGE_SHIFT )) + seg->last = vi->vfs_inode.i_size >>PAGE_SHIFT ; +if (seg->last >= seg->start) { +mutex_lock (&vi->segs_mutex); +interval_tree_insert (seg, &vi->segs); +mutex_unlock (&vi->segs_mutex); + }else +erofs_pcs_free_seg (seg); + }return ret;#else return iomap_read_folio (folio, &erofs_iomap_ops);
@@ -371,6 +387,8 @@ static void erofs_readahead(struct readahead_control *rac)#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE struct erofs_inode *vi =NULL ;struct file *file = rac->file; +struct interval_tree_node *seg; +erofs_off_t start, end;if (file && file->private_data) { vi = file->private_data;
@@ -378,10 +396,26 @@ static void erofs_readahead(struct readahead_control *rac) rac->mapping->host = &vi->vfs_inode; else vi =NULL ; + start =readahead_pos (rac); + end = start +readahead_length (rac); +if (end > vi->vfs_inode.i_size) + end = vi->vfs_inode.i_size; }iomap_readahead (rac, &erofs_iomap_ops); -if (vi) +if (vi) { rac->mapping->host =file_inode (file); + seg =erofs_pcs_alloc_seg (); +if (!seg) +return ; + seg->start = start >>PAGE_SHIFT ; + seg->last = end >>PAGE_SHIFT ; +if (seg->last >= seg->start) { +mutex_lock (&vi->segs_mutex); +interval_tree_insert (seg, &vi->segs); +mutex_unlock (&vi->segs_mutex); + }else +erofs_pcs_free_seg (seg); + }#else return iomap_readahead (rac, &erofs_iomap_ops);#endif
fs/erofs/internal.h +5 -0
@@ -18,6 +18,8 @@#include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/iomap.h> +#include <linux/interval_tree.h> +#include <linux/mutex.h> #include "erofs_fs.h" /* redefine pr_fmt "erofs: " */
@@ -290,6 +292,9 @@ struct erofs_inode { };#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE struct inode *ano_inode; +/* segments attributed by this inode */ +struct rb_root_cached segs; +struct mutex segs_mutex;#endif /* the corresponding vfs inode */ struct inode vfs_inode;
fs/erofs/pagecache_share.c +68 -0
112 lines not on this page · raw message
fs/erofs/pagecache_share.h +2 -1
@@ -14,7 +14,8 @@int erofs_pcs_init_mnt (void );void erofs_pcs_free_mnt (void );void erofs_pcs_fill_inode (struct inode *inode); +struct interval_tree_node *erofs_pcs_alloc_seg (void ); +void erofs_pcs_free_seg (struct interval_tree_node *seg);extern const struct vm_operations_struct generic_file_vm_ops; -#endif
fs/erofs/super.c +9 -0
@@ -105,10 +105,19 @@ static void erofs_free_inode(struct inode *inode)struct erofs_inode *vi =EROFS_I (inode);#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +struct interval_tree_node *seg, *next_seg; +if (S_ISREG (inode->i_mode) && vi->ano_inode) {iput (vi->ano_inode); vi->ano_inode =NULL ; } + seg =interval_tree_iter_first (&vi->segs,0 ,LLONG_MAX ); +while (seg) { + next_seg =interval_tree_iter_next (seg,0 ,LLONG_MAX ); +interval_tree_remove (seg, &vi->segs); +erofs_pcs_free_seg (seg); + seg = next_seg; + }#endif if (inode->i_op == &erofs_fast_symlink_iops)kfree (inode->i_link);
Signature · 1 line
2.43.5
kernel test robot
build botRe: [PATCH RFC v4 4/4] erofs: introduce .fadvise for page cache share
kernel test robot noticed the following build warnings:
Hi Hongzhen,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on xiang-erofs/fixes]
[also build test WARNING on linus/master v6.11-rc6]
[cannot apply to xiang-erofs/dev-test xiang-erofs/dev next-20240905] [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/Hongzhen-Luo/erofs-move-struct-erofs_anon_fs_type-to-super-c/20240902-204137 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git fixes patch link: https://lore.kernel.org/r/20240902110620.2202586-5-hongzhen%40linux.alibaba.com patch subject: [PATCH RFC v4 4/4] erofs: introduce .fadvise for page cache share config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20240905/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240905/[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 warnings (new ones prefixed by >>):
In file included from include/linux/limits.h:7,
from include/linux/overflow.h:6, from include/linux/string.h:12, from include/linux/seq_file.h:6, from fs/erofs/super.c:8:
fs/erofs/super.c: In function 'erofs_free_inode':
>> include/vdso/limits.h:14:25: warning: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '9223372036854775807' to '4294967295' [-Woverflow]
14 | #define LLONG_MAX ((long long)(~0ULL >> 1))
| ^~~~~~~~~~~~~~~~~~~~~~~~~
fs/erofs/super.c:114:54: note: in expansion of macro 'LLONG_MAX'
114 | seg = interval_tree_iter_first(&vi->segs, 0, LLONG_MAX);
| ^~~~~~~~~
>> include/vdso/limits.h:14:25: warning: unsigned conversion from 'long long int' to 'long unsigned int' changes value from '9223372036854775807' to '4294967295' [-Woverflow]
14 | #define LLONG_MAX ((long long)(~0ULL >> 1))
| ^~~~~~~~~~~~~~~~~~~~~~~~~
fs/erofs/super.c:116:60: note: in expansion of macro 'LLONG_MAX'
116 | next_seg = interval_tree_iter_next(seg, 0, LLONG_MAX);
| ^~~~~~~~~vim +14 include/vdso/limits.h
3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 4 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 5 #define USHRT_MAX ((unsigned short)~0U) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 6 #define SHRT_MAX ((short)(USHRT_MAX >> 1)) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 7 #define SHRT_MIN ((short)(-SHRT_MAX - 1)) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 8 #define INT_MAX ((int)(~0U >> 1)) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 9 #define INT_MIN (-INT_MAX - 1) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 10 #define UINT_MAX (~0U) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 11 #define LONG_MAX ((long)(~0UL >> 1)) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 12 #define LONG_MIN (-LONG_MAX - 1) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 13 #define ULONG_MAX (~0UL) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 @14 #define LLONG_MAX ((long long)(~0ULL >> 1)) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 15 #define LLONG_MIN (-LLONG_MAX - 1) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 16 #define ULLONG_MAX (~0ULL) 3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 17 #define UINTPTR_MAX ULONG_MAX
3e0e9f8c6e3ca9 Vincenzo Frascino 2020-03-20 18
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki