From nobody Mon Feb 9 02:45:29 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 A4DD733345F; Mon, 17 Nov 2025 13:37:25 +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=1763386648; cv=none; b=ArYIsLYKwzL05P4/Hl9u7kTafb+nihESsqxqOPRoqyFJuxxxNuWqesvLFXCRqyaVwloEUc/DcqiSOrwpRLYEDBOYN6Okre3T8xHrns3idAC6MnuqCI1AsKlsNmQDzto7vWL54y4uZKh6jrayzT7YV/NuRyGqWctc0hUhww9a32Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386648; c=relaxed/simple; bh=Rdfio9HC+kmHqrCfvzjq3WVzae8Iambf0d5KXAVRtgc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SWb5YMqZ689T5+itg46t/nw7gErYOKeGlV8IYgigrjF4JSC/nlVWWd3E6RX0cOH8noNY9B+o3yp4W5NybSJmTYun4PIlI92OfIiZtJoPQSXdf42ERXXbpRdULdp8ehLainOx4kulHOHtzfz5pCrzpmJyItRHfbaqjQa1E5QVm9o= 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=a8rQf3Jb; 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="a8rQf3Jb" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=BVhF3yufDuIbXhKcQ3iHeQwoOMperFUkVZd/f2P+AHo=; b=a8rQf3Jble94XsxFMCCvM1CmKDR1arZplg1wLHEmmwObinrd0C8C0wFYYGSk5ncR9FAeHgpwY gQxxsVcOwUMaeFpAOPR6DAZtaizbc2gRUnCfyuAWHVu8GopAwrMy4XMSpxM18YTOnYQCAsfyeLG ZDt1QcjGfMTRyww0M2Qruks= Received: from mail.maildlp.com (unknown [172.19.162.112]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4d97zT1vfPzmV6f; Mon, 17 Nov 2025 21:35:33 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 10E2F140276; Mon, 17 Nov 2025 21:37:16 +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; Mon, 17 Nov 2025 21:37:15 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 01/10] iomap: stash iomap read ctx in the private field of iomap_iter Date: Mon, 17 Nov 2025 13:25:28 +0000 Message-ID: <20251117132537.227116-2-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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). Reviewed-by: Gao Xiang Signed-off-by: Hongbo Li --- 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 8275b6681b9b..98dd20f0bb53 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -973,7 +973,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; } @@ -1075,7 +1075,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 6ae031ac8058..8e79303c074e 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -496,13 +496,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_pending =3D 0; int ret; @@ -560,13 +561,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_pending; =20 diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 8b1ac08c7474..c3ecbbdb14e8 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); @@ -594,7 +594,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, @@ -605,7 +605,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 Mon Feb 9 02:45:29 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 DCFFC333426; Mon, 17 Nov 2025 13:37:24 +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=1763386647; cv=none; b=Wx0Y6JAVorTwwpKESFVIJ5Il0R1woz7nJd3yhV/asAOs9DkA9HM0dBpHOIywTciyace1ZvGXlsgOjTISsaOgzNVXHlx4jbM+uR8/SQjkD1KLn+PRNsK1P+IXvBZDwDZAoryGs0OlrJCteqeF7Z4JalJJD6dxizWHWkL9/bzQa8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386647; c=relaxed/simple; bh=iMzG2+zP/IUS6D3F4jSWIkWkguBK3qZpux23YxBT6Oc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Sy5nybFJvDmyeS+qyELlSswhsygVwI84iqVH0BWQzvRIYnyl6/7q1gv2dQW8n6r7bBkh4BaYHSxMqDeg4+Gv/zN3v4pf34pvSkLzQV9Catu+I2SFEi4DY8amOj5idbSfzXkjpc4LxMCYBbaGRgqUAXg8M0tF7CS7vkn2SNmouzM= 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=f6aakdSN; 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="f6aakdSN" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=vU6EJAy0LzGznIOrPjQLaa18klM/ZD1fI+JTkKlV6BU=; b=f6aakdSNbQueOa3f+ZI/EEU7cWYT96Fbg8l2aQim9xeUvHRcv3ouCihqRFyYJgVzMzJ1qHECA NvXGFDhH2WlOqf+7SJ88Yb7nMVFTwulSfqgu78YKG4v1UTh+YpFIVh06BiUqlF4V0UMysBYMYvP ddNtYj5L05/B6/mSV9tNClU= Received: from mail.maildlp.com (unknown [172.19.88.234]) by canpmsgout07.his.huawei.com (SkyGuard) with ESMTPS id 4d97zV1Cs6zLlXd; Mon, 17 Nov 2025 21:35:34 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 7AB60140113; Mon, 17 Nov 2025 21:37:16 +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; Mon, 17 Nov 2025 21:37:15 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 02/10] erofs: hold read context in iomap_iter if needed Date: Mon, 17 Nov 2025 13:25:29 +0000 Message-ID: <20251117132537.227116-3-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 --- 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 Mon Feb 9 02:45:29 2026 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (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 12AE733030F; Mon, 17 Nov 2025 13:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386643; cv=none; b=eF8mIver6D1DVOFs9s8RHWCUgY2olrnjY8uLAcM1R9BqgHC2jsOVBwtR6L8+3JebW6E9KuyhtuhOROOmlPYelUAHNknNesHYe0N6DvfpAufeZVlccdnqtaBYZqR3lqEPvmHwePeTk0Z0W30RqHMdVLaYhiyvCeAC5kOj9JQYHDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386643; c=relaxed/simple; bh=0A9Wkrt8+ZhaJnsnwTcszWsChlrIImuGRWWh7hulGP8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SqkMrv0Rc7xwpDUzzxQPNuMP5MKobl+kC0SShgJ1lt2LFXJ/dV8eT5zj3rRWcj31oD3/MQ7T1HT7522U5AG9lYZHnyOz7JoEJ8pQcqWbYNK7/IWDU3Ev5nYojKrpdjIaQ24kb8SbPubfYE66i7HApnxsPxfgXzoxE7U4T4Pk+aQ= 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=WvVM8WAY; arc=none smtp.client-ip=113.46.200.227 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="WvVM8WAY" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=FbVkas6xVh0EDYbcJEaJK0b7cxUQjdGPdQbtHmbK7b4=; b=WvVM8WAYbcCPfvxIdH80g3SFtK4G6jWtv6xeMl0W4ZnksajU36D/yxNVcxFylE5k57bFBZGP2 NoNThwtMbhT9AzGRahB3aI+S7QK7cpok4MncykLqMEnp2g0W3wRbb2dnzefbv4XFS9w4z6cuUxa nw57G2pty4rDrYfsgXLVf8k= Received: from mail.maildlp.com (unknown [172.19.162.112]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4d97zm3GCnznTW3; Mon, 17 Nov 2025 21:35:48 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id EEC4D140276; Mon, 17 Nov 2025 21:37:16 +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; Mon, 17 Nov 2025 21:37:16 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 03/10] fs: Export alloc_empty_backing_file Date: Mon, 17 Nov 2025 13:25:30 +0000 Message-ID: <20251117132537.227116-4-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 --- fs/file_table.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/file_table.c b/fs/file_table.c index b223d873e48b..7508f69a1839 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 Mon Feb 9 02:45:29 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 C9938332EDD; Mon, 17 Nov 2025 13:37:24 +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=1763386647; cv=none; b=mm6bJV0DmklOtSq7eDPX/Eh9ojGhl2Mr1KbDQViUgHD5LgMDb0y3XJ4jz0vcq8g9Jfcf2fAlKg1dK9wpk1ihVt8IAzEPqtil4RUx1sCZE+VZ7PxwH9Zts0B4Dab0XR/GGdzpYP/jNXHQ37yLtrVbpaLgCDu1Dp0TGZGkX7zJ9bA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386647; c=relaxed/simple; bh=tH0JolREo8cNIFkYyW3F7pwq+OVNHXGNB0uE8egG1/Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fIDh4c3MwWyQVIxmwhZNfHZcylNLI9eSnNLz1YIksmp0L99FchC+6hSzuJnC2kCO/uV8PLeawx1Qb1w5CY9cbwAh1ixhFFkno1ejfDmqdmDitreZ1rRpgde/2pXB1XPxE2BjTq9ZjNpQZ5xN7+zDMr2ef92KJGzaqosP/mSRFzs= 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=U0mzbbkr; 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="U0mzbbkr" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=VE0DQ7pctvI8MKUuVLQSMq+RxdHSNjkD65i/wt7FY9k=; b=U0mzbbkr6XqSBexR9vLPrW62ltoceXM76eb1thCUd7R4PI93f3zOeio1BUh/Y+FBEfGQAzWN5 xHjBu8EECQ9XlCFtNCx2BdnQyM5Uu/epg1dcdYDUMj9D0roOOPABrkwiRIfvdGRK0BFth5hcxDm ujhGwQ2xuWSnAQ60VG2gOXM= Received: from mail.maildlp.com (unknown [172.19.163.174]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4d97zW113BzRhrk; Mon, 17 Nov 2025 21:35:35 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 60D1D140202; Mon, 17 Nov 2025 21:37:17 +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; Mon, 17 Nov 2025 21:37:16 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 04/10] erofs: move `struct erofs_anon_fs_type` to super.c Date: Mon, 17 Nov 2025 13:25:31 +0000 Message-ID: <20251117132537.227116-5-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) To kwepemr500015.china.huawei.com (7.202.195.162) Content-Type: text/plain; charset="utf-8" From: Hongzhen Luo Move the `struct erofs_anon_fs_type` to the super.c and expose it in preparation for the upcoming page cache share feature. Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li --- fs/erofs/fscache.c | 13 ------------- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 362acf828279..2d1683479fc0 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 f3f8d8c066e4..0d88c04684b9 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 @@ -920,6 +921,20 @@ 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 { + .owner =3D THIS_MODULE, + .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 Mon Feb 9 02:45:29 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 538DE334363; Mon, 17 Nov 2025 13:37:26 +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=1763386648; cv=none; b=rnD+VAMDQcAHGclkABnmq9uZ17rwHfs6TNlvLjq1S5xCAt5IbS6jZAE11qW4vbDVrFPM4CFyzzs3hIbpDucfJLSCaS6nmLDShA02I+8a33vlSG0sHmEy0p28zXnzrAndkYkerBaqe9ttScXmtf+qjuRrZqS/21CWDUa//pmCdkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386648; c=relaxed/simple; bh=if69pTpyGDjh70xquVDyUW4b961K/ysLzjW54pXMNtA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VILDYOEIqlYijAVDC/b6rqP0iS60ZEEg/2wJuBoWJ33KEMA0zs00oSpDC+zLCbz9oagHqYkfKOIfdm7x0zr5vFT69VUq+mHUxrN65ffbmxs9QfC22f409RtsshfqROe8n0YVyZjRnmrKC6toaSgeID0rm87cAypl+g0G7x5p2R0= 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=1bTGghAn; 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="1bTGghAn" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=+yTAZNkUZ6BJVhksgxaanaIqjrrIgHHIwTRXiBhCoe4=; b=1bTGghAnrzxS0UD9Jne+KfXgyEcOMlZMCNE1RPXycNBiBDOTgNy527uiPsOGy0y/l9Riuq4Ag B/xmFlKECrNDsKpuXfk+s1dk8oEAfxpCmvT0Z/Yqt8vB4kDy/+HTeCev2RMQGO6u2C3OwejsOIu 5wOjzw5f982xBPLjnQTds0I= Received: from mail.maildlp.com (unknown [172.19.88.194]) by canpmsgout06.his.huawei.com (SkyGuard) with ESMTPS id 4d97zW4GJSzRhrk; Mon, 17 Nov 2025 21:35:35 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id D0AC8140132; Mon, 17 Nov 2025 21:37:17 +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; Mon, 17 Nov 2025 21:37:17 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 05/10] erofs: support user-defined fingerprint name Date: Mon, 17 Nov 2025 13:25:32 +0000 Message-ID: <20251117132537.227116-6-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 --- fs/erofs/Kconfig | 9 +++++++++ fs/erofs/erofs_fs.h | 6 ++++-- fs/erofs/internal.h | 2 ++ fs/erofs/super.c | 5 +++-- fs/erofs/xattr.c | 15 +++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/fs/erofs/Kconfig b/fs/erofs/Kconfig index d81f3318417d..c88b6d0714a4 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 device. + + If unsure, say N. diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 3d5738f80072..9b9fe1abe0b9 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -35,8 +35,9 @@ #define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES 0x00000040 #define EROFS_FEATURE_INCOMPAT_48BIT 0x00000080 #define EROFS_FEATURE_INCOMPAT_METABOX 0x00000100 +#define EROFS_FEATURE_INCOMPAT_ISHARE_KEY 0x00000200 #define EROFS_ALL_FEATURE_INCOMPAT \ - ((EROFS_FEATURE_INCOMPAT_METABOX << 1) - 1) + ((EROFS_FEATURE_INCOMPAT_ISHARE_KEY << 1) - 1) =20 #define EROFS_SB_EXTSLOT_SIZE 16 =20 @@ -83,7 +84,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; /* indice the ishare key in prefix xattr */ + __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..3033252211ba 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_pfx; /* ishare prefix xattr index */ struct erofs_xattr_prefix_item *xattr_prefixes; unsigned int xattr_filter_reserved; #endif @@ -234,6 +235,7 @@ EROFS_FEATURE_FUNCS(dedupe, incompat, INCOMPAT_DEDUPE) EROFS_FEATURE_FUNCS(xattr_prefixes, incompat, INCOMPAT_XATTR_PREFIXES) EROFS_FEATURE_FUNCS(48bit, incompat, INCOMPAT_48BIT) EROFS_FEATURE_FUNCS(metabox, incompat, INCOMPAT_METABOX) +EROFS_FEATURE_FUNCS(ishare_key, incompat, INCOMPAT_ISHARE_KEY) 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) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 0d88c04684b9..80f032cb2cc3 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -298,6 +298,9 @@ static int erofs_read_superblock(struct super_block *sb) if (ret) goto out; } + if (erofs_sb_has_ishare_key(sbi)) + sbi->ishare_xattr_pfx =3D + dsb->ishare_xattr_prefix_id & EROFS_XATTR_LONG_PREFIX_MASK; =20 ret =3D -EINVAL; sbi->feature_incompat =3D le32_to_cpu(dsb->feature_incompat); @@ -339,7 +342,6 @@ static int erofs_read_superblock(struct super_block *sb) return -EFSCORRUPTED; /* self-loop detection */ } sbi->inos =3D le64_to_cpu(dsb->inos); - sbi->epoch =3D (s64)le64_to_cpu(dsb->epoch); sbi->fixed_nsec =3D le32_to_cpu(dsb->fixed_nsec); super_set_uuid(sb, (void *)dsb->uuid, sizeof(dsb->uuid)); @@ -737,7 +739,6 @@ static int erofs_fc_fill_super(struct super_block *sb, = struct fs_context *fc) err =3D erofs_xattr_prefixes_init(sb); if (err) return err; - erofs_set_sysfs_name(sb); err =3D erofs_register_sysfs(sb); if (err) diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 396536d9a862..6cb76313c14c 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -519,6 +519,21 @@ int erofs_xattr_prefixes_init(struct super_block *sb) } =20 erofs_put_metabuf(&buf); + if (!ret && erofs_sb_has_ishare_key(sbi)) { + struct erofs_xattr_long_prefix *new_pfx, *pfx =3D + pfs[sbi->ishare_xattr_pfx].prefix; + + new_pfx =3D krealloc(pfx, + sizeof(struct erofs_xattr_long_prefix) + + pfs[sbi->ishare_xattr_pfx].infix_len + 1, + GFP_KERNEL); + if (new_pfx) { + new_pfx->infix[pfs[sbi->ishare_xattr_pfx].infix_len] =3D '\0'; + pfs[sbi->ishare_xattr_pfx].prefix =3D new_pfx; + } else { + ret =3D -ENOMEM; + } + } sbi->xattr_prefixes =3D pfs; if (ret) erofs_xattr_prefixes_cleanup(sb); --=20 2.22.0 From nobody Mon Feb 9 02:45:29 2026 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (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 0068E3314B3; Mon, 17 Nov 2025 13:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386644; cv=none; b=MoexXJ0tF76Nvd5xHBAvjB7WGXsgu7enE6Ra80KR+fKURHuILcEvVs/7B+caDcde4vLcMGBIECzdHiF6pdffNBZM2RT0BvSD1hWpcSRcrLc23DLDQPU1dSjZh+YsTyXh+uD3Nzuwo2iUhGLQcuUgcvji2d7rcLVTxslWW1oeImM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386644; c=relaxed/simple; bh=Oelws93WivX7++kXLOXBiUl+c9440aNZg9fAqh5zeMA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lYAzI+S0Cr5biZ13PWGs+OZJarZQOF96BgMl94I8uWm/TM2zbrU8Jq/u9ICm5Wsxj+9T39mzUn69UaFkSnFXqPcYSdakRF+ijQdQRn+gCsX/m5OF+0gSsY1VZQAgUw/ruSAoA43voYJTM5jUuXxvVlpvPFmVRM3QBsZzl4zY8cs= 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=OCntdh3j; arc=none smtp.client-ip=113.46.200.227 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="OCntdh3j" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=hG3ZwBWx+b/D3O7O0d3ZAoE45/BCf1dWrd35luw2P74=; b=OCntdh3jC0bnPvI7d0q2CKgk/zRS/vJxiLDn+0yuHC+At3yxP7gwTtdC1XqJpiuyBQQQkVIu5 8YhfxkOskIJwjtO0GdIn98gxVZbjtagsZmBBtzV63N90tZEQJtA1sp35hbQDBSSuG9gvf5s24+k Zpn69A6cbhKg4D0OyqcVRq0= Received: from mail.maildlp.com (unknown [172.19.163.17]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4d97zn5b8yznTW3; Mon, 17 Nov 2025 21:35:49 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 4B0AA1A0188; Mon, 17 Nov 2025 21:37:18 +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; Mon, 17 Nov 2025 21:37:17 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 06/10] erofs: support domain-specific page cache share Date: Mon, 17 Nov 2025 13:25:33 +0000 Message-ID: <20251117132537.227116-7-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 --- fs/erofs/super.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 80f032cb2cc3..9a5e3f9dcd0d 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -517,6 +517,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); @@ -617,7 +619,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_key(sbi)) super_set_sysfs_name_generic(sb, "%s,%s", sbi->domain_id, sbi->fsid); else if (sbi->fsid) @@ -1034,6 +1036,8 @@ static int erofs_show_options(struct seq_file *seq, s= truct dentry *root) #ifdef CONFIG_EROFS_FS_ONDEMAND if (sbi->fsid) seq_printf(seq, ",fsid=3D%s", sbi->fsid); +#endif +#if defined(CONFIG_EROFS_FS_ONDEMAND) || defined(CONFIG_EROFS_FS_PAGE_CACH= E_SHARE) if (sbi->domain_id) seq_printf(seq, ",domain_id=3D%s", sbi->domain_id); #endif --=20 2.22.0 From nobody Mon Feb 9 02:45:29 2026 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (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 889D6333751; Mon, 17 Nov 2025 13:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386653; cv=none; b=NDlWcidvFS+JlMiTqVGFTLfZaQLKYRBR/TVLjcuJbiwfu4atfCyciiaP8uKW8oYR0UUdDDBEA+ZLHRIFrHG7KZWDnB+V1jjSA1v2XLX4x3TWItdAGqh6uO/Y89R9mdLxmGEPmNQx83f4YDnC+iKNNivqxpo4AYd1fA6+HpgK6dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386653; c=relaxed/simple; bh=YzQMyF33stPgCsUpxHarlCggEPUC6v2c8Bhx9n10rqM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LR/Q9WrDh3ritkoE/gH2jxo8FfZNBOvbLtr//CWEpr74KJJf4hwtWId++QGx27mo4d2R5aLJbC7ePBLiLZxRzctGNN1DgnKROav6snNVSyWJOadS1i5XyDOQIXEmPGdbpbS2aHrgecMP8JPuPeO7K59Q9EwGR8l2/9y2Q9TwloI= 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=wONxQ35P; arc=none smtp.client-ip=113.46.200.226 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="wONxQ35P" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=gjPehcgOYLqsaIG5VW0lK3lA1pE/5/H6+T1O88BF328=; b=wONxQ35PMX07LmTZZTjz6iVIwCMhiCMbp15o8APW/j4qWmkkqe/qcJAJkl/pBJcxLISFHAK4n pcF1Ov8dEtAdrePatxxtNth2Is04YZnQbzXRkr6I+FVk5cXEnk4gHkxRIpbpmBdmcWGYJwhc3bW AqhH7+5bnDZfTBphsLYOcyg= Received: from mail.maildlp.com (unknown [172.19.88.234]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4d97zW4TVRzKm9m; Mon, 17 Nov 2025 21:35:35 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id AE9EA140113; Mon, 17 Nov 2025 21:37:18 +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; Mon, 17 Nov 2025 21:37:18 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 07/10] erofs: introduce the page cache share feature Date: Mon, 17 Nov 2025 13:25:34 +0000 Message-ID: <20251117132537.227116-8-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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. Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li --- fs/erofs/Makefile | 1 + fs/erofs/internal.h | 29 ++++++ fs/erofs/ishare.c | 241 ++++++++++++++++++++++++++++++++++++++++++++ fs/erofs/super.c | 31 +++++- 4 files changed, 300 insertions(+), 2 deletions(-) create mode 100644 fs/erofs/ishare.c 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 3033252211ba..93ad34f2b488 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -304,6 +304,22 @@ struct erofs_inode { }; #endif /* CONFIG_EROFS_FS_ZIP */ }; +#ifdef CONFIG_EROFS_FS_PAGE_CACHE_SHARE + union { + /* internal dedup inode */ + struct { + char *fingerprint; + spinlock_t lock; + /* all backing inodes */ + struct list_head backing_head; + }; + + struct { + struct inode *ishare; + struct list_head backing_link; + }; + }; +#endif /* the corresponding vfs inode */ struct inode vfs_inode; }; @@ -410,6 +426,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 +558,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 erofs_ishare_init(struct super_block *sb); +void erofs_ishare_exit(struct super_block *sb); +bool erofs_ishare_fill_inode(struct inode *inode); +void erofs_ishare_free_inode(struct inode *inode); +#else +static inline int erofs_ishare_init(struct super_block *sb) { return 0; } +static inline void erofs_ishare_exit(struct super_block *sb) {} +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..f386efb260da --- /dev/null +++ b/fs/erofs/ishare.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2024, Alibaba Cloud + */ +#include +#include +#include +#include +#include +#include "internal.h" +#include "xattr.h" + +#include "../internal.h" + +static DEFINE_MUTEX(erofs_ishare_lock); +static struct vfsmount *erofs_ishare_mnt; +static refcount_t erofs_ishare_supers; + +int erofs_ishare_init(struct super_block *sb) +{ + struct vfsmount *mnt =3D NULL; + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + + if (!erofs_sb_has_ishare_key(sbi)) + return 0; + + mutex_lock(&erofs_ishare_lock); + if (erofs_ishare_mnt) { + refcount_inc(&erofs_ishare_supers); + } else { + mnt =3D kern_mount(&erofs_anon_fs_type); + if (!IS_ERR(mnt)) { + erofs_ishare_mnt =3D mnt; + refcount_set(&erofs_ishare_supers, 1); + } + } + mutex_unlock(&erofs_ishare_lock); + return IS_ERR(mnt) ? PTR_ERR(mnt) : 0; +} + +void erofs_ishare_exit(struct super_block *sb) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(sb); + struct vfsmount *tmp; + + if (!erofs_sb_has_ishare_key(sbi) || !erofs_ishare_mnt) + return; + + mutex_lock(&erofs_ishare_lock); + if (refcount_dec_and_test(&erofs_ishare_supers)) { + tmp =3D erofs_ishare_mnt; + erofs_ishare_mnt =3D NULL; + mutex_unlock(&erofs_ishare_lock); + kern_unmount(tmp); + mutex_lock(&erofs_ishare_lock); + } + mutex_unlock(&erofs_ishare_lock); +} + +static int erofs_ishare_iget5_eq(struct inode *inode, void *data) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + + return vi->fingerprint && memcmp(vi->fingerprint, data, + sizeof(size_t) + *(size_t *)data) =3D=3D 0; +} + +static int erofs_ishare_iget5_set(struct inode *inode, void *data) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + + vi->fingerprint =3D data; + INIT_LIST_HEAD(&vi->backing_head); + spin_lock_init(&vi->lock); + return 0; +} + +bool erofs_ishare_fill_inode(struct inode *inode) +{ + struct erofs_sb_info *sbi =3D EROFS_SB(inode->i_sb); + struct erofs_xattr_prefix_item *ishare_prefix; + struct erofs_inode *vi =3D EROFS_I(inode); + struct inode *idedup; + /* + * fingerprint layout: + * fingerprint length + fingerprint content (xattr_value + domain_id) + */ + char *ishare_key, *fingerprint; + ssize_t ishare_vlen; + unsigned long hash; + int key_idx; + + if (!sbi->domain_id || !erofs_sb_has_ishare_key(sbi)) + return false; + + ishare_prefix =3D sbi->xattr_prefixes + sbi->ishare_xattr_pfx; + ishare_key =3D ishare_prefix->prefix->infix; + key_idx =3D ishare_prefix->prefix->base_index; + ishare_vlen =3D erofs_getxattr(inode, key_idx, ishare_key, NULL, 0); + if (ishare_vlen <=3D 0 || ishare_vlen > (1 << sbi->blkszbits)) + return false; + + fingerprint =3D kmalloc(sizeof(ssize_t) + ishare_vlen + + strlen(sbi->domain_id), GFP_KERNEL); + if (!fingerprint) + return false; + + *(ssize_t *)fingerprint =3D ishare_vlen + strlen(sbi->domain_id); + if (ishare_vlen !=3D erofs_getxattr(inode, key_idx, ishare_key, + fingerprint + sizeof(ssize_t), + ishare_vlen)) { + kfree(fingerprint); + return false; + } + + memcpy(fingerprint + sizeof(ssize_t) + ishare_vlen, + sbi->domain_id, strlen(sbi->domain_id)); + hash =3D xxh32(fingerprint + sizeof(ssize_t), + ishare_vlen + strlen(sbi->domain_id), hash); + idedup =3D iget5_locked(erofs_ishare_mnt->mnt_sb, hash, + erofs_ishare_iget5_eq, erofs_ishare_iget5_set, + fingerprint); + if (!idedup) { + kfree(fingerprint); + return false; + } + + INIT_LIST_HEAD(&vi->backing_link); + vi->ishare =3D idedup; + spin_lock(&EROFS_I(idedup)->lock); + list_add(&vi->backing_link, &EROFS_I(idedup)->backing_head); + spin_unlock(&EROFS_I(idedup)->lock); + if (!(idedup->i_state & I_NEW)) { + kfree(fingerprint); + return true; + } + if (erofs_inode_is_data_compressed(vi->datalayout)) + idedup->i_mapping->a_ops =3D &z_erofs_aops; + else + idedup->i_mapping->a_ops =3D &erofs_aops; + idedup->i_mode =3D vi->vfs_inode.i_mode; + i_size_write(idedup, vi->vfs_inode.i_size); + unlock_new_inode(idedup); + return true; +} + +void erofs_ishare_free_inode(struct inode *inode) +{ + struct erofs_inode *vi =3D EROFS_I(inode); + struct inode *idedup =3D vi->ishare; + + if (!idedup) + return; + spin_lock(&EROFS_I(idedup)->lock); + list_del(&vi->backing_link); + spin_unlock(&EROFS_I(idedup)->lock); + iput(idedup); + vi->ishare =3D NULL; +} + +static int erofs_ishare_file_open(struct inode *inode, struct file *file) +{ + struct file *realfile; + struct inode *dedup; + + dedup =3D EROFS_I(inode)->ishare; + if (!dedup) + return -EINVAL; + + realfile =3D alloc_empty_backing_file(O_RDONLY|O_NOATIME, current_cred()); + if (IS_ERR(realfile)) + return PTR_ERR(realfile); + ihold(dedup); + realfile->f_op =3D &erofs_file_fops; + realfile->f_inode =3D dedup; + realfile->f_mapping =3D dedup->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; + + if (!realfile) + return -EINVAL; + 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 inode *inode =3D file_inode(iocb->ki_filp); + struct kiocb dedup_iocb; + ssize_t nread; + + if (!realfile) + return -EINVAL; + if (!iov_iter_count(to)) + return 0; + + /* fallback to the original file in DAX or DIRECT mode */ + if (IS_DAX(inode) || (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; + + if (!realfile) + return -EINVAL; + + 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, +}; diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 9a5e3f9dcd0d..37e060dd5aff 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -746,6 +746,10 @@ static int erofs_fc_fill_super(struct super_block *sb,= struct fs_context *fc) if (err) return err; =20 + err =3D erofs_ishare_init(sb); + if (err) + return err; + sbi->dir_ra_bytes =3D EROFS_DIR_RA_BYTES; erofs_info(sb, "mounted with root inode @ nid %llu.", sbi->root_nid); return 0; @@ -906,6 +910,7 @@ static void erofs_put_super(struct super_block *sb) { struct erofs_sb_info *const sbi =3D EROFS_SB(sb); =20 + erofs_ishare_exit(sb); erofs_unregister_sysfs(sb); erofs_shrinker_unregister(sb); erofs_xattr_prefixes_cleanup(sb); @@ -924,10 +929,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); +#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 { @@ -1053,6 +1079,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); } --=20 2.22.0 From nobody Mon Feb 9 02:45:29 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 73FCD33342A; Mon, 17 Nov 2025 13:37:28 +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=1763386651; cv=none; b=lLRadxTGlmPSbacDiRymemfE5g12rhMMlEt2OLsCEz35nXSfUwgo9dUJtbiZItOrr+PqQ/olIXGEixMr1L7XoUbfyGCxarhVgduisgFpqpH/Ue9VHqpB7rS94k5ZK+9xG++6MR7jy7k1OH64hcfC4A8M/+hLzgZ6LzSkQk1O+Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386651; c=relaxed/simple; bh=qKwzyYgp3MUh7k5z3QieUTtHbRcxFC9lSB3b+ZBW4+U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W4/fNlM8zq80BgMbdz3tniUMZLBvoQ5PCkQsj7tiFJcBF6MQyV/QJniaiID6UvVyekqZiIaErQvEgmI1gXlebJh3IWrf2f4keyJjipcjYkXfYo8XzftK6JU1+DDQyRNokgUk6TCwFHX8ZJ6oa7D3gpBL18QbNEj7NGu3CI8J1ko= 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=bxuUj4zM; 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="bxuUj4zM" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=zUpiwq3GswNAucJgBmwIKwOgpNh9M/1fRGnlwv5lH7U=; b=bxuUj4zM0yKKeOmJuVDKC88oPqDld72nwbMllbPkiolwUTtkHleCf4cJRFglWKI8X7quNAORu jIKdWYfxxsfulz+62Mqb5O4QR8JCbUDMSN7/jpnKTqfVDfKofs1dd+UxL5/LUf6ilSchi2QCBxl s3VRjIJSvtM7MkjdmiMy6ww= Received: from mail.maildlp.com (unknown [172.19.163.252]) by canpmsgout01.his.huawei.com (SkyGuard) with ESMTPS id 4d97zm4Jn7z1T4G8; Mon, 17 Nov 2025 21:35:48 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 1A5AF180B20; Mon, 17 Nov 2025 21:37:19 +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; Mon, 17 Nov 2025 21:37:18 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 08/10] erofs: support unencoded inodes for page cache share Date: Mon, 17 Nov 2025 13:25:35 +0000 Message-ID: <20251117132537.227116-9-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 --- fs/erofs/data.c | 30 +++++++++++++++++++++++------- fs/erofs/inode.c | 4 ++++ fs/erofs/internal.h | 17 +++++++++++++++++ fs/erofs/ishare.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 71e23d91123d..862df0c7ceb7 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 {}; + struct erofs_iomap_iter_ctx iter_ctx =3D { + .realinode =3D erofs_ishare_iget(inode), + }; =20 + if (!iter_ctx.realinode) + return -EIO; trace_erofs_read_folio(folio, true); =20 iomap_read_folio(&erofs_iomap_ops, &read_ctx, &iter_ctx); + erofs_ishare_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 {}; + struct erofs_iomap_iter_ctx iter_ctx =3D { + .realinode =3D erofs_ishare_iget(inode), + }; =20 + if (!iter_ctx.realinode) + return; trace_erofs_readahead(rac->mapping->host, readahead_index(rac), readahead_count(rac), true); =20 iomap_readahead(&erofs_iomap_ops, &read_ctx, &iter_ctx); + erofs_ishare_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 cb780c095d28..3be4614d1add 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 93ad34f2b488..37b536eebc3d 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -197,6 +197,19 @@ static inline bool erofs_is_fscache_mode(struct super_= block *sb) !erofs_is_fileio_mode(EROFS_SB(sb)) && !sb->s_bdev; } =20 +#if defined(CONFIG_EROFS_FS_INODE_SHARE) +static inline bool erofs_is_ishare_inode(struct inode *inode) +{ + /* we have assumed FS_ONDEMAND is excluded with FS_INODE_SHARE feature */ + return inode->i_sb->s_type =3D=3D &erofs_anon_fs_type; +} +#else +static inline bool erofs_is_ishare_inode(struct inode *inode) +{ + return false; +} +#endif + enum { EROFS_ZIP_CACHE_DISABLED, EROFS_ZIP_CACHE_READAHEAD, @@ -563,11 +576,15 @@ int erofs_ishare_init(struct super_block *sb); void erofs_ishare_exit(struct super_block *sb); bool erofs_ishare_fill_inode(struct inode *inode); void erofs_ishare_free_inode(struct inode *inode); +struct inode *erofs_ishare_iget(struct inode *inode); +void erofs_ishare_iput(struct inode *realinode); #else static inline int erofs_ishare_init(struct super_block *sb) { return 0; } static inline void erofs_ishare_exit(struct super_block *sb) {} 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_ishare_iget(struct inode *inode) { retur= n inode; } +static inline void erofs_ishare_iput(struct inode *realinode) {} #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 f386efb260da..da735d69f21f 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -239,3 +239,34 @@ const struct file_operations erofs_ishare_fops =3D { .get_unmapped_area =3D thp_get_unmapped_area, .splice_read =3D filemap_splice_read, }; + +/* + * erofs_ishare_iget - find the backing inode. + */ +struct inode *erofs_ishare_iget(struct inode *inode) +{ + struct erofs_inode *vi, *vi_dedup; + struct inode *realinode; + + if (!erofs_is_ishare_inode(inode)) + return igrab(inode); + + vi_dedup =3D EROFS_I(inode); + spin_lock(&vi_dedup->lock); + /* fall back to all backing inodes */ + DBG_BUGON(list_empty(&vi_dedup->backing_head)); + list_for_each_entry(vi, &vi_dedup->backing_head, backing_link) { + realinode =3D igrab(&vi->vfs_inode); + if (realinode) + break; + } + spin_unlock(&vi_dedup->lock); + + DBG_BUGON(!realinode); + return realinode; +} + +void erofs_ishare_iput(struct inode *realinode) +{ + iput(realinode); +} --=20 2.22.0 From nobody Mon Feb 9 02:45:29 2026 Received: from canpmsgout11.his.huawei.com (canpmsgout11.his.huawei.com [113.46.200.226]) (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 89980334698; Mon, 17 Nov 2025 13:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.226 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386651; cv=none; b=qKfBAjI7kTqCmJMmLIkwqdtJG51QAd27RV8YG09sMKXXcotbFP+Pv2NrcuEK2qBuecy8zqjIvETNMNxKSZyQUMstFMeUd7k3iepU8piREwXXigJtKSYdI6MKT6khUZaeOoQdKiZOmC5gEmXfpb7T7ev7pVjMwTxs/XQlTUx1e3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386651; c=relaxed/simple; bh=OjOqPv1EpRrrQ0DG+bdISLd35lzrPatc9mHHJ1Q9MCw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JZTXjirqPK6MRMldqJnWVa1qSLHtWTOVOzAU6ZsLNpDDqyE7OIbZkRfIldJwDzxT9yYK22yHhPegACE+SyT3dysrAU6dOdUHIWgJuHGaRBlMB1u7z50nbtpPeqYHgl0Gxqx1NI8Hyh8d7j9AkfrPgxMf4dUh9Z7Pn0Yxg+yKriY= 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=mInAdm+h; arc=none smtp.client-ip=113.46.200.226 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="mInAdm+h" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=dYNIooyIs5lp/I69stBGQ6Msz6ordRzMmr8uctJ6RDk=; b=mInAdm+hm82F6e8/wF+lwQwm9Dwl6nrUsN7nGmaij/qTJmfP0pgq0YAx/P1CTmJuxBAWq68F0 qGAUH9/sOQSYYdZ4tyRYueujDLzYr1TRfaEDt76twlYSUaAtNRe3b5NWOLh72OIEpjCne6TUHSF OifkoczMJv4VgV2csCzeAH4= Received: from mail.maildlp.com (unknown [172.19.88.163]) by canpmsgout11.his.huawei.com (SkyGuard) with ESMTPS id 4d97zX2LQdzKm5v; Mon, 17 Nov 2025 21:35:36 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 9063818001B; Mon, 17 Nov 2025 21:37:19 +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; Mon, 17 Nov 2025 21:37:18 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 09/10] erofs: support compressed inodes for page cache share Date: Mon, 17 Nov 2025 13:25:36 +0000 Message-ID: <20251117132537.227116-10-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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 | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index bc80cfe482f7..f92891022670 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; struct erofs_map_blocks map; struct z_erofs_bvec_iter biter; =20 @@ -1870,10 +1870,18 @@ static void z_erofs_pcluster_readmore(struct z_erof= s_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 inode =3D folio->mapping->host, *realinode; + Z_EROFS_DEFINE_FRONTEND(f, NULL, folio_pos(folio)); int err; =20 + if (erofs_is_ishare_inode(inode)) + realinode =3D erofs_ishare_iget(inode); + else + realinode =3D inode; + + if (!realinode) + return -EIO; + f.inode =3D realinode; trace_erofs_read_folio(folio, false); z_erofs_pcluster_readmore(&f, NULL, true); err =3D z_erofs_scan_folio(&f, folio, false); @@ -1883,23 +1891,34 @@ 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 (erofs_is_ishare_inode(inode)) + erofs_ishare_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 inode =3D rac->mapping->host, *realinode; + Z_EROFS_DEFINE_FRONTEND(f, NULL, 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); + if (erofs_is_ishare_inode(inode)) + realinode =3D erofs_ishare_iget(inode); + else + realinode =3D inode; + + if (!realinode) + return; + f.inode =3D realinode; + 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; @@ -1913,8 +1932,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); @@ -1922,6 +1941,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 (erofs_is_ishare_inode(inode)) + erofs_ishare_iput(realinode); } =20 const struct address_space_operations z_erofs_aops =3D { --=20 2.22.0 From nobody Mon Feb 9 02:45:29 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 17A04331A5B; Mon, 17 Nov 2025 13:37:21 +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=1763386643; cv=none; b=pq4rp/Jlg8Iv4qmsWIZvxhGIrzXcMhxgY4tL5uzcITG9AjLqJ9p9xoiVUe+BgJEJbCbBcBSFhLSFkS1ScswbUwRHXz+rRIA4LOeLlD5Dc7h0tgULve04Xex5Ov5bcNmc9ZBpqMkKga7TaII1jDVFwU/OMhycUwFjEMBpUjhJ07Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763386643; c=relaxed/simple; bh=tk/BLR6SGDHZd8PgqWActDpF5QWDgHXfHSMSbURwoo8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YoFdZLZakQWAlTFRagmA1uUk1T7RTt/Dl5RyPbixGVsM4YQCc9nRuEaICu0SqD8YF5CMFVvSL+ixyxlgQhmyPhirW/aICkyFpLlas13AFkYQhTqAXMiYO0s+26dZkFd96RJCwZPc17+l/isISRUFCuCWGEVfuldg32Rk6Qcvewg= 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=ykDEiun6; 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="ykDEiun6" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=p0umYnge/9FjlLkpy4PvS2wcFW3FASjdMXzdFE5g+6g=; b=ykDEiun6uQV0x6mT1Z3+CS6s2um2ALZmoXqzXZGY9B7fYbgrrdPioYXkHBidFDyRjPXiFpoX5 tfyRDEhEfpPqwNAu49HkEEPW+idu9Q908Jdp9+RqzZdOZ8pM6dvRNpwCDF+rAULgwyGFT/BDItI i9tinlXEg7iqM4Ht/Uxq20Y= Received: from mail.maildlp.com (unknown [172.19.162.254]) by canpmsgout05.his.huawei.com (SkyGuard) with ESMTPS id 4d97zq2zltz12Lfd; Mon, 17 Nov 2025 21:35:51 +0800 (CST) Received: from kwepemr500015.china.huawei.com (unknown [7.202.195.162]) by mail.maildlp.com (Postfix) with ESMTPS id 043B1180471; Mon, 17 Nov 2025 21:37:20 +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; Mon, 17 Nov 2025 21:37:19 +0800 From: Hongbo Li To: , , , , , CC: , , , Subject: [PATCH v9 10/10] erofs: implement .fadvise for page cache share Date: Mon, 17 Nov 2025 13:25:37 +0000 Message-ID: <20251117132537.227116-11-lihongbo22@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20251117132537.227116-1-lihongbo22@huawei.com> References: <20251117132537.227116-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: kwepems200002.china.huawei.com (7.221.188.68) 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(). Reviewed-by: Gao Xiang Signed-off-by: Hongzhen Luo Signed-off-by: Hongbo Li --- fs/erofs/ishare.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c index da735d69f21f..d8bff0cdf702 100644 --- a/fs/erofs/ishare.c +++ b/fs/erofs/ishare.c @@ -230,6 +230,16 @@ 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) +{ + struct file *realfile =3D file->private_data; + + if (!realfile) + return -EINVAL; + return vfs_fadvise(realfile, offset, len, advice); +} + const struct file_operations erofs_ishare_fops =3D { .open =3D erofs_ishare_file_open, .llseek =3D generic_file_llseek, @@ -238,6 +248,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 /* --=20 2.22.0