From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F3B02DF131; Wed, 31 Dec 2025 09:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172444; cv=none; b=DVJnYWGMzag3mGb4X0lhp3ZNShLFDkdWa/5JbxYSunieX/duavileaACslfxVjJcY3dUH8xPh6Aq1G10aaoGZlStte89YvcsMl2P6gXMdKqUZZKFupYXSZOL6rtyv2P1MH47oU2qOg5G59GCKc7CfQ6PyrxGP8P5vC6M0Ktivv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172444; c=relaxed/simple; bh=n0CYApCMSTPET0JshPYELMjqMo0Sh6yI6KkP6p9i+R0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HpKmRVUQ4wQJ3KkMTsxIv6W39380Ac7JYROaic86qc1ZiAUeYrHE+i/B98yAFvvTRNKiefreLC71ui6dLtR0xhpTJWpJkVNAxOETJRpMzmhNepzzUhzgVuEdI8t5b7urW0A82ZQX5wXUCZ1ra3pZwASmsy+JvEW6xr2YRUR/A1I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=ZP999kvm; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="ZP999kvm" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=lfJ/O4D8J9vNgJSRQcHGc3PWqPTwsbyNQanvesy0zuM=; b=ZP999kvmVIM5g0Z3M5rHvI+y02z5I7bYWmfzFpC634J7gM4BedPDjrL4fqVf3LZONrFV0gfaN U6jq58kyErcj7RXi+ftcBapO3T3+xxEGWoIu19ZNf2zZg2VcSoQLSsTRGstQrWQnaVXJm2+QAMb wvyKxEUvvb4EU52IoW46QKE= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4dh41f5hq2zmV71; Wed, 31 Dec 2025 17:10:46 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 90BE74069C; Wed, 31 Dec 2025 17:13:58 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:13:57 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 01/10] iomap: stash iomap read ctx in the private field of iomap_iter Date: Wed, 31 Dec 2025 09:01:09 +0000 Message-ID: <20251231090118.541061-2-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" It's useful to get filesystem-specific information using the existing private field in the @iomap_iter passed to iomap_{begin,end} for advanced usage for iomap buffered reads, which is much like the current iomap DIO. For example, EROFS needs it to: - implement an efficient page cache sharing feature, since iomap needs to apply to anon inode page cache but we'd like to get the backing inode/fs instead, so filesystem-specific private data is needed to keep such information; - pass in both struct page * and void * for inline data to avoid kmap_to_page() usage (which is bogus). Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/fuse/file.c | 4 ++-- fs/iomap/buffered-io.c | 6 ++++-- include/linux/iomap.h | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 01bc894e9c2b..f5d8887c1922 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -979,7 +979,7 @@ static int fuse_read_folio(struct file *file, struct fo= lio *folio) return -EIO; } =20 - iomap_read_folio(&fuse_iomap_ops, &ctx); + iomap_read_folio(&fuse_iomap_ops, &ctx, NULL); fuse_invalidate_atime(inode); return 0; } @@ -1081,7 +1081,7 @@ static void fuse_readahead(struct readahead_control *= rac) if (fuse_is_bad(inode)) return; =20 - iomap_readahead(&fuse_iomap_ops, &ctx); + iomap_readahead(&fuse_iomap_ops, &ctx, NULL); } =20 static ssize_t fuse_cache_read_iter(struct kiocb *iocb, struct iov_iter *t= o) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e5c1ca440d93..5f7dcbabbda3 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -555,13 +555,14 @@ static int iomap_read_folio_iter(struct iomap_iter *i= ter, } =20 void iomap_read_folio(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx) + struct iomap_read_folio_ctx *ctx, void *private) { struct folio *folio =3D ctx->cur_folio; struct iomap_iter iter =3D { .inode =3D folio->mapping->host, .pos =3D folio_pos(folio), .len =3D folio_size(folio), + .private =3D private, }; size_t bytes_submitted =3D 0; int ret; @@ -620,13 +621,14 @@ static int iomap_readahead_iter(struct iomap_iter *it= er, * the filesystem to be reentered. */ void iomap_readahead(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx) + struct iomap_read_folio_ctx *ctx, void *private) { struct readahead_control *rac =3D ctx->rac; struct iomap_iter iter =3D { .inode =3D rac->mapping->host, .pos =3D readahead_pos(rac), .len =3D readahead_length(rac), + .private =3D private, }; size_t cur_bytes_submitted; =20 diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 520e967cb501..441d614e9fdf 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -341,9 +341,9 @@ ssize_t iomap_file_buffered_write(struct kiocb *iocb, s= truct iov_iter *from, const struct iomap_ops *ops, const struct iomap_write_ops *write_ops, void *private); void iomap_read_folio(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx); + struct iomap_read_folio_ctx *ctx, void *private); void iomap_readahead(const struct iomap_ops *ops, - struct iomap_read_folio_ctx *ctx); + struct iomap_read_folio_ctx *ctx, void *private); bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count= ); struct folio *iomap_get_folio(struct iomap_iter *iter, loff_t pos, size_t = len); bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); @@ -595,7 +595,7 @@ static inline void iomap_bio_read_folio(struct folio *f= olio, .cur_folio =3D folio, }; =20 - iomap_read_folio(ops, &ctx); + iomap_read_folio(ops, &ctx, NULL); } =20 static inline void iomap_bio_readahead(struct readahead_control *rac, @@ -606,7 +606,7 @@ static inline void iomap_bio_readahead(struct readahead= _control *rac, .rac =3D rac, }; =20 - iomap_readahead(ops, &ctx); + iomap_readahead(ops, &ctx, NULL); } #endif /* CONFIG_BLOCK */ =20 --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D571831960E; Wed, 31 Dec 2025 09:14:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172452; cv=none; b=cIE5jvwxzUOhxi2oAdgk55N/3s3rzF9TmA2Pw4moLh2tF8GwdX3N2xkj85YIoFYT7YxPCyNKjry+kgY0ADcW4Zl6srhrQ/g2Dmw/hCD42VKzsgKSYEbVf/IQRh+4cLroyiEMVLud00RkYv3QzDf7hLZQzA766bZ3a+zRYjA8mLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172452; c=relaxed/simple; bh=GIG0iVEeSaYWSb9UOeG6A4TW0TzFA2hTW6WDyaPChPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t+gWGnjeaDUYVMTG/iG2oV1enVWhxKNxstB2irfBajme6h0tXmBhqViZqScV5ORyKYJULi2eQnwoW6aM+wNyRMymTjY9KOK3jWyZyYpbmyxlQ+rIAHlTcsW4rtxTy00Wm1f+Oa1JZhz2Ga/MOeKm5VJbchW74KSBZQGSnrQOy40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=hDPirPbx; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="hDPirPbx" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=GMiG3KxyMRrDcExhh2zKYwP+YiMVAseTuuCZp2tTRO0=; b=hDPirPbxVDQuKp01p2DNZl+buDOy3ab1lSG7hTWnEYHAoMWsq5JNoa2iAlAKSfml9SRsJQPtD SjjEEa/uVi/RJDqnk5YxToqDDuK0kq9uVDcP+i0eORJ5Abmld7TR/4kKCRQKQN74myXaNF2WDmG m7SA24qGQvEAADFb083dgV8= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4dh41X0JGVzcb0w; Wed, 31 Dec 2025 17:10:40 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 0CFA94056A; Wed, 31 Dec 2025 17:13:59 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:13:58 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 02/10] erofs: hold read context in iomap_iter if needed Date: Wed, 31 Dec 2025 09:01:10 +0000 Message-ID: <20251231090118.541061-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" Introduce `struct erofs_iomap_iter_ctx` to hold both `struct page *` and `void *base`, avoiding bogus use of `kmap_to_page()` in `erofs_iomap_end()`. With this change, fiemap and bmap no longer need to read inline data. Additionally, the upcoming page cache sharing mechanism requires passing the backing inode pointer to `erofs_iomap_{begin,end}()`, as I/O accesses must apply to backing inodes rather than anon inodes. Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/data.c | 67 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index bb13c4cb8455..71e23d91123d 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -266,13 +266,20 @@ void erofs_onlinefolio_end(struct folio *folio, int e= rr, bool dirty) folio_end_read(folio, !(v & BIT(EROFS_ONLINEFOLIO_EIO))); } =20 +struct erofs_iomap_iter_ctx { + struct page *page; + void *base; +}; + static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t le= ngth, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { - int ret; + struct iomap_iter *iter =3D container_of(iomap, struct iomap_iter, iomap); + struct erofs_iomap_iter_ctx *ctx =3D iter->private; struct super_block *sb =3D inode->i_sb; struct erofs_map_blocks map; struct erofs_map_dev mdev; + int ret; =20 map.m_la =3D offset; map.m_llen =3D length; @@ -283,7 +290,6 @@ static int erofs_iomap_begin(struct inode *inode, loff_= t offset, loff_t length, iomap->offset =3D map.m_la; iomap->length =3D map.m_llen; iomap->flags =3D 0; - iomap->private =3D NULL; iomap->addr =3D IOMAP_NULL_ADDR; if (!(map.m_flags & EROFS_MAP_MAPPED)) { iomap->type =3D IOMAP_HOLE; @@ -309,16 +315,20 @@ static int erofs_iomap_begin(struct inode *inode, lof= f_t offset, loff_t length, } =20 if (map.m_flags & EROFS_MAP_META) { - void *ptr; - struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; - iomap->type =3D IOMAP_INLINE; - ptr =3D erofs_read_metabuf(&buf, sb, map.m_pa, - erofs_inode_in_metabox(inode)); - if (IS_ERR(ptr)) - return PTR_ERR(ptr); - iomap->inline_data =3D ptr; - iomap->private =3D buf.base; + /* read context should read the inlined data */ + if (ctx) { + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + void *ptr; + + ptr =3D erofs_read_metabuf(&buf, sb, map.m_pa, + erofs_inode_in_metabox(inode)); + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + iomap->inline_data =3D ptr; + ctx->page =3D buf.page; + ctx->base =3D buf.base; + } } else { iomap->type =3D IOMAP_MAPPED; } @@ -328,18 +338,18 @@ static int erofs_iomap_begin(struct inode *inode, lof= f_t offset, loff_t length, static int erofs_iomap_end(struct inode *inode, loff_t pos, loff_t length, ssize_t written, unsigned int flags, struct iomap *iomap) { - void *ptr =3D iomap->private; + struct iomap_iter *iter =3D container_of(iomap, struct iomap_iter, iomap); + struct erofs_iomap_iter_ctx *ctx =3D iter->private; =20 - if (ptr) { + if (ctx && ctx->base) { struct erofs_buf buf =3D { - .page =3D kmap_to_page(ptr), - .base =3D ptr, + .page =3D ctx->page, + .base =3D ctx->base, }; =20 DBG_BUGON(iomap->type !=3D IOMAP_INLINE); erofs_put_metabuf(&buf); - } else { - DBG_BUGON(iomap->type =3D=3D IOMAP_INLINE); + ctx->base =3D NULL; } return written; } @@ -369,18 +379,30 @@ int erofs_fiemap(struct inode *inode, struct fiemap_e= xtent_info *fieinfo, */ static int erofs_read_folio(struct file *file, struct folio *folio) { + struct iomap_read_folio_ctx read_ctx =3D { + .ops =3D &iomap_bio_read_ops, + .cur_folio =3D folio, + }; + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + trace_erofs_read_folio(folio, true); =20 - iomap_bio_read_folio(folio, &erofs_iomap_ops); + iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx); return 0; } =20 static void erofs_readahead(struct readahead_control *rac) { + struct iomap_read_folio_ctx read_ctx =3D { + .ops =3D &iomap_bio_read_ops, + .rac =3D rac, + }; + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + trace_erofs_readahead(rac->mapping->host, readahead_index(rac), readahead_count(rac), true); =20 - iomap_bio_readahead(rac, &erofs_iomap_ops); + iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx); } =20 static sector_t erofs_bmap(struct address_space *mapping, sector_t block) @@ -400,9 +422,12 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb= , struct iov_iter *to) if (IS_DAX(inode)) return dax_iomap_rw(iocb, to, &erofs_iomap_ops); #endif - if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) + if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) { + struct erofs_iomap_iter_ctx iter_ctx =3D {}; + return iomap_dio_rw(iocb, to, &erofs_iomap_ops, - NULL, 0, NULL, 0); + NULL, 0, &iter_ctx, 0); + } return filemap_read(iocb, to, 0); } =20 --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout03.his.huawei.com (canpmsgout03.his.huawei.com [113.46.200.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8C4A311C39; Wed, 31 Dec 2025 09:14:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.218 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172444; cv=none; b=B1ZXqWPNq1k/6YTwB/oV/WssWVSawpT/c6HWxlBWI6j4A5QYhit1iSm3KBotVL+7Ahlm4H8Tn14KlYyJ6mn+EEC/OhnPF03L4pVebPsRb3iM1HoxtbOCJfB9Ny1uruWK3SDJAyUrlgCzyPk2mFUPMrmVSAhy8+AJ8DgQVK/ayWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172444; c=relaxed/simple; bh=/DOP628ou57Yld7gMP4kYmxmunqIn78QOq3XPXhRUAY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TsBaF6TbuaTzbkTVjTwlYbeB8RYZgmg6hHRFvzLD+fWPobjB4R5anUMgHMZOHMiFPdb4jOkj48RrdiMgOQfOlqSIlgkUxO0bpldCzs6IpnHAIhV5HZ7bRTuYCLcKG5sXGRIKtTRx/Rmst81L3UqEm5zzlo8ODZoJpcB95BsYXPg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=aViTVgKb; arc=none smtp.client-ip=113.46.200.218 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="aViTVgKb" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=IJqOVDMyH2cU6HZaQ6KGaq7L7r7sGB/NU+oSMo68sYk=; b=aViTVgKbU3p9F6fvfb/DRZ9GIhljQ3rKlHQMPA1II5YccTLm1l79Wl8RBcmkkhYNwMzHKxXz0 9YV1Y0ow6kq2fONT0jz7uycW8blnvYaMxZYGGACdFOLs9cXkvJ3tWcEIwXSiiP4I/798eIXtO+j kCdEQvGGYPkM65v8oi6/oqU= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4dh41k4dcTzpStp; Wed, 31 Dec 2025 17:10:50 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 7A3484056B; Wed, 31 Dec 2025 17:13:59 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:13:58 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 03/10] fs: Export alloc_empty_backing_file Date: Wed, 31 Dec 2025 09:01:11 +0000 Message-ID: <20251231090118.541061-4-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" There is no need to open nonexistent real files if backing files couldn't be backed by real files (e.g., EROFS page cache sharing doesn't need typical real files to open again). Therefore, we export the alloc_empty_backing_file() helper, allowing filesystems to dynamically set the backing file without real file open. This is particularly useful for obtaining the correct @path and @inode when calling file_user_path() and file_user_inode(). Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang Acked-by: Amir Goldstein --- fs/file_table.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/file_table.c b/fs/file_table.c index cd4a3db4659a..476edfe7d8f5 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -308,6 +308,7 @@ struct file *alloc_empty_backing_file(int flags, const = struct cred *cred) ff->file.f_mode |=3D FMODE_BACKING | FMODE_NOACCOUNT; return &ff->file; } +EXPORT_SYMBOL_GPL(alloc_empty_backing_file); =20 /** * file_init_path - initialize a 'struct file' based on path --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE0FD316193; Wed, 31 Dec 2025 09:14:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.217 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172450; cv=none; b=XSKEUq/jZnJSXwMov534hP27PmQR8zZnFxHQpm7TotHCLuU5hKUNdIx8C8C6hiyWdXnjvDVpcLZj+TqL2/S+wgvaW3h7gRibFBTW49dBllMfasGgRDhnN1GFicovBCseZrtVJZkhXrR0gM1zg1dForc3OZGf09nosv5OxRWae7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172450; c=relaxed/simple; bh=bLPyX55goz9UpKyTSsH/rsQVx9Lcd+68NmlbcIC2gHs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HpfQV3aGHG2sS/fFRyN4KmjXQBAGkue582NxbIFaA1YUyTD+2HN1KRVVjJ4zlmmVHFS1AF6w03lPW621h33qyMrRG9wZg8o6VVZgBc3TAMKnfRF3L9LAPDGbmuFO4W5CTFjp6eTZWOBlpz6/ouXU8FUaadXM9xJhGrZwKTjaZUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=oJbF4d0t; arc=none smtp.client-ip=113.46.200.217 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="oJbF4d0t" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=otZzmT6rxktVNDVECk5mC06H07hAnwXYZ9UJTBeZ2EE=; b=oJbF4d0t5wRl+Q3D2MEG1XxQ46Sws4p95wCVOUDW01xFXaHTtZLIuDaU1CGP+FYnhHWI9gyc+ vl1DpAL3wOTCohN8rpHMh58gcD4/VUG36UAoqVqtLr4Wg1E8jI9n820W4N+o3Weae21OVDrRQCJ RiDve7yi5NEMgQAYQ4IAnOc= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4dh41Y0HfKzcZyD; Wed, 31 Dec 2025 17:10:41 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 0AC214056A; Wed, 31 Dec 2025 17:14:00 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:13:59 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 04/10] erofs: decouple `struct erofs_anon_fs_type` Date: Wed, 31 Dec 2025 09:01:12 +0000 Message-ID: <20251231090118.541061-5-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Gao Xiang - Move the `struct erofs_anon_fs_type` to super.c and expose it in preparation for the upcoming page cache share feature; - Remove the `.owner` field, as they are all internal mounts and fully managed by EROFS. Retaining `.owner` would unnecessarily increment module reference counts, preventing the EROFS kernel module from being unloaded. Signed-off-by: Gao Xiang --- fs/erofs/fscache.c | 13 ------------- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 7a346e20f7b7..f4937b025038 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -3,7 +3,6 @@ * Copyright (C) 2022, Alibaba Cloud * Copyright (C) 2022, Bytedance Inc. All rights reserved. */ -#include #include #include "internal.h" =20 @@ -13,18 +12,6 @@ static LIST_HEAD(erofs_domain_list); static LIST_HEAD(erofs_domain_cookies_list); static struct vfsmount *erofs_pseudo_mnt; =20 -static int erofs_anon_init_fs_context(struct fs_context *fc) -{ - return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; -} - -static struct file_system_type erofs_anon_fs_type =3D { - .owner =3D THIS_MODULE, - .name =3D "pseudo_erofs", - .init_fs_context =3D erofs_anon_init_fs_context, - .kill_sb =3D kill_anon_super, -}; - struct erofs_fscache_io { struct netfs_cache_resources cres; struct iov_iter iter; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index f7f622836198..98fe652aea33 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -188,6 +188,8 @@ static inline bool erofs_is_fileio_mode(struct erofs_sb= _info *sbi) return IS_ENABLED(CONFIG_EROFS_FS_BACKED_BY_FILE) && sbi->dif0.file; } =20 +extern struct file_system_type erofs_anon_fs_type; + static inline bool erofs_is_fscache_mode(struct super_block *sb) { return IS_ENABLED(CONFIG_EROFS_FS_ONDEMAND) && diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 937a215f626c..f18f43b78fca 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "xattr.h" =20 #define CREATE_TRACE_POINTS @@ -936,6 +937,19 @@ static struct file_system_type erofs_fs_type =3D { }; MODULE_ALIAS_FS("erofs"); =20 +#if defined(CONFIG_EROFS_FS_ONDEMAND) +static int erofs_anon_init_fs_context(struct fs_context *fc) +{ + return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; +} + +struct file_system_type erofs_anon_fs_type =3D { + .name =3D "pseudo_erofs", + .init_fs_context =3D erofs_anon_init_fs_context, + .kill_sb =3D kill_anon_super, +}; +#endif + static int __init erofs_module_init(void) { int err; --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout07.his.huawei.com (canpmsgout07.his.huawei.com [113.46.200.222]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E68031578E; Wed, 31 Dec 2025 09:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.222 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172445; cv=none; b=Kjf+UiHYcVgBJAXTMG47SqyYkV8WYMnk9+PjLod1hjPjjep7PlnrfTuELnFBEi628UTbn0CrsY9D9n/V75hzaz+qlp5eDaPOQfuaCclJKGDFMN/vJy19/ADuDU7y0TutYM7u2XRO5ZaIgUGlUauT9xWw9yfBP3fbau5r0rhiBr8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172445; c=relaxed/simple; bh=rXVocoARrav5F9iqdE9uW2S2fitJawjEKBGGH3kMBC4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=png3H9sx05mRpNDhMc1suGYaFZ6CWQiDC3ydKMDQA44k9P2w1yFenK/KS2vlR33vTYlUJJuO6OIvJlB4z0dDr3eWfI2P2dFr01X41+smsOQDca0gcIS8DHJBQDOz8MqgHp3F9febdRsxKzwN4wkq+p1KvEqzvOYGuzCn+4Kktic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=G3u9w4Ct; arc=none smtp.client-ip=113.46.200.222 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="G3u9w4Ct" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=AkwyAy/a1gOEFPbH0KVqKhamoqcDqFdiJaCVxpOTKuw=; b=G3u9w4CtQ+ZjFlbzmXiZ8/OmYCzYhPDyKR9C8AOvElUTGdc/lleVCm3VrnhU8vnBfSCP45MjO UAplSxw93Q61QmZJcR9cZxWa5R6irYYDuzyWMEr+nEXAAfSIFKu0tfTfO5pOOz/iyvx9Ac8VHpx ihwDY3Gt4X9lSU3o5x/HSfQ= Received: from mail.maildlp.com (unknown [172.19.162.92]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4dh41j6vwFzLlXZ; Wed, 31 Dec 2025 17:10:49 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 7957340562; Wed, 31 Dec 2025 17:14:00 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:13:59 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 05/10] erofs: support user-defined fingerprint name Date: Wed, 31 Dec 2025 09:01:13 +0000 Message-ID: <20251231090118.541061-6-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo When creating the EROFS image, users can specify the fingerprint name. This is to prepare for the upcoming inode page cache share. Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/Kconfig | 9 +++++++++ fs/erofs/erofs_fs.h | 5 +++-- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 9 +++++++++ fs/erofs/xattr.c | 13 +++++++++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/fs/erofs/Kconfig b/fs/erofs/Kconfig index d81f3318417d..b71f2a8074fe 100644 --- a/fs/erofs/Kconfig +++ b/fs/erofs/Kconfig @@ -194,3 +194,12 @@ config EROFS_FS_PCPU_KTHREAD_HIPRI at higher priority. =20 If unsure, say N. + +config EROFS_FS_PAGE_CACHE_SHARE + bool "EROFS page cache share support (experimental)" + depends on EROFS_FS && EROFS_FS_XATTR && !EROFS_FS_ONDEMAND + help + This enables page cache sharing among inodes with identical + content fingerprints on the same machine. + + If unsure, say N. diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index e24268acdd62..b30a74d307c5 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -17,7 +17,7 @@ #define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004 #define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008 #define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010 - +#define EROFS_FEATURE_COMPAT_ISHARE_XATTRS 0x00000020 =20 /* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should @@ -83,7 +83,8 @@ struct erofs_super_block { __le32 xattr_prefix_start; /* start of long xattr prefixes */ __le64 packed_nid; /* nid of the special packed inode */ __u8 xattr_filter_reserved; /* reserved for xattr name filter */ - __u8 reserved[3]; + __u8 ishare_xattr_prefix_id; + __u8 reserved[2]; __le32 build_time; /* seconds added to epoch for mkfs time */ __le64 rootnid_8b; /* (48BIT on) nid of root directory */ __le64 reserved2; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 98fe652aea33..ec79e8b44d3b 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -134,6 +134,7 @@ struct erofs_sb_info { u32 xattr_blkaddr; u32 xattr_prefix_start; u8 xattr_prefix_count; + u8 ishare_xattr_prefix_id; struct erofs_xattr_prefix_item *xattr_prefixes; unsigned int xattr_filter_reserved; #endif @@ -238,6 +239,7 @@ EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER) EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_META= BOX) EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX) +EROFS_FEATURE_FUNCS(ishare_xattrs, compat, COMPAT_ISHARE_XATTRS) =20 static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_= t nid) { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index f18f43b78fca..dca1445f6c92 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -320,6 +320,15 @@ static int erofs_read_superblock(struct super_block *s= b) sbi->xattr_prefix_start =3D le32_to_cpu(dsb->xattr_prefix_start); sbi->xattr_prefix_count =3D dsb->xattr_prefix_count; sbi->xattr_filter_reserved =3D dsb->xattr_filter_reserved; + if (erofs_sb_has_ishare_xattrs(sbi)) { + if (dsb->ishare_xattr_prefix_id >=3D sbi->xattr_prefix_count) { + erofs_err(sb, "invalid ishare xattr prefix id %u", + dsb->ishare_xattr_prefix_id); + ret =3D -EFSCORRUPTED; + goto out; + } + sbi->ishare_xattr_prefix_id =3D dsb->ishare_xattr_prefix_id; + } #endif sbi->islotbits =3D ilog2(sizeof(struct erofs_inode_compact)); if (erofs_sb_has_48bit(sbi) && dsb->rootnid_8b) { diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 396536d9a862..ae61f20cb861 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -519,6 +519,19 @@ int erofs_xattr_prefixes_init(struct super_block *sb) } =20 erofs_put_metabuf(&buf); + if (!ret && erofs_sb_has_ishare_xattrs(sbi)) { + struct erofs_xattr_prefix_item *pf =3D pfs + sbi->ishare_xattr_prefix_id; + struct erofs_xattr_long_prefix *newpfx; + + newpfx =3D krealloc(pf->prefix, + sizeof(*newpfx) + pf->infix_len + 1, GFP_KERNEL); + if (newpfx) { + newpfx->infix[pf->infix_len] =3D '\0'; + pf->prefix =3D newpfx; + } else { + ret =3D -ENOMEM; + } + } sbi->xattr_prefixes =3D pfs; if (ret) erofs_xattr_prefixes_cleanup(sb); --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout09.his.huawei.com (canpmsgout09.his.huawei.com [113.46.200.224]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6850C3168E3; Wed, 31 Dec 2025 09:14:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.224 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172447; cv=none; b=UqpVZidreu/EzFuhSvet5DB9Af7UgWtyTpKhJHMqDN2mzNlZAcGk/45xWTU18Napkd8aXIjscow84CzfXgE6zO2CT5MP8VRUHeCXeZiT6pBf5nMgorRK3ikGmXGsvfjDQbG2vo1Ak2ZOd97cKulWGz5yi1zyuvMapU9+Ha4KgEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172447; c=relaxed/simple; bh=S7RjyECHRDHNXIL1Al8k3RPWxT6vjUtdtCg4YK41Swo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NuOnnkz7/Exv0yTzV3tBGzp9aW41AfQQLuR77irbWPTpQ5hdb2f8T4OGL+cfzWsWJsK+Q51AjUaCqa0UbIQaSNXpEgy6W3iFZFAAj1hMIgtU9rF2RLm01RRkFBPwL6eVCIAT/NWtylef7vGySS9OMx+SlE/FHktmJMbJrs51L5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=6vbCpnyS; arc=none smtp.client-ip=113.46.200.224 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="6vbCpnyS" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Ii4OAViqYCm/sgHCVWzYCGvcDaSOgZiGOYibBrZpOYU=; b=6vbCpnySXkmEqQBj+K55ndCgfd4lrG6flgNfy05ERumm6g/PuPxdBMSEG46fc1SwIvzqG7gg+ 1+WQ3JCBdt0XUhX2EChxqn0BVx0dlMHswwEPUz0SaTu0tPTlwDgXoNAw249+FBw+UlUxb7wWNZW cBSMB8miZLhswOMENMspOgk= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout09.his.huawei.com (SkyGuard) with ESMTPS id 4dh41k2Vbsz1cyP2; Wed, 31 Dec 2025 17:10:50 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 04FFD4069C; Wed, 31 Dec 2025 17:14:01 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:14:00 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 06/10] erofs: support domain-specific page cache share Date: Wed, 31 Dec 2025 09:01:14 +0000 Message-ID: <20251231090118.541061-7-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo Only files in the same domain will share the page cache. Also modify the sysfs related content in preparation for the upcoming page cache share feature. Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/super.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index dca1445f6c92..960da62636ad 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -524,6 +524,8 @@ static int erofs_fc_parse_param(struct fs_context *fc, if (!sbi->fsid) return -ENOMEM; break; +#endif +#if defined(CONFIG_EROFS_FS_ONDEMAND) || defined(CONFIG_EROFS_FS_PAGE_CACH= E_SHARE) case Opt_domain_id: kfree(sbi->domain_id); sbi->domain_id =3D kstrdup(param->string, GFP_KERNEL); @@ -624,7 +626,7 @@ static void erofs_set_sysfs_name(struct super_block *sb) { struct erofs_sb_info *sbi =3D EROFS_SB(sb); =20 - if (sbi->domain_id) + if (sbi->domain_id && !erofs_sb_has_ishare_xattrs(sbi)) super_set_sysfs_name_generic(sb, "%s,%s", sbi->domain_id, sbi->fsid); else if (sbi->fsid) @@ -1054,12 +1056,10 @@ static int erofs_show_options(struct seq_file *seq,= struct dentry *root) seq_puts(seq, ",dax=3Dnever"); if (erofs_is_fileio_mode(sbi) && test_opt(opt, DIRECT_IO)) seq_puts(seq, ",directio"); -#ifdef CONFIG_EROFS_FS_ONDEMAND if (sbi->fsid) seq_printf(seq, ",fsid=3D%s", sbi->fsid); if (sbi->domain_id) seq_printf(seq, ",domain_id=3D%s", sbi->domain_id); -#endif if (sbi->dif0.fsoff) seq_printf(seq, ",fsoffset=3D%llu", sbi->dif0.fsoff); return 0; --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout04.his.huawei.com (canpmsgout04.his.huawei.com [113.46.200.219]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFBC43168E8; Wed, 31 Dec 2025 09:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.219 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172453; cv=none; b=kqdixYC5aQYHZvJwG0HQ9TURGgHcsddakIvM4hOXyPfd1V01LCHgdxBNYX9uvhfp2r3st2OJ6oNjbFdKEvjeDcp7bpJsNhvSgOshrGAVbNz8kYAQIlaoozJCucfFjf0g9+XxfRej5ZjhG2sXkqujfCVOq/NqB4NJW0GrDt4Xbjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172453; c=relaxed/simple; bh=a0QqvNrYPFubruQ67FnAc/cXqz6GClwn7y8Iuu5836M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K9Fk5HbAOJvTgJBYS7jkcC8xC6yo7qGG4O/3BFL6vy6C2gQM7lqhSL+TfmFvyC6TWwrxd6WQrPgmCHwsKtLOYxur0V++2th0DAjeXKmscWn9vLOkPVeyPavDgEphYFoLkjoyw5Suupjq4ZxfpgMnpvphKhN77IWbi1bdb8PqDTA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=1l9pXQ8O; arc=none smtp.client-ip=113.46.200.219 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="1l9pXQ8O" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=XRtplRdiz3jA8mIDc2U5PapZgM3+0TDyFLKmWDJnWKc=; b=1l9pXQ8OWpG4F0zQwO1oq16Xlku9bWYwrh3YcrmWVt/alt/7fdQG6WpzP0aDa0BrkLdC2ePXU 6SziaAoDOJL+rJqzy/DQbxjJm6GVKUk8dxpffz7yU7k8hWLiysQ/DRdkARZqEbJ0QY5u0dfAKAC nku42zrI6o1yMjt1821Rlv8= Received: from mail.maildlp.com (unknown [172.19.162.140]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4dh41h2VYYz1prKH; Wed, 31 Dec 2025 17:10:48 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 7999420104; Wed, 31 Dec 2025 17:14:01 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:14:00 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 07/10] erofs: introduce the page cache share feature Date: Wed, 31 Dec 2025 09:01:15 +0000 Message-ID: <20251231090118.541061-8-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo 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 Signed-off-by: Hongbo Li --- Documentation/filesystems/erofs.rst | 5 + fs/erofs/Makefile | 1 + fs/erofs/internal.h | 31 +++++ fs/erofs/ishare.c | 170 ++++++++++++++++++++++++++++ fs/erofs/super.c | 55 ++++++++- fs/erofs/xattr.c | 34 ++++++ fs/erofs/xattr.h | 3 + 7 files changed, 297 insertions(+), 2 deletions(-) create mode 100644 fs/erofs/ishare.c diff --git a/Documentation/filesystems/erofs.rst b/Documentation/filesystem= s/erofs.rst index 08194f194b94..27d3caa3c73c 100644 --- a/Documentation/filesystems/erofs.rst +++ b/Documentation/filesystems/erofs.rst @@ -128,7 +128,12 @@ device=3D%s Specify a path to an extra de= vice to be used together. fsid=3D%s Specify a filesystem image ID for Fscache back-en= d. domain_id=3D%s Specify a domain ID in fscache mode so that diffe= rent images with the same blobs under a given domain ID can sha= re storage. + Also used for inode page sharing mode which defines= a sharing + domain. fsoffset=3D%llu Specify block-aligned filesystem offset for the p= rimary device. +inode_share Enable inode page sharing for this filesystem. Ino= des with + identical content within the same domain ID can sha= re the + page cache. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 Sysfs Entries diff --git a/fs/erofs/Makefile b/fs/erofs/Makefile index 549abc424763..a80e1762b607 100644 --- a/fs/erofs/Makefile +++ b/fs/erofs/Makefile @@ -10,3 +10,4 @@ erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) +=3D decompressor_zstd.o erofs-$(CONFIG_EROFS_FS_ZIP_ACCEL) +=3D decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) +=3D fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) +=3D fscache.o +erofs-$(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) +=3D ishare.o diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index ec79e8b44d3b..6ef1cdd9d651 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -179,6 +179,7 @@ struct erofs_sb_info { #define EROFS_MOUNT_DAX_ALWAYS 0x00000040 #define EROFS_MOUNT_DAX_NEVER 0x00000080 #define EROFS_MOUNT_DIRECT_IO 0x00000100 +#define EROFS_MOUNT_INODE_SHARE 0x00000200 =20 #define clear_opt(opt, option) ((opt)->mount_opt &=3D ~EROFS_MOUNT_##optio= n) #define set_opt(opt, option) ((opt)->mount_opt |=3D EROFS_MOUNT_##option) @@ -269,6 +270,11 @@ static inline u64 erofs_nid_to_ino64(struct erofs_sb_i= nfo *sbi, erofs_nid_t nid) /* default readahead size of directories */ #define EROFS_DIR_RA_BYTES 16384 =20 +struct erofs_inode_fingerprint { + u8 *opaque; + int size; +}; + struct erofs_inode { erofs_nid_t nid; =20 @@ -304,6 +310,18 @@ struct erofs_inode { }; #endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + struct list_head ishare_list; + union { + /* for each anon shared inode */ + struct { + struct erofs_inode_fingerprint fingerprint; + spinlock_t ishare_lock; + }; + /* for each real inode */ + struct inode *sharedinode; + }; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; }; @@ -410,6 +428,7 @@ extern const struct inode_operations erofs_dir_iops; =20 extern const struct file_operations erofs_file_fops; extern const struct file_operations erofs_dir_fops; +extern const struct file_operations erofs_ishare_fops; =20 extern const struct iomap_ops z_erofs_iomap_report_ops; =20 @@ -541,6 +560,18 @@ static inline struct bio *erofs_fscache_bio_alloc(stru= ct erofs_map_dev *mdev) { static inline void erofs_fscache_submit_bio(struct bio *bio) {} #endif =20 +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +int __init erofs_init_ishare(void); +void erofs_exit_ishare(void); +bool erofs_ishare_fill_inode(struct inode *inode); +void erofs_ishare_free_inode(struct inode *inode); +#else +static inline int erofs_init_ishare(void) { return 0; } +static inline void erofs_exit_ishare(void) {} +static inline bool erofs_ishare_fill_inode(struct inode *inode) { return f= alse; } +static inline void erofs_ishare_free_inode(struct inode *inode) {} +#endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE + long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); long erofs_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c new file mode 100644 index 000000000000..e93d379d4a3a --- /dev/null +++ b/fs/erofs/ishare.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2024, Alibaba Cloud + */ +#include +#include +#include "internal.h" +#include "xattr.h" + +#include "../internal.h" + +static struct vfsmount *erofs_ishare_mnt; + +static int erofs_ishare_iget5_eq(struct inode *inode, void *data) +{ + struct erofs_inode_fingerprint *fp1 =3D &EROFS_I(inode)->fingerprint; + struct erofs_inode_fingerprint *fp2 =3D data; + + return fp1->size =3D=3D fp2->size && + !memcmp(fp1->opaque, fp2->opaque, fp2->size); +} + +static int erofs_ishare_iget5_set(struct inode *inode, void *data) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + + vi->fingerprint =3D *(struct erofs_inode_fingerprint *)data; + INIT_LIST_HEAD(&vi->ishare_list); + spin_lock_init(&vi->ishare_lock); + return 0; +} + +bool erofs_ishare_fill_inode(struct inode *inode) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(inode->i_sb); + struct erofs_inode *vi =3D EROFS_I(inode); + struct erofs_inode_fingerprint fp; + struct inode *sharedinode; + unsigned long hash; + + if (!test_opt(&sbi->opt, INODE_SHARE)) + return false; + (void)erofs_xattr_fill_ishare_fp(&fp, inode, sbi->domain_id); + if (!fp.size) + return false; + hash =3D xxh32(fp.opaque, fp.size, 0); + sharedinode =3D iget5_locked(erofs_ishare_mnt->mnt_sb, hash, + erofs_ishare_iget5_eq, erofs_ishare_iget5_set, + &fp); + if (!sharedinode) { + kfree(fp.opaque); + return false; + } + + vi->sharedinode =3D sharedinode; + if (inode_state_read_once(sharedinode) & I_NEW) { + if (erofs_inode_is_data_compressed(vi->datalayout)) + sharedinode->i_mapping->a_ops =3D &z_erofs_aops; + else + sharedinode->i_mapping->a_ops =3D &erofs_aops; + sharedinode->i_mode =3D vi->vfs_inode.i_mode; + sharedinode->i_size =3D vi->vfs_inode.i_size; + unlock_new_inode(sharedinode); + } else { + kfree(fp.opaque); + } + INIT_LIST_HEAD(&vi->ishare_list); + spin_lock(&EROFS_I(sharedinode)->ishare_lock); + list_add(&vi->ishare_list, &EROFS_I(sharedinode)->ishare_list); + spin_unlock(&EROFS_I(sharedinode)->ishare_lock); + return true; +} + +void erofs_ishare_free_inode(struct inode *inode) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + struct inode *sharedinode =3D vi->sharedinode; + + if (!sharedinode) + return; + spin_lock(&EROFS_I(sharedinode)->ishare_lock); + list_del(&vi->ishare_list); + spin_unlock(&EROFS_I(sharedinode)->ishare_lock); + iput(sharedinode); + vi->sharedinode =3D NULL; +} + +static int erofs_ishare_file_open(struct inode *inode, struct file *file) +{ + struct inode *sharedinode; + struct file *realfile; + + sharedinode =3D EROFS_I(inode)->sharedinode; + realfile =3D alloc_empty_backing_file(O_RDONLY|O_NOATIME, current_cred()); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); + ihold(sharedinode); + realfile->f_op =3D &erofs_file_fops; + realfile->f_inode =3D sharedinode; + realfile->f_mapping =3D sharedinode->i_mapping; + path_get(&file->f_path); + backing_file_set_user_path(realfile, &file->f_path); + + file_ra_state_init(&realfile->f_ra, file->f_mapping); + realfile->private_data =3D EROFS_I(inode); + file->private_data =3D realfile; + return 0; +} + +static int erofs_ishare_file_release(struct inode *inode, struct file *fil= e) +{ + struct file *realfile =3D file->private_data; + + iput(realfile->f_inode); + fput(realfile); + file->private_data =3D NULL; + return 0; +} + +static ssize_t erofs_ishare_file_read_iter(struct kiocb *iocb, + struct iov_iter *to) +{ + struct file *realfile =3D iocb->ki_filp->private_data; + struct kiocb dedup_iocb; + ssize_t nread; + + if (!iov_iter_count(to)) + return 0; + + /* fallback to the original file in DIRECT mode */ + if (iocb->ki_flags & IOCB_DIRECT) + realfile =3D iocb->ki_filp; + + kiocb_clone(&dedup_iocb, iocb, realfile); + nread =3D filemap_read(&dedup_iocb, to, 0); + iocb->ki_pos =3D dedup_iocb.ki_pos; + file_accessed(iocb->ki_filp); + return nread; +} + +static int erofs_ishare_mmap(struct file *file, struct vm_area_struct *vma) +{ + struct file *realfile =3D file->private_data; + + vma_set_file(vma, realfile); + return generic_file_readonly_mmap(file, vma); +} + +const struct file_operations erofs_ishare_fops =3D { + .open =3D erofs_ishare_file_open, + .llseek =3D generic_file_llseek, + .read_iter =3D erofs_ishare_file_read_iter, + .mmap =3D erofs_ishare_mmap, + .release =3D erofs_ishare_file_release, + .get_unmapped_area =3D thp_get_unmapped_area, + .splice_read =3D filemap_splice_read, +}; + +int __init erofs_init_ishare(void) +{ + erofs_ishare_mnt =3D kern_mount(&erofs_anon_fs_type); + if (IS_ERR(erofs_ishare_mnt)) + return PTR_ERR(erofs_ishare_mnt); + return 0; +} + +void erofs_exit_ishare(void) +{ + kern_unmount(erofs_ishare_mnt); +} diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 960da62636ad..6489241c5e42 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -396,6 +396,7 @@ static void erofs_default_options(struct erofs_sb_info = *sbi) enum { Opt_user_xattr, Opt_acl, Opt_cache_strategy, Opt_dax, Opt_dax_enum, Opt_device, Opt_fsid, Opt_domain_id, Opt_directio, Opt_fsoffset, + Opt_inode_share, }; =20 static const struct constant_table erofs_param_cache_strategy[] =3D { @@ -423,6 +424,7 @@ static const struct fs_parameter_spec erofs_fs_paramete= rs[] =3D { fsparam_string("domain_id", Opt_domain_id), fsparam_flag_no("directio", Opt_directio), fsparam_u64("fsoffset", Opt_fsoffset), + fsparam_flag("inode_share", Opt_inode_share), {} }; =20 @@ -551,6 +553,14 @@ static int erofs_fc_parse_param(struct fs_context *fc, case Opt_fsoffset: sbi->dif0.fsoff =3D result.uint_64; break; +#if defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) + case Opt_inode_share: + set_opt(&sbi->opt, INODE_SHARE); +#else + case Opt_inode_share: + errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name); +#endif + break; } return 0; } @@ -649,6 +659,16 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) sb->s_maxbytes =3D MAX_LFS_FILESIZE; sb->s_op =3D &erofs_sops; =20 + if (sbi->domain_id && + (!sbi->fsid && !test_opt(&sbi->opt, INODE_SHARE))) { + errorfc(fc, "domain_id should be with fsid or inode_share option"); + return -EINVAL; + } + if (test_opt(&sbi->opt, DAX_ALWAYS) && test_opt(&sbi->opt, INODE_SHARE)) { + errorfc(fc, "dax is not allowed when inode_share is on"); + return -EINVAL; + } + sbi->blkszbits =3D PAGE_SHIFT; if (!sb->s_bdev) { /* @@ -948,10 +968,31 @@ static struct file_system_type erofs_fs_type =3D { }; MODULE_ALIAS_FS("erofs"); =20 -#if defined(CONFIG_EROFS_FS_ONDEMAND) +#if defined(CONFIG_EROFS_FS_ONDEMAND) || defined(CONFIG_EROFS_FS_PAGE_CACH= E_SHARE) +static void erofs_free_anon_inode(struct inode *inode) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + kfree(vi->fingerprint.opaque); +#endif + kmem_cache_free(erofs_inode_cachep, vi); +} + +static const struct super_operations erofs_anon_sops =3D { + .alloc_inode =3D erofs_alloc_inode, + .free_inode =3D erofs_free_anon_inode, +}; + static int erofs_anon_init_fs_context(struct fs_context *fc) { - return init_pseudo(fc, EROFS_SUPER_MAGIC) ? 0 : -ENOMEM; + struct pseudo_fs_context *ctx; + + ctx =3D init_pseudo(fc, EROFS_SUPER_MAGIC); + if (ctx) + ctx->ops =3D &erofs_anon_sops; + + return ctx ? 0 : -ENOMEM; } =20 struct file_system_type erofs_anon_fs_type =3D { @@ -986,6 +1027,10 @@ static int __init erofs_module_init(void) if (err) goto sysfs_err; =20 + err =3D erofs_init_ishare(); + if (err) + goto ishare_err; + err =3D register_filesystem(&erofs_fs_type); if (err) goto fs_err; @@ -993,6 +1038,8 @@ static int __init erofs_module_init(void) return 0; =20 fs_err: + erofs_exit_ishare(); +ishare_err: erofs_exit_sysfs(); sysfs_err: z_erofs_exit_subsystem(); @@ -1010,6 +1057,7 @@ static void __exit erofs_module_exit(void) /* Ensure all RCU free inodes / pclusters are safe to be destroyed. */ rcu_barrier(); =20 + erofs_exit_ishare(); erofs_exit_sysfs(); z_erofs_exit_subsystem(); erofs_exit_shrinker(); @@ -1062,6 +1110,8 @@ static int erofs_show_options(struct seq_file *seq, s= truct dentry *root) seq_printf(seq, ",domain_id=3D%s", sbi->domain_id); if (sbi->dif0.fsoff) seq_printf(seq, ",fsoffset=3D%llu", sbi->dif0.fsoff); + if (test_opt(opt, INODE_SHARE)) + seq_puts(seq, ",inode_share"); return 0; } =20 @@ -1072,6 +1122,7 @@ static void erofs_evict_inode(struct inode *inode) dax_break_layout_final(inode); #endif =20 + erofs_ishare_free_inode(inode); truncate_inode_pages_final(&inode->i_data); clear_inode(inode); } diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index ae61f20cb861..ec7a0f5dc172 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -577,3 +577,37 @@ struct posix_acl *erofs_get_acl(struct inode *inode, i= nt type, bool rcu) return acl; } #endif + +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE +int erofs_xattr_fill_ishare_fp(struct erofs_inode_fingerprint *fp, + struct inode *inode, const char *domain_id) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(inode->i_sb); + struct erofs_xattr_prefix_item *prefix; + const char *infix; + int valuelen, base_index, domainlen; + + fp->size =3D 0; + if (!erofs_sb_has_ishare_xattrs(sbi)) + return 0; + prefix =3D sbi->xattr_prefixes + sbi->ishare_xattr_prefix_id; + infix =3D prefix->prefix->infix; + base_index =3D prefix->prefix->base_index; + valuelen =3D erofs_getxattr(inode, base_index, infix, NULL, 0); + if (valuelen <=3D 0 || valuelen > (1 << sbi->blkszbits)) + return -EFSCORRUPTED; + domainlen =3D domain_id ? strlen(domain_id) : 0; + fp->opaque =3D kmalloc(valuelen + domainlen, GFP_KERNEL); + if (!fp->opaque) + return -ENOMEM; + if (valuelen !=3D erofs_getxattr(inode, base_index, infix, + fp->opaque, valuelen)) { + kfree(fp->opaque); + fp->opaque =3D NULL; + return -EFSCORRUPTED; + } + memcpy(fp->opaque + valuelen, domain_id, domainlen); + fp->size =3D valuelen + domainlen; + return 0; +} +#endif diff --git a/fs/erofs/xattr.h b/fs/erofs/xattr.h index 6317caa8413e..8656ec8d931e 100644 --- a/fs/erofs/xattr.h +++ b/fs/erofs/xattr.h @@ -67,4 +67,7 @@ struct posix_acl *erofs_get_acl(struct inode *inode, int = type, bool rcu); #define erofs_get_acl (NULL) #endif =20 +int erofs_xattr_fill_ishare_fp(struct erofs_inode_fingerprint *fp, + struct inode *inode, const char *domain_id); + #endif --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout01.his.huawei.com (canpmsgout01.his.huawei.com [113.46.200.216]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFA7631B111; Wed, 31 Dec 2025 09:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.216 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172455; cv=none; b=fua37b49f2qTWpe6TnQrVFyS/RqoPyXXKHY4BJMQd2mb3M5AzV9hkM2GzSazOsUJzt5pak8Lqk3OKuO7S941fJed8IdDbP21fh/ghsgks3+4Muvppd8KxNPRQ+tjaYso1VJ6nIIGzPQ1wF2YUDD+qsyOt36tGM1RnykUlcBYP48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172455; c=relaxed/simple; bh=FDdlPmjWR956Laimcxh6D73LlWAcNyLae7aOSKhM9go=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=snOgjSI4/JV7i5cay+4fX2U5vtUbwRweJfesxLNZXa2/+k8G44RjeauvMLF94W8YXaS3mP1LsUzklMfHp/y/OZMje2rlALn2bH6pidkYleLZ15jYnkwvwAThb3CCWGmyP5Z3GyLmBdsHe0l06bTjEBbul6uHQx0YaEBgUO0lSF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=YtLVKg9Q; arc=none smtp.client-ip=113.46.200.216 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="YtLVKg9Q" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=blCE/MmPqYfBuawXGsDKLTcGDcPKVdlLgTzlVCH0Olo=; b=YtLVKg9Q5uIyIYzsa3dZkLnOI6NofGHL8T43zgDBlYC8BXKDd01gO099H4/FvHdwjUmmsLE+z XhO1DAUrO9tQoNCfpPJFh7wqSecMCulnK7h/HeKetdiPq8FRb+97ag3O99rR6S+oAy3aBbmpatH 61tOpQjsPtVdscbTkYqGW6c= Received: from mail.maildlp.com (unknown [172.19.162.223]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4dh42V1bPpz1T4FV; Wed, 31 Dec 2025 17:11:30 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 099FD4056E; Wed, 31 Dec 2025 17:14:02 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:14:01 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 08/10] erofs: support unencoded inodes for page cache share Date: Wed, 31 Dec 2025 09:01:16 +0000 Message-ID: <20251231090118.541061-9-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" This patch adds inode page cache sharing functionality for unencoded files. I conducted experiments in the container environment. Below is the memory usage for reading all files in two different minor versions of container images: +-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 241 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 163 | 33% | +-------------------+------------------+-------------+---------------+ | | No | 872 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 630 | 28% | +-------------------+------------------+-------------+---------------+ | | No | 2771 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 2340 | 16% | +-------------------+------------------+-------------+---------------+ | | No | 926 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 735 | 21% | +-------------------+------------------+-------------+---------------+ | | No | 390 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 219 | 44% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 924 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 474 | 49% | +-------------------+------------------+-------------+---------------+ Additionally, the table below shows the runtime memory usage of the container: +-------------------+------------------+-------------+---------------+ | Image | Page Cache Share | Memory (MB) | Memory | | | | | Reduction (%) | +-------------------+------------------+-------------+---------------+ | | No | 35 | - | | redis +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 28 | 20% | +-------------------+------------------+-------------+---------------+ | | No | 149 | - | | postgres +------------------+-------------+---------------+ | 16.1 & 16.2 | Yes | 95 | 37% | +-------------------+------------------+-------------+---------------+ | | No | 1028 | - | | tensorflow +------------------+-------------+---------------+ | 2.11.0 & 2.11.1 | Yes | 930 | 10% | +-------------------+------------------+-------------+---------------+ | | No | 155 | - | | mysql +------------------+-------------+---------------+ | 8.0.11 & 8.0.12 | Yes | 132 | 15% | +-------------------+------------------+-------------+---------------+ | | No | 25 | - | | nginx +------------------+-------------+---------------+ | 7.2.4 & 7.2.5 | Yes | 20 | 20% | +-------------------+------------------+-------------+---------------+ | tomcat | No | 186 | - | | 10.1.25 & 10.1.26 +------------------+-------------+---------------+ | | Yes | 98 | 48% | +-------------------+------------------+-------------+---------------+ Co-developed-by: Hongzhen Luo Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/data.c | 30 +++++++++++++++++++++++------- fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 6 ++++++ fs/erofs/ishare.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 71e23d91123d..5fc8e3ce0d9e 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -269,6 +269,7 @@ void erofs_onlinefolio_end(struct folio *folio, int err= , bool dirty) struct erofs_iomap_iter_ctx { struct page *page; void *base; + struct inode *realinode; }; =20 static int erofs_iomap_begin(struct inode *inode, loff_t offset, loff_t le= ngth, @@ -276,14 +277,15 @@ static int erofs_iomap_begin(struct inode *inode, lof= f_t offset, loff_t length, { struct iomap_iter *iter =3D container_of(iomap, struct iomap_iter, iomap); struct erofs_iomap_iter_ctx *ctx =3D iter->private; - struct super_block *sb =3D inode->i_sb; + struct inode *realinode =3D ctx ? ctx->realinode : inode; + struct super_block *sb =3D realinode->i_sb; struct erofs_map_blocks map; struct erofs_map_dev mdev; int ret; =20 map.m_la =3D offset; map.m_llen =3D length; - ret =3D erofs_map_blocks(inode, &map); + ret =3D erofs_map_blocks(realinode, &map); if (ret < 0) return ret; =20 @@ -296,7 +298,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_= t offset, loff_t length, return 0; } =20 - if (!(map.m_flags & EROFS_MAP_META) || !erofs_inode_in_metabox(inode)) { + if (!(map.m_flags & EROFS_MAP_META) || !erofs_inode_in_metabox(realinode)= ) { mdev =3D (struct erofs_map_dev) { .m_deviceid =3D map.m_deviceid, .m_pa =3D map.m_pa, @@ -322,7 +324,7 @@ static int erofs_iomap_begin(struct inode *inode, loff_= t offset, loff_t length, void *ptr; =20 ptr =3D erofs_read_metabuf(&buf, sb, map.m_pa, - erofs_inode_in_metabox(inode)); + erofs_inode_in_metabox(realinode)); if (IS_ERR(ptr)) return PTR_ERR(ptr); iomap->inline_data =3D ptr; @@ -379,30 +381,42 @@ int erofs_fiemap(struct inode *inode, struct fiemap_e= xtent_info *fieinfo, */ static int erofs_read_folio(struct file *file, struct folio *folio) { + struct inode *inode =3D folio_inode(folio); struct iomap_read_folio_ctx read_ctx =3D { .ops =3D &iomap_bio_read_ops, .cur_folio =3D folio, }; - struct erofs_iomap_iter_ctx iter_ctx =3D {}; + bool need_iput; + struct erofs_iomap_iter_ctx iter_ctx =3D { + .realinode =3D erofs_real_inode(inode, &need_iput), + }; =20 trace_erofs_read_folio(folio, true); =20 iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx); + if (need_iput) + iput(iter_ctx.realinode); return 0; } =20 static void erofs_readahead(struct readahead_control *rac) { + struct inode *inode =3D rac->mapping->host; struct iomap_read_folio_ctx read_ctx =3D { .ops =3D &iomap_bio_read_ops, .rac =3D rac, }; - struct erofs_iomap_iter_ctx iter_ctx =3D {}; + bool need_iput; + struct erofs_iomap_iter_ctx iter_ctx =3D { + .realinode =3D erofs_real_inode(inode, &need_iput), + }; =20 trace_erofs_readahead(rac->mapping->host, readahead_index(rac), readahead_count(rac), true); =20 iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx); + if (need_iput) + iput(iter_ctx.realinode); } =20 static sector_t erofs_bmap(struct address_space *mapping, sector_t block) @@ -423,7 +437,9 @@ static ssize_t erofs_file_read_iter(struct kiocb *iocb,= struct iov_iter *to) return dax_iomap_rw(iocb, to, &erofs_iomap_ops); #endif if ((iocb->ki_flags & IOCB_DIRECT) && inode->i_sb->s_bdev) { - struct erofs_iomap_iter_ctx iter_ctx =3D {}; + struct erofs_iomap_iter_ctx iter_ctx =3D { + .realinode =3D inode, + }; =20 return iomap_dio_rw(iocb, to, &erofs_iomap_ops, NULL, 0, &iter_ctx, 0); diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index bce98c845a18..8116738fe432 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -215,6 +215,10 @@ static int erofs_fill_inode(struct inode *inode) case S_IFREG: inode->i_op =3D &erofs_generic_iops; inode->i_fop =3D &erofs_file_fops; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + if (erofs_ishare_fill_inode(inode)) + inode->i_fop =3D &erofs_ishare_fops; +#endif break; case S_IFDIR: inode->i_op =3D &erofs_dir_iops; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index 6ef1cdd9d651..b02defbcdbfe 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -565,11 +565,17 @@ int __init erofs_init_ishare(void); void erofs_exit_ishare(void); bool erofs_ishare_fill_inode(struct inode *inode); void erofs_ishare_free_inode(struct inode *inode); +struct inode *erofs_real_inode(struct inode *inode, bool *need_iput); #else static inline int erofs_init_ishare(void) { return 0; } static inline void erofs_exit_ishare(void) {} static inline bool erofs_ishare_fill_inode(struct inode *inode) { return f= alse; } static inline void erofs_ishare_free_inode(struct inode *inode) {} +static inline struct inode *erofs_real_inode(struct inode *inode, bool *ne= ed_iput) +{ + *need_iput =3D false; + return inode; +} #endif // CONFIG_EROFS_FS_PAGE_CACHE_SHARE =20 long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c index e93d379d4a3a..b91f0ce412c0 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -11,6 +11,12 @@ =20 static struct vfsmount *erofs_ishare_mnt; =20 +static inline bool erofs_is_ishare_inode(struct inode *inode) +{ + /* assumed FS_ONDEMAND is excluded with FS_PAGE_CACHE_SHARE feature */ + return inode->i_sb->s_type =3D=3D &erofs_anon_fs_type; +} + static int erofs_ishare_iget5_eq(struct inode *inode, void *data) { struct erofs_inode_fingerprint *fp1 =3D &EROFS_I(inode)->fingerprint; @@ -156,6 +162,32 @@ const struct file_operations erofs_ishare_fops =3D { .splice_read =3D filemap_splice_read, }; =20 +struct inode *erofs_real_inode(struct inode *inode, bool *need_iput) +{ + struct erofs_inode *vi, *vi_share; + struct inode *realinode; + + *need_iput =3D false; + if (!erofs_is_ishare_inode(inode)) + return inode; + + vi_share =3D EROFS_I(inode); + spin_lock(&vi_share->ishare_lock); + /* fetch any one as real inode */ + DBG_BUGON(list_empty(&vi_share->ishare_list)); + list_for_each_entry(vi, &vi_share->ishare_list, ishare_list) { + realinode =3D igrab(&vi->vfs_inode); + if (realinode) { + *need_iput =3D true; + break; + } + } + spin_unlock(&vi_share->ishare_lock); + + DBG_BUGON(!realinode); + return realinode; +} + int __init erofs_init_ishare(void) { erofs_ishare_mnt =3D kern_mount(&erofs_anon_fs_type); --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout06.his.huawei.com (canpmsgout06.his.huawei.com [113.46.200.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB7E031A54C; Wed, 31 Dec 2025 09:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172453; cv=none; b=SpWL4Dzak6pxbkg4aFV2EeWmP/Hu86AmHoqVEuNH60eHq7EfUiSD5elQnfEa3WRk+3SMvRRZvt7E9yASZMnkzw5d8gbYzys5sHURf60vauJiUWeI/cPyO60kc3CErQ8H68uq7OxsVWAoXvhQNtu58OnPoDkJ35DP5Z56ocGZCHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172453; c=relaxed/simple; bh=78DH+j+x3P9qyj0ZcYKGVjdZblPl5ZHKAV8AZKMu7V4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ue0y/JJoY07w8he0qp0H4pbmeBKVLXV9G89cd8TjWTmJ1FsRww9gvyq6QfksC8P2+KDfO5rYloZX/CIW6tkfBwbFmWI8GEi3IVAHN/zdbBFtvc8o8WP8kCippVdSB2+pakx/Y5jnRWWpYvCIYtaYlFEpBJxblGGyYo3d0FsdJwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=IlA3NzPR; arc=none smtp.client-ip=113.46.200.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="IlA3NzPR" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=CV6/Y+pgopddex/1nQUVVxg9kFgB/FWJT+yu9bxaR4s=; b=IlA3NzPRr2/WRpzKhfXsB0X7lTw4dVqWf0JoKrh6H4uyv2gtI7Mog1RDhi/bDL2CChb49P+lj ZiS4qWldVfzz2fvMfYhs68jNDVpFFpBh0FyPxQx82qhMzWiD/GA9420s8Z75VJLhwZON+yNQtYS eC6kHRhkpGxPWGc0mqciP/w= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4dh41l04nXzRhR8; Wed, 31 Dec 2025 17:10:51 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 79BA24056B; Wed, 31 Dec 2025 17:14:02 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:14:01 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 09/10] erofs: support compressed inodes for page cache share Date: Wed, 31 Dec 2025 09:01:17 +0000 Message-ID: <20251231090118.541061-10-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo This patch adds page cache sharing functionality for compressed inodes. Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li --- fs/erofs/zdata.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 65da21504632..2697c703a4c4 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -493,7 +493,8 @@ enum z_erofs_pclustermode { }; =20 struct z_erofs_frontend { - struct inode *const inode; + struct inode *inode; + struct inode *sharedinode; struct erofs_map_blocks map; struct z_erofs_bvec_iter biter; =20 @@ -508,8 +509,8 @@ struct z_erofs_frontend { unsigned int icur; }; =20 -#define Z_EROFS_DEFINE_FRONTEND(fe, i, ho) struct z_erofs_frontend fe =3D = { \ - .inode =3D i, .head =3D Z_EROFS_PCLUSTER_TAIL, \ +#define Z_EROFS_DEFINE_FRONTEND(fe, i, si, ho) struct z_erofs_frontend fe = =3D { \ + .inode =3D i, .sharedinode =3D si, .head =3D Z_EROFS_PCLUSTER_TAIL, \ .mode =3D Z_EROFS_PCLUSTER_FOLLOWED, .headoffset =3D ho } =20 static bool z_erofs_should_alloc_cache(struct z_erofs_frontend *fe) @@ -1866,7 +1867,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_= frontend *f, pgoff_t index =3D cur >> PAGE_SHIFT; struct folio *folio; =20 - folio =3D erofs_grab_folio_nowait(inode->i_mapping, index); + folio =3D erofs_grab_folio_nowait(f->sharedinode->i_mapping, index); if (!IS_ERR_OR_NULL(folio)) { if (folio_test_uptodate(folio)) folio_unlock(folio); @@ -1883,8 +1884,10 @@ static void z_erofs_pcluster_readmore(struct z_erofs= _frontend *f, =20 static int z_erofs_read_folio(struct file *file, struct folio *folio) { - struct inode *const inode =3D folio->mapping->host; - Z_EROFS_DEFINE_FRONTEND(f, inode, folio_pos(folio)); + struct inode *const sharedinode =3D folio->mapping->host; + bool need_iput; + struct inode *realinode =3D erofs_real_inode(sharedinode, &need_iput); + Z_EROFS_DEFINE_FRONTEND(f, realinode, sharedinode, folio_pos(folio)); int err; =20 trace_erofs_read_folio(folio, false); @@ -1896,23 +1899,28 @@ static int z_erofs_read_folio(struct file *file, st= ruct folio *folio) /* if some pclusters are ready, need submit them anyway */ err =3D z_erofs_runqueue(&f, 0) ?: err; if (err && err !=3D -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); =20 erofs_put_metabuf(&f.map.buf); erofs_release_pages(&f.pagepool); + + if (need_iput) + iput(realinode); return err; } =20 static void z_erofs_readahead(struct readahead_control *rac) { - struct inode *const inode =3D rac->mapping->host; - Z_EROFS_DEFINE_FRONTEND(f, inode, readahead_pos(rac)); + struct inode *const sharedinode =3D rac->mapping->host; + bool need_iput; + struct inode *realinode =3D erofs_real_inode(sharedinode, &need_iput); + Z_EROFS_DEFINE_FRONTEND(f, realinode, sharedinode, readahead_pos(rac)); unsigned int nrpages =3D readahead_count(rac); struct folio *head =3D NULL, *folio; int err; =20 - 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 =3D readahead_folio(rac))) { folio->private =3D head; @@ -1926,8 +1934,8 @@ static void z_erofs_readahead(struct readahead_contro= l *rac) =20 err =3D z_erofs_scan_folio(&f, folio, true); if (err && err !=3D -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); @@ -1935,6 +1943,9 @@ static void z_erofs_readahead(struct readahead_contro= l *rac) (void)z_erofs_runqueue(&f, nrpages); erofs_put_metabuf(&f.map.buf); erofs_release_pages(&f.pagepool); + + if (need_iput) + iput(realinode); } =20 const struct address_space_operations z_erofs_aops =3D { --=20 2.22.0 From nobody Sat Feb 7 05:14:45 2026 Received: from canpmsgout05.his.huawei.com (canpmsgout05.his.huawei.com [113.46.200.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D04303191BA; Wed, 31 Dec 2025 09:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.220 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172449; cv=none; b=Fmjw81AJjhc3s4CKvDjma5APdEfR77B0drQOSNExLCOD2+BfuC9v/zUNy1TypOxLcpMeUrEhlZfW9K3E1QogNwzmBuv5I4Z9uwUvfr95BMCXuL9iI0oP+mHzMBE60COIl0oYEPISO3yORKJRDBmZAyJF2kbCSg5mSy0HNjzCo/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767172449; c=relaxed/simple; bh=Z1+mrHcVx+KTT4EB306qKfgW24bF1dSwWLrK3KG7ALQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PWdAAONRQ1IPuAqK7ZHSHMU0ykyV5xH/JBf6aFw2DPnc+cefmEYr75IZR9/r07pY1aL7OEyEKn80VEXh4Egp3Sck05RKa9PiyNPdaDV9N6hXYZI4csvkHP+tBQ5fKZaQb566zRgxVw53n0f1XpkxFMHhQ6QGg9ePcCFq0BpJQuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=Lr6wWqp9; arc=none smtp.client-ip=113.46.200.220 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="Lr6wWqp9" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=NTdhokYX3kI07kKshOUNPjp2sz5Cl0rGRESoWXdC/s8=; b=Lr6wWqp9bpNPnS+wDXjw2P7VdC7omvQxMxE0x7eBdXMprgWXOFhzZLXykT28pHIIv/3WwPjbI N3WGGdkh+znXVXgDYMgYGBR0JnfzjpNsbmgLLRJbKRaBJDGyDfBJYBxBYm+UkCXPLW7P0IXC1z7 D2hptI7JmQbi3TlXW1KZkQ4= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4dh41p4l7Cz12LDq; Wed, 31 Dec 2025 17:10:54 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 004684056A; Wed, 31 Dec 2025 17:14:03 +0800 (CST) Received: from huawei.com (10.67.174.162) by kwepemr500015.china.huawei.com (7.202.195.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Dec 2025 17:14:02 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v12 10/10] erofs: implement .fadvise for page cache share Date: Wed, 31 Dec 2025 09:01:18 +0000 Message-ID: <20251231090118.541061-11-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251231090118.541061-1-lihongbo22@huawei.com> References: <20251231090118.541061-1-lihongbo22@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo This patch implements the .fadvise interface for page cache share. Similar to overlayfs, it drops those clean, unused pages through vfs_fadvise(). Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li Reviewed-by: Gao Xiang --- fs/erofs/ishare.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c index b91f0ce412c0..2b7660d7e9d4 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -152,6 +152,13 @@ static int erofs_ishare_mmap(struct file *file, struct= vm_area_struct *vma) return generic_file_readonly_mmap(file, vma); } =20 +static int erofs_ishare_fadvise(struct file *file, loff_t offset, + loff_t len, int advice) +{ + return vfs_fadvise((struct file *)file->private_data, + offset, len, advice); +} + const struct file_operations erofs_ishare_fops =3D { .open =3D erofs_ishare_file_open, .llseek =3D generic_file_llseek, @@ -160,6 +167,7 @@ const struct file_operations erofs_ishare_fops =3D { .release =3D erofs_ishare_file_release, .get_unmapped_area =3D thp_get_unmapped_area, .splice_read =3D filemap_splice_read, + .fadvise =3D erofs_ishare_fadvise, }; =20 struct inode *erofs_real_inode(struct inode *inode, bool *need_iput) --=20 2.22.0