erofs: support compressed inodes for page cache share

This patch adds page cache sharing functionality for compressed inodes.

Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
This commit is contained in:
Hongzhen Luo 2026-01-23 01:31:31 +00:00 committed by Gao Xiang
parent 34096ba919
commit 9364b55a4d
2 changed files with 24 additions and 16 deletions

View file

@ -44,8 +44,6 @@ bool erofs_ishare_fill_inode(struct inode *inode)
struct inode *sharedinode;
unsigned long hash;
if (erofs_inode_is_data_compressed(vi->datalayout))
return false;
if (erofs_xattr_fill_inode_fingerprint(&fp, inode, sbi->domain_id))
return false;
hash = xxh32(fp.opaque, fp.size, 0);

View file

@ -494,7 +494,7 @@ enum z_erofs_pclustermode {
};
struct z_erofs_frontend {
struct inode *const inode;
struct inode *inode, *sharedinode;
struct erofs_map_blocks map;
struct z_erofs_bvec_iter biter;
@ -509,8 +509,8 @@ struct z_erofs_frontend {
unsigned int icur;
};
#define Z_EROFS_DEFINE_FRONTEND(fe, i, ho) struct z_erofs_frontend fe = { \
.inode = i, .head = Z_EROFS_PCLUSTER_TAIL, \
#define Z_EROFS_DEFINE_FRONTEND(fe, i, si, ho) struct z_erofs_frontend fe = { \
.inode = i, .sharedinode = si, .head = Z_EROFS_PCLUSTER_TAIL, \
.mode = Z_EROFS_PCLUSTER_FOLLOWED, .headoffset = ho }
static bool z_erofs_should_alloc_cache(struct z_erofs_frontend *fe)
@ -1858,7 +1858,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
pgoff_t index = cur >> PAGE_SHIFT;
struct folio *folio;
folio = erofs_grab_folio_nowait(inode->i_mapping, index);
folio = erofs_grab_folio_nowait(f->sharedinode->i_mapping, index);
if (!IS_ERR_OR_NULL(folio)) {
if (folio_test_uptodate(folio))
folio_unlock(folio);
@ -1875,11 +1875,13 @@ 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 *sharedinode = folio->mapping->host;
bool need_iput;
struct inode *realinode = erofs_real_inode(sharedinode, &need_iput);
Z_EROFS_DEFINE_FRONTEND(f, realinode, sharedinode, folio_pos(folio));
int err;
trace_erofs_read_folio(inode, folio, false);
trace_erofs_read_folio(realinode, folio, false);
z_erofs_pcluster_readmore(&f, NULL, true);
err = z_erofs_scan_folio(&f, folio, false);
z_erofs_pcluster_readmore(&f, NULL, false);
@ -1888,23 +1890,28 @@ 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 (need_iput)
iput(realinode);
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 *sharedinode = rac->mapping->host;
bool need_iput;
struct inode *realinode = erofs_real_inode(sharedinode, &need_iput);
Z_EROFS_DEFINE_FRONTEND(f, realinode, sharedinode, readahead_pos(rac));
unsigned int nrpages = readahead_count(rac);
struct folio *head = NULL, *folio;
int err;
trace_erofs_readahead(inode, readahead_index(rac), nrpages, false);
trace_erofs_readahead(realinode, readahead_index(rac), nrpages, false);
z_erofs_pcluster_readmore(&f, rac, true);
while ((folio = readahead_folio(rac))) {
folio->private = head;
@ -1918,8 +1925,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);
@ -1927,6 +1934,9 @@ static void z_erofs_readahead(struct readahead_control *rac)
(void)z_erofs_runqueue(&f, nrpages << PAGE_SHIFT);
erofs_put_metabuf(&f.map.buf);
erofs_release_pages(&f.pagepool);
if (need_iput)
iput(realinode);
}
const struct address_space_operations z_erofs_aops = {