From nobody Sun Feb 8 15:37:37 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 6C09019D8BC; Fri, 9 Jan 2026 03:14:55 +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=1767928498; cv=none; b=q65E/xrOTL2D/WTvvXGqid4vyp/EQhZAhS8yUR9LnzsNnhDfQ6ceB7tWmW519pjbQnAU6DDmjKVst//nRH+IZEwBw0q6xkSbY9YQIbEMM4rHNOgN0n/4/0R+oiFQ0XMpv5Kl8ChJ4yiA+X0hrI3eJ/xwT/j7WJLchTZ9XoGu4PA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928498; c=relaxed/simple; bh=n0CYApCMSTPET0JshPYELMjqMo0Sh6yI6KkP6p9i+R0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h2Xp0BXTQvdZdO24gE/HpcBwAoFoxxZ/FJ2Mz97ogz8gapJKXrRuj4YHC59f4EdGyXQNRVqJmehq0I86hGol8al1rxZGajjfbM1HoYwF/NX/SioADHvjKx4QsIbj/MJPuRCxzc+rYhK4boEDDKPIV0RKy4yEpR8D3alg4QMy2rw= 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.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="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.104]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4dnRcV3CRwz1T4qW; Fri, 9 Jan 2026 11:11:06 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id E1F124056A; Fri, 9 Jan 2026 11:14:51 +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; Fri, 9 Jan 2026 11:14:51 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 01/10] iomap: stash iomap read ctx in the private field of iomap_iter Date: Fri, 9 Jan 2026 03:01:31 +0000 Message-ID: <20260109030140.594936-2-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 AEF473033C6; Fri, 9 Jan 2026 03:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; cv=none; b=QOwLJJnxDeWoZlfMJBx8+bSjnRlznJuxgx/QY2IChyxW2dyXNgY1MMP+bANJTdttfnjop1A/9BwEX4RDpZ4lg98eHpO8H/uceF+TWlzqdjTX/J0HZ6Z5ECkcKxHNsTk2w5mg6AL3nLaRoZzEG+Wb2qFMkT3ZzIbdaav/IPkMzp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; c=relaxed/simple; bh=GIG0iVEeSaYWSb9UOeG6A4TW0TzFA2hTW6WDyaPChPs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tzpHLpwDtJFVlJKgPc3a1+ZEeCNzai9AxjouvJ3oBZevspC+VKizdHc8Jcu2lZyedI2Du7E2Tixpn+ekc0NUKcoGPBkpzQbsCVyiL0I5AxcIsRnnBk5wUIPZbQ1Nw2ZqwuKTpbRt7lVlsvjkAoXAjoNUP6afO8q6dTDGdE8HEJ8= 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; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=hDPirPbx; arc=none smtp.client-ip=45.249.212.187 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=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 canpmsgout04.his.huawei.com (unknown [172.19.92.133]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgk4SNHz1BFrL; Fri, 9 Jan 2026 11:13:54 +0800 (CST) 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.162.144]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4dnRd2055Yz1prKH; Fri, 9 Jan 2026 11:11:34 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 6788840567; Fri, 9 Jan 2026 11:14:52 +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; Fri, 9 Jan 2026 11:14:51 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 02/10] erofs: hold read context in iomap_iter if needed Date: Fri, 9 Jan 2026 03:01:32 +0000 Message-ID: <20260109030140.594936-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 AEFC9322753; Fri, 9 Jan 2026 03:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; cv=none; b=GqpQzj1GFEEbCLgRXPKSuiayEfQ+afjYlldJAO3R+T9WvEH0mx8KIf9sPRUXVkzXKruACMT5kX1q+JpKMXRiIYKh6rhk4qyHpCBOqqDJ3EoWMZsgBsTGH7Cy1RvwCQpo9PFfBBkt1HXpOuwBcrbec0DUPR1wu9ydIovA5OhdnZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; c=relaxed/simple; bh=/DOP628ou57Yld7gMP4kYmxmunqIn78QOq3XPXhRUAY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AI6MG0B5zS+HcFt8/aaeXEt2+OzmIh1CnvHWOKjJEMnZ2H0QUXXy5jLE8ER5Ftmc1Rl7YRnMW3j4nuMb8JmFJVj37SZHfAZxHBJRZyuboiODZw4icDKkXC6wSBkKcXFaJmSDz4660+zUNedUNy/TE0In4NH6VP9fLtRM1x2aFMM= 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; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=aViTVgKb; arc=none smtp.client-ip=45.249.212.187 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=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 canpmsgout04.his.huawei.com (unknown [172.19.92.133]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgk4Rtsz1BFq8; Fri, 9 Jan 2026 11:13:54 +0800 (CST) 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.162.140]) by canpmsgout04.his.huawei.com (SkyGuard) with ESMTPS id 4dnRd23Hrxz1prKH; Fri, 9 Jan 2026 11:11:34 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id D6DAB2012A; Fri, 9 Jan 2026 11:14:52 +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; Fri, 9 Jan 2026 11:14:52 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 03/10] fs: Export alloc_empty_backing_file Date: Fri, 9 Jan 2026 03:01:33 +0000 Message-ID: <20260109030140.594936-4-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 A7DC333EB0A; Fri, 9 Jan 2026 03:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928514; cv=none; b=BNhZykL8zP/cTg3ufCXOwl15VLC9Up/M51wxLR+7ZMgrBPCiV+bBf80Wn8PXuRC9z3mCQxrSFcn4vqcXlGdNZKN9mQZJsAv+pbGm1+yHNAhFN8MnxcgfoU2qkpPpgtQ6TvGZSfTLh24bmxO32apx5e7V9ivgHlUTS8LHRY4xnP0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928514; c=relaxed/simple; bh=bLPyX55goz9UpKyTSsH/rsQVx9Lcd+68NmlbcIC2gHs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=K4wlQA7DUaaiC09KYY119Jmw1agxfmsr+IlhpMfI4pQfiDy6vhRgwKwUHjhdba42jwItT61F7jxIODbXvdp5ktF+QoQiYGxv0pQmYR+igswQNJcOP+2lWfcNazUBcYIKJi6x4Fg9dIHqXCxxNqIGRc0bnuuacqMEl5Pu6oOS+mE= 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; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=oJbF4d0t; arc=none smtp.client-ip=45.249.212.187 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=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 canpmsgout02.his.huawei.com (unknown [172.19.92.185]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgr2gp8z1BFq8; Fri, 9 Jan 2026 11:14:00 +0800 (CST) 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.162.197]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4dnRck2myNzcb3h; Fri, 9 Jan 2026 11:11:18 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 5ED5F40569; Fri, 9 Jan 2026 11:14:53 +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; Fri, 9 Jan 2026 11:14:52 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 04/10] erofs: decouple `struct erofs_anon_fs_type` Date: Fri, 9 Jan 2026 03:01:34 +0000 Message-ID: <20260109030140.594936-5-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 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 314321DE3B7; Fri, 9 Jan 2026 03:14:56 +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=1767928500; cv=none; b=Y8znf6s59LCcdCKaczGlcHwiAjIALMOCbSEsh1fRb5KE6eoYyHURRb/4V+ehXxjM08Ms3CnjeHtWLbGo1qTNGMW5qAce51yrmq/iNGl2MAxbEjlgqMuS85a1Zhh2D15dqMXabOANUoz/DVdlG1XMaFWhqJBb45OsqE3ujXc5QO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928500; c=relaxed/simple; bh=hjtjZM+/G2TpOF1N0I5N/LIijanDvM1LsENzKcdgQcE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ls5GoT1P359kgmt9hSqLLnzHhf/a3mRcZvxIhe4/HmSFg7q43BcHbI5O8Uhf6ahprqHc3/6JazhvtxKgmaxUcK3lRWTpkT1P2vsADvwkrsg3GEUhJtorr3Rc+xd/Xno9Nv9kx1sesP8Q2AZlMZqZayigOZX3kSSZDvomMr7tWYA= 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=VpLGGUGK; 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="VpLGGUGK" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=R7ApHnfNiBchhGXf8a8E/bOiMkaOH3q7V/YSP7S/uow=; b=VpLGGUGK+sRa0H7ow0v8gH347fWJZpEHkyBZ3bykf3XfoVbM3NPW+A+CBiyS787GwG0uZeAsy ruololEhaWwkPw29RrTxowpDFgVzkkLk4xJ2sTZwI9Q4ua+/fGcOQsKa6W7kUNaxDZdizCESOW3 zJu9mBU9EfwJBzx/UWj/eLE= Received: from mail.maildlp.com (unknown [172.19.163.127]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4dnRd61LL3zLlV4; Fri, 9 Jan 2026 11:11:38 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id EC58A40570; Fri, 9 Jan 2026 11:14:53 +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; Fri, 9 Jan 2026 11:14:53 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 05/10] erofs: support user-defined fingerprint name Date: Fri, 9 Jan 2026 03:01:35 +0000 Message-ID: <20260109030140.594936-6-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 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 7270026ED59; Fri, 9 Jan 2026 03:14:56 +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=1767928498; cv=none; b=IMlflhy1di2+43SqKGMmSBeVeCMmnR82WSFxJRhrvK+GJm3aLuZSBNB5l5wuHroD4O3jdFxEBlQT/fhBggNuAqwqHE51PFMinMTGeQYVpLfeK83V6vELxU5ixY3A8yoLv1RMxqTG/nLmMhk5ma+WSqnfzyUJOYLCPRTwimVCSYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928498; c=relaxed/simple; bh=S7RjyECHRDHNXIL1Al8k3RPWxT6vjUtdtCg4YK41Swo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c0O/4aERHlsTasDfFt1TFVSWbd/PH8TRJYfU1V6FB7uAgG2XTzdXb1wo6H5UunMeLZAgfDN5ex4+OcToiNGrnIJLttk8yASjQ1A6HTETMZ4WzlUoKCrpuvqn/fEV+HqGhDBLYk3W93oLw4+Qp+SBcZ+9dlCa6UiqJGfwu8gwKww= 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.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="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.162.144]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4dnRcy129wzpStD; Fri, 9 Jan 2026 11:11:30 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 671E440567; Fri, 9 Jan 2026 11:14:54 +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; Fri, 9 Jan 2026 11:14:53 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 06/10] erofs: support domain-specific page cache share Date: Fri, 9 Jan 2026 03:01:36 +0000 Message-ID: <20260109030140.594936-7-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Sun Feb 8 15:37:37 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 03DBD2EA482; Fri, 9 Jan 2026 03:14:56 +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=1767928499; cv=none; b=fbcoEEGq7KZTQ7SswdOY3/pnzbzIlk4YxY8+Joj6NaySCFMav3lyE5qozzvJT7wlUckPwIg6dGg5jI3d3WT4nC0MlEILRt602HYvRI93C0FJIDoM41GcA3zXYDBq4aT+ryeWqgYHS1HlkV33OJurknPyVtUluq9/kR96SXf6XpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928499; c=relaxed/simple; bh=1AXMMLgAtPonl9m3oopDutNN8HE2zlqaCKdJ7T40yt8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EWdxJoZqESYikKOSpE3s7qNMOrsRlLXmrbpKlY7cKQEj6XcQl4d9cP0vK1/frQcCRM6vBAmkC37SJbP2njb3MnRcaBq5WAlGmahJ18Xq1htod/lRRuRQk0Vfe/IQ7wnUNhD5gzGQRSjgTAkZ8Jhti/WTf0ot4SZq8y3U3Nyi4eo= 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=EIFY3rR1; 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="EIFY3rR1" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=4rNWRaSWfCHR+prXfxqoib9OwjF27m3Q22Nw2E9LXRI=; b=EIFY3rR1ngzIy1ZfnnUzh5Nb5YW20PGDOowjQ91cb0u4V2yS9+48SVHX7jspyLUl91ZpvhjYa KIJ4MZFf4MwpvtUy+l1r3ly+2iccbfPnX2d3VkHmikCdhOYEbqnX3CPpkXgDzq9AmLaqVOJ9KCJ aKBDVU58EG/GO767xSL1k2Q= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4dnRd61lmczRhTf; Fri, 9 Jan 2026 11:11:38 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id E5A784036C; Fri, 9 Jan 2026 11:14:54 +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; Fri, 9 Jan 2026 11:14:54 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 07/10] erofs: introduce the page cache share feature Date: Fri, 9 Jan 2026 03:01:37 +0000 Message-ID: <20260109030140.594936-8-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 | 161 ++++++++++++++++++++++++++++ fs/erofs/super.c | 53 ++++++++- fs/erofs/xattr.c | 33 ++++++ fs/erofs/xattr.h | 3 + 7 files changed, 285 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..56a955aaeb18 --- /dev/null +++ b/fs/erofs/ishare.c @@ -0,0 +1,161 @@ +// 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 (erofs_xattr_fill_inode_fingerprint(&fp, inode, sbi->domain_id)) + 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; + + if (file->f_flags & O_DIRECT) + return -EINVAL; + 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; + kiocb_clone(&dedup_iocb, iocb, realfile); + nread =3D filemap_read(&dedup_iocb, to, 0); + iocb->ki_pos =3D dedup_iocb.ki_pos; + 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); + return PTR_ERR_OR_ZERO(erofs_ishare_mnt); +} + +void erofs_exit_ishare(void) +{ + kern_unmount(erofs_ishare_mnt); +} diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 960da62636ad..a851b47ee579 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,13 @@ static int erofs_fc_parse_param(struct fs_context *fc, case Opt_fsoffset: sbi->dif0.fsoff =3D result.uint_64; break; + case Opt_inode_share: +#if defined(CONFIG_EROFS_FS_PAGE_CACHE_SHARE) + set_opt(&sbi->opt, INODE_SHARE); +#else + errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name); +#endif + break; } return 0; } @@ -649,6 +658,11 @@ 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 (test_opt(&sbi->opt, DAX_ALWAYS) && test_opt(&sbi->opt, INODE_SHARE)) { + errorfc(fc, "FSDAX is not allowed when inode_ishare is on"); + return -EINVAL; + } + sbi->blkszbits =3D PAGE_SHIFT; if (!sb->s_bdev) { /* @@ -719,6 +733,10 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) erofs_info(sb, "unsupported blocksize for DAX"); clear_opt(&sbi->opt, DAX_ALWAYS); } + if (test_opt(&sbi->opt, INODE_SHARE) && !erofs_sb_has_ishare_xattrs(sbi))= { + erofs_info(sb, "inode ishare is unavailable"); + clear_opt(&sbi->opt, INODE_SHARE); + } =20 sb->s_time_gran =3D 1; sb->s_xattr =3D erofs_xattr_handlers; @@ -948,10 +966,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 +1025,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 +1036,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 +1055,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 +1108,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 +1120,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..290acbf89fa6 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -577,3 +577,36 @@ 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_inode_fingerprint(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; + + if (!test_opt(&sbi->opt, INODE_SHARE)) + return -EOPNOTSUPP; + 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..bf75a580b8f1 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_inode_fingerprint(struct erofs_inode_fingerprint *fp, + struct inode *inode, const char *domain_id); + #endif --=20 2.22.0 From nobody Sun Feb 8 15:37:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 B38D732D7CC; Fri, 9 Jan 2026 03:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928516; cv=none; b=Uloi5CRZIjDeE6agbmPtibvS1fu2P5M08AFuz17ziN2UJh1aP+Q7Xgs4U832r9xwZA7tM1byg1qfDNuJL+E5yHqcsA8ucKzeCutgOc6TkNlmBs9rb9arjzrlra7VOICONlr9pI6+OTE+5sApu2kaUoGGgAflI4I1Rkc27KVOqVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928516; c=relaxed/simple; bh=UwWOsRUB24diKM8fkhiKMPltEPJ25+I84ZWvnq8H218=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=u3pSRnInIO3XwLdXtHcXxa74GtPQy7YwoCVdikD3uJ0boNVUk0cuDXsv4ueaSOubqjUTjgCp7yPVk9aiyWpUDqQelL6I55eCGJXdB2/ey4oX5XzaoztE7imOyoBm5B8J31MlRXo/LoovN6j4vJwqsc6oHI6P659zyvFUW7+Wn98= 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=IogXJGtj; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=IogXJGtj; arc=none smtp.client-ip=45.249.212.187 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="IogXJGtj"; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="IogXJGtj" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=9NLPhsZmaKC1PLCD0+wR2I0Skqm5KSrWZfV4a3ELOhM=; b=IogXJGtj2UIf88m+/UoBFPdej25EgyTEDQfUIe6QMMP0gM5n0200ZSU9YYAf40x/jkWAI3kx2 3uUFwoID/3OYGwnBKZGQGU6DXtmhQPf/lCzDGZgCSpkRNemUIayJL7g+GnBaHOqCXuGLlLudtqv lSbEFlwE5UBC0BCHZioQSqA= Received: from canpmsgout02.his.huawei.com (unknown [172.19.92.185]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgt36xNz1BFq8; Fri, 9 Jan 2026 11:14:02 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=9NLPhsZmaKC1PLCD0+wR2I0Skqm5KSrWZfV4a3ELOhM=; b=IogXJGtj2UIf88m+/UoBFPdej25EgyTEDQfUIe6QMMP0gM5n0200ZSU9YYAf40x/jkWAI3kx2 3uUFwoID/3OYGwnBKZGQGU6DXtmhQPf/lCzDGZgCSpkRNemUIayJL7g+GnBaHOqCXuGLlLudtqv lSbEFlwE5UBC0BCHZioQSqA= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4dnRcm3VGTzcb3h; Fri, 9 Jan 2026 11:11:20 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 7862B4036C; Fri, 9 Jan 2026 11:14:55 +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; Fri, 9 Jan 2026 11:14:54 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 08/10] erofs: support unencoded inodes for page cache share Date: Fri, 9 Jan 2026 03:01:38 +0000 Message-ID: <20260109030140.594936-9-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 | 2 ++ fs/erofs/internal.h | 6 ++++++ fs/erofs/ishare.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 63 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..52179b706b5b 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -215,6 +215,8 @@ 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; + if (erofs_ishare_fill_inode(inode)) + inode->i_fop =3D &erofs_ishare_fops; 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 56a955aaeb18..85b244ba306a 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; @@ -149,6 +155,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 Sun Feb 8 15:37:37 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 9AC4F2ECE98; Fri, 9 Jan 2026 03:14:57 +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=1767928500; cv=none; b=uAUTTqBCpXZuaec47yQaeGoXwTTRX0l2O/xvPRAq65mM7XGnbDKO/mj6naWWjUJrbnS9SvKwuc580Q0YN+iLIryeWS/czo5ImvxNtNRHv4wV+TSf1ZOwoA8IyBpKHXsGx9m6621dCVS5CPN+XXJudzrNwXEQtXi7zZQrwHP674Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928500; c=relaxed/simple; bh=shYAQ3lGozBsYbgoOmCKLJomtqqhFwD0YN3X53tnIG8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LWf+OdO1Z9vzUsp7dOLWidVy2HbxYaTYoiQQuELJnDXudodzJjEUDRVzSGFLAlDSkuW+UGusrSSKR1TzHppeTe0XBhxK6e8t/A2WUwGeRSAIBR+Wyxj4O7xXK1ozHA86AZ3Ox60uTnzUR3A2wYavRqPurqr1R5yPXfk4B6AfOVc= 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=hUIhslzj; 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="hUIhslzj" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=hQ8B+kTJ87A5bJZYLMwSH+1zUPwX+xL11pHpPAvyQBc=; b=hUIhslzjt+3TiLa4Crz2+1YnA91y/cGKGQTyech0JJnAPNHvsHF+2TckCPxjmEZl/eywQaxv1 LY/cPzAWdwuceaZe2HTeYECY0LdqlqdpyOL5mkxbNWs0RFlF/gDYq+Gv6FcAF8TWMHxW4MOjvUY euvz90ggx++3rtD+NGzdA9c= Received: from mail.maildlp.com (unknown [172.19.163.0]) by canpmsgout03.his.huawei.com (SkyGuard) with ESMTPS id 4dnRcz4wpjzpSyw; Fri, 9 Jan 2026 11:11:31 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id EC6894036C; Fri, 9 Jan 2026 11:14:55 +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; Fri, 9 Jan 2026 11:14:55 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 09/10] erofs: support compressed inodes for page cache share Date: Fri, 9 Jan 2026 03:01:39 +0000 Message-ID: <20260109030140.594936-10-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 Reviewed-by: Gao Xiang --- fs/erofs/zdata.c | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 3d31f7840ca0..62d9dca90822 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -493,7 +493,7 @@ enum z_erofs_pclustermode { }; =20 struct z_erofs_frontend { - struct inode *const inode; + struct inode *inode, *sharedinode; struct erofs_map_blocks map; struct z_erofs_bvec_iter biter; =20 @@ -508,8 +508,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 +1866,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 +1883,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 *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 +1898,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 *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 +1933,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 +1942,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 Sun Feb 8 15:37:37 2026 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (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 8036E32BF2F; Fri, 9 Jan 2026 03:15:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928516; cv=none; b=Tt3BVroy+LK2p6DJW/zVGhz3CccIfu8TJG4EsLoBumAW2CXDfoLV6zAFQBt/+99d332Ub85PSmhwzdohWsAY9ivcLBpyjQANUwTm1jzfV8TDkGwnH6A+pZiTKsxpTyLfYad5Shqpt7+b+oHM1YxNkwAkdXYHoemkb/tcSaEeu1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767928516; c=relaxed/simple; bh=fWamhOFTM/hSqzDRnm3J+ehbkjswxcER7Tq3ufunKaI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CQIN9M6xeeacQu2kIrzocC6TJ9kjYmthh47/sMEXQ4E98zZdpxH1EX9TLUcQ9BZN34AYwNzSP48G/1QYdMk2B91A0SoJTu5WRIedcDc2N5+c6k/a1LYTN3uQ3SeUUHPZhJUuFDPQ//QAuur4TcLr0L0Z3Opa1ROlA4/t53O1TPk= 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=eT8p2xLl; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=eT8p2xLl; arc=none smtp.client-ip=45.249.212.187 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="eT8p2xLl"; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="eT8p2xLl" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Y9iG9ndcqnun6d+cB2jUtN8m3ukc7DAvlqzso25aXTA=; b=eT8p2xLl1jlYZCmBpyNNlXYMUHlAwZcLB//uGk3tQhpxbm6Jdc205QkIo8hUUYh0t03+Eo1K7 BaGPyTTn0lrbA/DKSG2lZpLiVU72CCYfqDMAk1wtIYGkzqo0SSLBezY55zK9McrXncSDcBtoTK9 2j9CfCdYzQwUqvDACKtTqzo= Received: from canpmsgout02.his.huawei.com (unknown [172.19.92.185]) by szxga01-in.huawei.com (SkyGuard) with ESMTPS id 4dnRgv2WKwz1BFq8; Fri, 9 Jan 2026 11:14:03 +0800 (CST) dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Y9iG9ndcqnun6d+cB2jUtN8m3ukc7DAvlqzso25aXTA=; b=eT8p2xLl1jlYZCmBpyNNlXYMUHlAwZcLB//uGk3tQhpxbm6Jdc205QkIo8hUUYh0t03+Eo1K7 BaGPyTTn0lrbA/DKSG2lZpLiVU72CCYfqDMAk1wtIYGkzqo0SSLBezY55zK9McrXncSDcBtoTK9 2j9CfCdYzQwUqvDACKtTqzo= Received: from mail.maildlp.com (unknown [172.19.162.197]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4dnRcn2rnNzcb3h; Fri, 9 Jan 2026 11:11:21 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 641DC40569; Fri, 9 Jan 2026 11:14:56 +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; Fri, 9 Jan 2026 11:14:55 +0800 From: Hongbo Li To: , , CC: , , , , , , Subject: [PATCH v13 10/10] erofs: implement .fadvise for page cache share Date: Fri, 9 Jan 2026 03:01:40 +0000 Message-ID: <20260109030140.594936-11-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20260109030140.594936-1-lihongbo22@huawei.com> References: <20260109030140.594936-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: kwepems100001.china.huawei.com (7.221.188.238) 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 85b244ba306a..51170792e365 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -145,6 +145,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, @@ -153,6 +160,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