From nobody Fri Sep 19 08:40:20 2025 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 4E1D0C4167D for ; Sat, 26 Nov 2022 00:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbiKZA6E (ORCPT ); Fri, 25 Nov 2022 19:58:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbiKZA6C (ORCPT ); Fri, 25 Nov 2022 19:58:02 -0500 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F3D5B5B5 for ; Fri, 25 Nov 2022 16:58:00 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R741e4;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=4;SR=0;TI=SMTPD_---0VVgyv.D_1669424277; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VVgyv.D_1669424277) by smtp.aliyun-inc.com; Sat, 26 Nov 2022 08:57:58 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 1/2] erofs: support large folio in fscache mode Date: Sat, 26 Nov 2022 08:57:55 +0800 Message-Id: <20221126005756.7662-2-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20221126005756.7662-1-jefflexu@linux.alibaba.com> References: <20221126005756.7662-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When large folio supported, one folio can be split into several slices=EF= =BC=8C each of which may be mapped to META/UNMAPPED/MAPPED, and the folio can be unlocked as a whole only when all slices have completed. Thus always allocate erofs_fscache_request for each .read_folio() or .readahead(). In this case, only when all slices of the folio or folio range have completed, the request will be marked as completed and the folio or folio range will be unlocked then. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 116 +++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 68 deletions(-) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 3cfe1af7a46e..0643b205c7eb 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -167,32 +167,18 @@ static int erofs_fscache_meta_read_folio(struct file = *data, struct folio *folio) return ret; } =20 -/* - * Read into page cache in the range described by (@pos, @len). - * - * On return, if the output @unlock is true, the caller is responsible for= page - * unlocking; otherwise the callee will take this responsibility through r= equest - * completion. - * - * The return value is the number of bytes successfully handled, or negati= ve - * error code on failure. The only exception is that, the length of the ra= nge - * instead of the error code is returned on failure after request is alloc= ated, - * so that .readahead() could advance rac accordingly. - */ -static int erofs_fscache_data_read(struct address_space *mapping, - loff_t pos, size_t len, bool *unlock) +static int erofs_fscache_data_read_slice(struct erofs_fscache_request *req) { + struct address_space *mapping =3D req->mapping; struct inode *inode =3D mapping->host; struct super_block *sb =3D inode->i_sb; - struct erofs_fscache_request *req; + loff_t pos =3D req->start + req->submitted; struct erofs_map_blocks map; struct erofs_map_dev mdev; struct iov_iter iter; size_t count; int ret; =20 - *unlock =3D true; - map.m_la =3D pos; ret =3D erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); if (ret) @@ -201,36 +187,37 @@ static int erofs_fscache_data_read(struct address_spa= ce *mapping, if (map.m_flags & EROFS_MAP_META) { struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; erofs_blk_t blknr; - size_t offset, size; + size_t offset; void *src; =20 /* For tail packing layout, the offset may be non-zero. */ offset =3D erofs_blkoff(map.m_pa); blknr =3D erofs_blknr(map.m_pa); - size =3D map.m_llen; + count =3D map.m_llen; =20 src =3D erofs_read_metabuf(&buf, sb, blknr, EROFS_KMAP); if (IS_ERR(src)) return PTR_ERR(src); =20 - iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, PAGE_SIZE); - if (copy_to_iter(src + offset, size, &iter) !=3D size) { + iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, count); + if (copy_to_iter(src + offset, count, &iter) !=3D count) { erofs_put_metabuf(&buf); return -EFAULT; } - iov_iter_zero(PAGE_SIZE - size, &iter); erofs_put_metabuf(&buf); - return PAGE_SIZE; + req->submitted +=3D count; + return 0; } =20 + count =3D req->len - req->submitted; if (!(map.m_flags & EROFS_MAP_MAPPED)) { - count =3D len; iov_iter_xarray(&iter, READ, &mapping->i_pages, pos, count); iov_iter_zero(count, &iter); - return count; + req->submitted +=3D count; + return 0; } =20 - count =3D min_t(size_t, map.m_llen - (pos - map.m_la), len); + count =3D min_t(size_t, map.m_llen - (pos - map.m_la), count); DBG_BUGON(!count || count % PAGE_SIZE); =20 mdev =3D (struct erofs_map_dev) { @@ -241,68 +228,61 @@ static int erofs_fscache_data_read(struct address_spa= ce *mapping, if (ret) return ret; =20 - req =3D erofs_fscache_req_alloc(mapping, pos, count); - if (IS_ERR(req)) - return PTR_ERR(req); - - *unlock =3D false; - ret =3D erofs_fscache_read_folios_async(mdev.m_fscache->cookie, + return erofs_fscache_read_folios_async(mdev.m_fscache->cookie, req, mdev.m_pa + (pos - map.m_la), count); - if (ret) - req->error =3D ret; +} =20 - erofs_fscache_req_put(req); - return count; +/* + * Read into page cache in the range described by (req->start, req->len). + */ +static int erofs_fscache_data_read(struct erofs_fscache_request *req) +{ + int ret; + + do { + ret =3D erofs_fscache_data_read_slice(req); + if (ret) + req->error =3D ret; + } while (!ret && req->submitted < req->len); + + return ret; } =20 static int erofs_fscache_read_folio(struct file *file, struct folio *folio) { - bool unlock; + struct erofs_fscache_request *req; int ret; =20 - DBG_BUGON(folio_size(folio) !=3D EROFS_BLKSIZ); - - ret =3D erofs_fscache_data_read(folio_mapping(folio), folio_pos(folio), - folio_size(folio), &unlock); - if (unlock) { - if (ret > 0) - folio_mark_uptodate(folio); + req =3D erofs_fscache_req_alloc(folio_mapping(folio), + folio_pos(folio), folio_size(folio)); + if (IS_ERR(req)) { folio_unlock(folio); + return PTR_ERR(req); } - return ret < 0 ? ret : 0; + + ret =3D erofs_fscache_data_read(req); + erofs_fscache_req_put(req); + return ret; } =20 static void erofs_fscache_readahead(struct readahead_control *rac) { - struct folio *folio; - size_t len, done =3D 0; - loff_t start, pos; - bool unlock; - int ret, size; + struct erofs_fscache_request *req; =20 if (!readahead_count(rac)) return; =20 - start =3D readahead_pos(rac); - len =3D readahead_length(rac); + req =3D erofs_fscache_req_alloc(rac->mapping, + readahead_pos(rac), readahead_length(rac)); + if (IS_ERR(req)) + return; =20 - do { - pos =3D start + done; - ret =3D erofs_fscache_data_read(rac->mapping, pos, - len - done, &unlock); - if (ret <=3D 0) - return; + /* The request completion will drop refs on the folios. */ + while (readahead_folio(rac)) + ; =20 - size =3D ret; - while (size) { - folio =3D readahead_folio(rac); - size -=3D folio_size(folio); - if (unlock) { - folio_mark_uptodate(folio); - folio_unlock(folio); - } - } - } while ((done +=3D ret) < len); + erofs_fscache_data_read(req); + erofs_fscache_req_put(req); } =20 static const struct address_space_operations erofs_fscache_meta_aops =3D { --=20 2.19.1.6.gb485710b From nobody Fri Sep 19 08:40:20 2025 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 D08E4C4167B for ; Sat, 26 Nov 2022 00:58:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiKZA6H (ORCPT ); Fri, 25 Nov 2022 19:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230080AbiKZA6E (ORCPT ); Fri, 25 Nov 2022 19:58:04 -0500 Received: from out199-13.us.a.mail.aliyun.com (out199-13.us.a.mail.aliyun.com [47.90.199.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6573A5C0E2 for ; Fri, 25 Nov 2022 16:58:03 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R321e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0VVgrtrD_1669424278; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VVgrtrD_1669424278) by smtp.aliyun-inc.com; Sat, 26 Nov 2022 08:57:59 +0800 From: Jingbo Xu To: xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 2/2] erofs: enable large folio support for non-compressed format Date: Sat, 26 Nov 2022 08:57:56 +0800 Message-Id: <20221126005756.7662-3-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.6.gb485710b In-Reply-To: <20221126005756.7662-1-jefflexu@linux.alibaba.com> References: <20221126005756.7662-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" Enable large folio in both device and fscache mode. Then the readahead routine will pass down large folio containing multiple pages. Enable this feature for non-compressed format for now, until the compression part supports large folio later. Signed-off-by: Jingbo Xu --- fs/erofs/fscache.c | 1 + fs/erofs/inode.c | 1 + 2 files changed, 2 insertions(+) diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c index 0643b205c7eb..d2dd58ce312b 100644 --- a/fs/erofs/fscache.c +++ b/fs/erofs/fscache.c @@ -436,6 +436,7 @@ struct erofs_fscache *erofs_fscache_acquire_cookie(stru= ct super_block *sb, inode->i_size =3D OFFSET_MAX; inode->i_mapping->a_ops =3D &erofs_fscache_meta_aops; mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); + mapping_set_large_folios(inode->i_mapping); =20 ctx->inode =3D inode; } diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index ad2a82f2eb4c..85932086d23f 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -295,6 +295,7 @@ static int erofs_fill_inode(struct inode *inode) goto out_unlock; } inode->i_mapping->a_ops =3D &erofs_raw_access_aops; + mapping_set_large_folios(inode->i_mapping); #ifdef CONFIG_EROFS_FS_ONDEMAND if (erofs_is_fscache_mode(inode->i_sb)) inode->i_mapping->a_ops =3D &erofs_fscache_access_aops; --=20 2.19.1.6.gb485710b