This patch adds page cache sharing functionality for compressed inodes. Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com> --- fs/erofs/zdata.c | 57 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 10 deletions(-)
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index aff09f94afb2..b6383cb26acb 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -5,6 +5,7 @@ * Copyright (C) 2022 Alibaba Cloud */ #include "compress.h" +#include "ishare.h" #include <linux/psi.h> #include <linux/cpuhotplug.h> #include <trace/events/erofs.h> @@ -474,7 +475,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; @@ -1835,11 +1836,24 @@ 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)); + struct inode *const inode = folio->mapping->host, *realinode; + Z_EROFS_DEFINE_FRONTEND(f, NULL, folio_pos(folio)); + struct erofs_read_ctx rdctx = { + .file = file, + .inode = inode, + }; int err; trace_erofs_read_folio(folio, false); + + erofs_read_begin(&rdctx); + + if (erofs_is_ishare_inode(inode)) + realinode = erofs_ishare_iget(inode); + else + realinode = inode; + + f.inode = realinode; z_erofs_pcluster_readmore(&f, NULL, true); err = z_erofs_scan_folio(&f, folio, false); z_erofs_pcluster_readmore(&f, NULL, false); @@ -1848,25 +1862,43 @@ 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 (erofs_is_ishare_inode(inode)) + erofs_ishare_iput(realinode); + + erofs_read_end(&rdctx); + 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)); + struct inode *const inode = rac->mapping->host, *realinode; + Z_EROFS_DEFINE_FRONTEND(f, NULL, readahead_pos(rac)); struct folio *head = NULL, *folio; unsigned int nrpages = readahead_count(rac); + struct erofs_read_ctx rdctx = { + .file = rac->file, + .inode = inode, + }; int err; + erofs_read_begin(&rdctx); + + if (erofs_is_ishare_inode(inode)) + realinode = erofs_ishare_iget(inode); + else + realinode = inode; + + f.inode = realinode; z_erofs_pcluster_readmore(&f, rac, true); nrpages = readahead_count(rac); - trace_erofs_readpages(inode, readahead_index(rac), nrpages, false); + trace_erofs_readpages(realinode, readahead_index(rac), nrpages, false); while ((folio = readahead_folio(rac))) { folio->private = head; head = folio; @@ -1879,8 +1911,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); @@ -1888,6 +1920,11 @@ 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 (erofs_is_ishare_inode(inode)) + erofs_ishare_iput(realinode); + + erofs_read_end(&rdctx); } const struct address_space_operations z_erofs_aops = { -- 2.43.5