From nobody Tue Nov 5 08:36:19 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B629C46467 for ; Wed, 11 Jan 2023 08:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbjAKIco (ORCPT ); Wed, 11 Jan 2023 03:32:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230074AbjAKIcP (ORCPT ); Wed, 11 Jan 2023 03:32:15 -0500 Received: from out30-7.freemail.mail.aliyun.com (out30-7.freemail.mail.aliyun.com [115.124.30.7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E804EBC9F; Wed, 11 Jan 2023 00:32:07 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R721e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0VZMek6i_1673425922; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VZMek6i_1673425922) by smtp.aliyun-inc.com; Wed, 11 Jan 2023 16:32:03 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: huyue2@coolpad.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 4/7] erofs: implement .read_iter for page cache sharing Date: Wed, 11 Jan 2023 16:31:55 +0800 Message-Id: <20230111083158.23462-5-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20230111083158.23462-1-jefflexu@linux.alibaba.com> References: <20230111083158.23462-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When page cache sharing enabled, page caches are managed in the address space of blobs rather than erofs inodes. All erofs inodes sharing one chunk will refer to and share the page cache in the blob's address space. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index f715b3efcc77..4075d9519a7d 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -384,8 +384,56 @@ static int erofs_fscache_share_file_open(struct inode = *inode, struct file *filp) return 0; } =20 +static ssize_t erofs_fscache_share_file_read_iter(struct kiocb *iocb, + struct iov_iter *to) +{ + struct file *filp =3D iocb->ki_filp; + struct inode *inode =3D file_inode(filp); + struct file *realfile =3D filp->private_data; + struct inode *realinode =3D file_inode(realfile); + struct erofs_fscache_share_file_info *finfo =3D realfile->private_data; + ssize_t already_read =3D 0; + int ret =3D 0; + + /* no need taking (shared) inode lock since it's a ro filesystem */ + if (!iov_iter_count(to)) + return 0; + + if (IS_DAX(inode) || iocb->ki_flags & IOCB_DIRECT) + return -EOPNOTSUPP; + + do { + struct folio *folio; + size_t bytes, copied, offset, fsize; + pgoff_t index =3D (finfo->pa + iocb->ki_pos) >> PAGE_SHIFT; + + folio =3D read_cache_folio(realinode->i_mapping, index, NULL, NULL); + if (IS_ERR(folio)) { + ret =3D PTR_ERR(folio); + break; + } + + fsize =3D folio_size(folio); + offset =3D iocb->ki_pos & (fsize - 1); + bytes =3D min_t(size_t, inode->i_size - iocb->ki_pos, iov_iter_count(to)= ); + bytes =3D min_t(size_t, bytes, fsize - offset); + copied =3D copy_folio_to_iter(folio, offset, bytes, to); + folio_put(folio); + iocb->ki_pos +=3D copied; + already_read +=3D copied; + if (copied < bytes) { + ret =3D -EFAULT; + break; + } + } while (iov_iter_count(to) && iocb->ki_pos < inode->i_size); + + file_accessed(filp); + return already_read ? already_read : ret; +} + const struct file_operations erofs_fscache_share_file_fops =3D { .llseek =3D generic_file_llseek, + .read_iter =3D erofs_fscache_share_file_read_iter, .open =3D erofs_fscache_share_file_open, .release =3D erofs_fscache_share_file_release, }; --=20 2.19.1.6.gb485710b