On 2025/11/17 11:14, Hongbo Li wrote:
Hi Xiang
On 2025/11/17 11:06, Gao Xiang wrote:
On 2025/11/14 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.
Signed-off-by: Hongzhen Luo <[email protected]>
Signed-off-by: Hongbo Li <[email protected]>
---
...
+
+static int erofs_ishare_file_open(struct inode *inode, struct file *file)
+{
+ struct file *realfile;
+ struct inode *dedup;
+
+ dedup = EROFS_I(inode)->ishare;
+ if (!dedup)
+ return -EINVAL;
+
+ realfile = alloc_file_pseudo(dedup, erofs_ishare_mnt, "erofs_ishare_file",
+ O_RDONLY, &erofs_file_fops);
+ if (IS_ERR(realfile))
+ return PTR_ERR(realfile);
+
+ file_ra_state_init(&realfile->f_ra, file->f_mapping);
+ realfile->private_data = EROFS_I(inode);
+ file->private_data = realfile;
+ return 0;
My apologies, I got it wrong. The latest code wasn't synced. The most current
version should be this one.
static int erofs_ishare_file_open(struct inode *inode, struct file *file)
{
struct file *realfile;
struct inode *dedup;
char *buf, *filepath;
dedup = EROFS_I(inode)->ishare;
if (!dedup)
return -EINVAL;
buf = kmalloc(PATH_MAX, GFP_KERNEL);
if (!buf)
return -ENOMEM;
filepath = file_path(file, buf, PATH_MAX);
if (IS_ERR(filepath)) {
kfree(buf);
return -PTR_ERR(filepath);
}
realfile = alloc_file_pseudo(dedup, erofs_ishare_mnt, filepath + 1,
O_RDONLY, &erofs_file_fops);
kfree(buf);
if (IS_ERR(realfile))
return PTR_ERR(realfile);
file_ra_state_init(&realfile->f_ra, file->f_mapping);
ihold(dedup);
realfile->private_data = EROFS_I(inode);
file->private_data = realfile;
return 0;
}
I changed the "erofs_ishare_file" with filepath + 1 to display the realpath of
the original file.
Although it could work for file_user_path() [but it's unclean on my side],
but file_user_inode() still doesn't work.
You should adapt backing_file infrastructure instead.
Thanks,
Gao Xiang