Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp995605pxp; Wed, 16 Mar 2022 23:51:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUmaxGiSckRGcQr781GGG5eSdW8lbd4yDzGYIWHBHmagCOtImcJNd9GQ5fYShp9ePNUiwG X-Received: by 2002:a62:30c4:0:b0:4f7:2b29:984 with SMTP id w187-20020a6230c4000000b004f72b290984mr3429216pfw.11.1647499909754; Wed, 16 Mar 2022 23:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647499909; cv=none; d=google.com; s=arc-20160816; b=zqzn6gd9NFogCZBLJjzanYnB27kzcuyOE4xy2sgLgfGaWEtE3LnMJqzyo2rlHRX+3v eye44CCMwhwzURDQyB1XhDBi5qSSlCQNkwER5YXVKoms55hpP+qBUCINkpWXrChlgEU6 ujZBdM83gA3sGGcWDXUryydw48Nx+Zpgl1Vhg8sPhId/gyxRJNLLmgdZZ5wQ2Y3BjcgJ dLhRWR8I8+G2+tIwHw466vyYmd4xdejjkPDWJxLyP9sM+fNZR6OaZctFyJrZmIov1BSs 7KtdAk0l7simPt7+AtbzVEGDVbrD2BndKCEg30UMNpCbSCzzEiW3h441fQKYcsMuvBFP E+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=RZJot0qC1NbsRpiUYRzFfkbmuoZXeHh71PdaU0F0OW0=; b=MdwNz/bvnkkNsNplFC/hRKAPCSm8iIe92Unu84bzGs6f4+dmgDDREb/698e74XUWe2 WQcjysL1kt89SGXzVPsnZD0iTpXV2nQ7t581Ydu8n2stvp+yh6gvOFdLzjD7tyVvhlbq iywjNPjqanX1npZMo2CDoDRX/4J4ZpfyyzOmAshyPVJIrt7Py1via9qrDtoZasOb/KDM 1M8+tSZRhwU0U5uxLVFOSYXldCWcSX/Sbx7lHhDGoEmFJo8oofF92L0iE+jHhMTUe5wI C+aw48pQpBX5iCb+i41rzHkgoRMQcN1bEtXzzCT5B850c23zWrCQJRqNm37U2jbRSQOo sdMg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r16-20020a632b10000000b003816043eee9si1242439pgr.222.2022.03.16.23.51.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:51:49 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EF9132C4934; Wed, 16 Mar 2022 22:56:38 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229493AbiCQFwK (ORCPT + 99 others); Thu, 17 Mar 2022 01:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbiCQFwH (ORCPT ); Thu, 17 Mar 2022 01:52:07 -0400 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D161A1EA2A7; Wed, 16 Mar 2022 22:23:02 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04357;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0V7QF66W_1647494576; Received: from B-P7TQMD6M-0146.local(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0V7QF66W_1647494576) by smtp.aliyun-inc.com(127.0.0.1); Thu, 17 Mar 2022 13:22:59 +0800 Date: Thu, 17 Mar 2022 13:22:56 +0800 From: Gao Xiang To: Jeffle Xu Cc: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com Subject: Re: [PATCH v5 21/22] erofs: implement fscache-based data readahead Message-ID: Mail-Followup-To: Jeffle Xu , dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org, torvalds@linux-foundation.org, gregkh@linuxfoundation.org, willy@infradead.org, linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com, gerry@linux.alibaba.com, eguan@linux.alibaba.com, linux-kernel@vger.kernel.org, luodaowen.backend@bytedance.com References: <20220316131723.111553-1-jefflexu@linux.alibaba.com> <20220316131723.111553-22-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220316131723.111553-22-jefflexu@linux.alibaba.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 16, 2022 at 09:17:22PM +0800, Jeffle Xu wrote: > This patch implements fscache-based data readahead. Also registers an > individual bdi for each erofs instance to enable readahead. > > Signed-off-by: Jeffle Xu > --- > fs/erofs/fscache.c | 153 +++++++++++++++++++++++++++++++++++++++++++++ > fs/erofs/super.c | 4 ++ > 2 files changed, 157 insertions(+) > > diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c > index 82c52b6e077e..913ca891deb9 100644 > --- a/fs/erofs/fscache.c > +++ b/fs/erofs/fscache.c > @@ -10,6 +10,13 @@ struct erofs_fscache_map { > u64 m_llen; > }; > > +struct erofs_fscahce_ra_ctx { typo, should be `erofs_fscache_ra_ctx' > + struct readahead_control *rac; > + struct address_space *mapping; > + loff_t start; > + size_t len, done; > +}; > + > static struct fscache_volume *volume; > > /* > @@ -199,12 +206,158 @@ static int erofs_fscache_readpage(struct file *file, struct page *page) > return ret; > } > > +static inline size_t erofs_fscache_calc_len(struct erofs_fscahce_ra_ctx *ractx, > + struct erofs_fscache_map *fsmap) > +{ > + /* > + * 1) For CHUNK_BASED layout, the output m_la is rounded down to the > + * nearest chunk boundary, and the output m_llen actually starts from > + * the start of the containing chunk. > + * 2) For other cases, the output m_la is equal to o_la. > + */ > + size_t len = fsmap->m_llen - (fsmap->o_la - fsmap->m_la); > + > + return min_t(size_t, len, ractx->len - ractx->done); > +} > + > +static inline void erofs_fscache_unlock_pages(struct readahead_control *rac, > + size_t len) Can we convert them into folios in advance? it seems much straight-forward to convert these... Or I have to convert them later, and it seems unnecessary... > +{ > + while (len) { > + struct page *page = readahead_page(rac); > + > + SetPageUptodate(page); > + unlock_page(page); > + put_page(page); > + > + len -= PAGE_SIZE; > + } > +} > + > +static int erofs_fscache_ra_hole(struct erofs_fscahce_ra_ctx *ractx, > + struct erofs_fscache_map *fsmap) > +{ > + struct iov_iter iter; > + loff_t start = ractx->start + ractx->done; > + size_t length = erofs_fscache_calc_len(ractx, fsmap); > + > + iov_iter_xarray(&iter, READ, &ractx->mapping->i_pages, start, length); > + iov_iter_zero(length, &iter); > + > + erofs_fscache_unlock_pages(ractx->rac, length); > + return length; > +} > + > +static int erofs_fscache_ra_noinline(struct erofs_fscahce_ra_ctx *ractx, > + struct erofs_fscache_map *fsmap) > +{ > + struct fscache_cookie *cookie = fsmap->m_ctx->cookie; > + loff_t start = ractx->start + ractx->done; > + size_t length = erofs_fscache_calc_len(ractx, fsmap); > + loff_t pstart = fsmap->m_pa + (fsmap->o_la - fsmap->m_la); > + int ret; > + > + ret = erofs_fscache_read_pages(cookie, ractx->mapping, > + start, length, pstart); > + if (!ret) { > + erofs_fscache_unlock_pages(ractx->rac, length); > + ret = length; > + } > + > + return ret; > +} > + > +static int erofs_fscache_ra_inline(struct erofs_fscahce_ra_ctx *ractx, > + struct erofs_fscache_map *fsmap) > +{ We could fold in this, since it has the only user. Thanks, Gao Xiang