On 2026/1/20 22:19, Gao Xiang wrote:
On 2026/1/16 17:55, Hongbo Li wrote:
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_share mount 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 | 5 +
fs/erofs/Makefile | 1 +
fs/erofs/inode.c | 24 +----
fs/erofs/internal.h | 57 ++++++++++
fs/erofs/ishare.c | 161 ++++++++++++++++++++++++++++
fs/erofs/super.c | 56 +++++++++-
fs/erofs/xattr.c | 34 ++++++
fs/erofs/xattr.h | 3 +
8 files changed, 316 insertions(+), 25 deletions(-)
create mode 100644 fs/erofs/ishare.c
diff --git a/Documentation/filesystems/erofs.rst
b/Documentation/filesystems/erofs.rst
index 08194f194b94..27d3caa3c73c 100644
--- a/Documentation/filesystems/erofs.rst
+++ b/Documentation/filesystems/erofs.rst
@@ -128,7 +128,12 @@ 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.
I think either the existing or the page cache sharing
here, `domain_id` should be protected as sensitive
information, so it'd be helpful to protect it as a
separate patch.
And change the description as below:
Specify a trusted domain ID for fscache mode
so that
different images with the same blobs,
identified by blob IDs,
can share storage within the same trusted
domain.
Also used for different filesystems with
inode page sharing
enabled to share page cache within the
trusted domain.
fsoffset=%llu Specify block-aligned filesystem offset for
the primary device.
+inode_share Enable inode page sharing for this
filesystem. Inodes with
+ identical content within the same domain ID
can share the
+ page cache.
===================
=========================================================
...
erofs_exit_shrinker();
@@ -1062,6 +1111,8 @@ static int erofs_show_options(struct seq_file
*seq, struct dentry *root)
seq_printf(seq, ",domain_id=%s", sbi->domain_id);
I think we shouldn't show `domain_id` to the userspace
entirely.
Also, let's use kfree_sentitive() and no_free_ptr() to
replace the following snippet:
case Opt_domain_id:
kfree(sbi->domain_id); -> kfree_sentitive
Ok, kfree_sensitive/no_free_ptr looks good, this way makes domain_id
more reliable.
Thanks,
Hongbo
sbi->domain_id = kstrdup(param->string, GFP_KERNEL);
-> sbi->domain_id = no_free_ptr(param->string);
if (!sbi->domain_id)
return -ENOMEM;
break;
And replace with kfree_sentitive() for domain_id everywhere.
Thanks,
Gao Xiang