Hi Christian,

On 2025/7/3 20:23, Christian Brauner wrote:
From: Hongzhen Luo <hongz...@linux.alibaba.com>

This modifies relevant functions to apply the page cache
share feature.

Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com>
Link: 
https://lore.kernel.org/20240902110620.2202586-4-hongz...@linux.alibaba.com
Signed-off-by: Christian Brauner <brau...@kernel.org>
---
  fs/erofs/data.c  | 33 +++++++++++++++++++++++++++++++++
  fs/erofs/inode.c | 15 ++++++++++++++-
  fs/erofs/super.c | 29 +++++++++++++++++++++++++++++
  fs/erofs/zdata.c | 32 ++++++++++++++++++++++++++++++++
  4 files changed, 108 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 6a329c329f43..fb54162f4c54 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -351,12 +351,45 @@ 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;

This is one of the parts I asked Hongzhen to refactor
because it simply doesn't work.

The background is that:
 - since the folio is from the anon_inode mapping now,
   so .iomap_begin() will use the anon inode rather
   than a real inode in a sb, which causes iomap
   don't find the real data source to read;

 - Hongzhen just switch `folio->mapping->host` but it's
   just broken.  Also `file` here can be NULL if the
   request is a kernel-internal request, so we'd better
   not rely on `file` argument.

 - My suggestion was that maintain a inode list so that
   erofs_iomap_begin() can find any valid sb inode to
   find data source instead.

+               else
+                       vi = NULL;
+       }
+       ret = iomap_read_folio(folio, &erofs_iomap_ops);
+       if (vi)
+               folio->mapping->host = file_inode(file);

here.

+       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

Also the #ifdef are too ugly from the upstream code cycle.

Thanks,
Gao Xiang

Reply via email to