Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp862291pxb; Thu, 21 Apr 2022 12:02:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZP0EWC4yF3V5EDk4R0DdJ/e0t6+bG12ahtDZjhhFBMsEPAk5tb1spK9KKxRcNTC6+4ZyN X-Received: by 2002:a17:90a:4308:b0:1cb:b996:1dc with SMTP id q8-20020a17090a430800b001cbb99601dcmr1154007pjg.224.1650567758904; Thu, 21 Apr 2022 12:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650567758; cv=none; d=google.com; s=arc-20160816; b=Q32LJV6GM10qNWmJZ8YkgBakpU3nst2NrEn0HtKSfwt35ht1zyADIDbrP0EHjybJa9 hMEWji8g5fgS/OsAtqS4goLcxDPIXMDVbxL7SW2vOY5tO01smaIpV2LnV7vvWL8+z9RG DcyR3CTwPBAyrxZfE1wZFTRyaLodqepUSx5CxiAZAKJVfY2Guj/lKi4kmqL2kZl9WXBk N5iaMMhIvLBOuQAHUNwEGDW3ctEH4OE+Ex4kS5aHW1tKMfiiTiUva+o5ICKTwQBWxs6l KDHxvpGqpe3R3J8nz4t1CsTRlOdIhlMRnrrtHlsJUzsHTQuiZNDxZunMsGfR46S8oa8i Zi0Q== 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=M+BWBDujfLbwIqArlepvTB97a0E7Cu4yW2STQAQ8LYw=; b=Mo/+RYfK7khIzMd5n5j6e2KmQj4UvDSqrSxTqHzZow/L3JCkLwMtdG6Fx0409+Fzqb ieWLUaX6UD+eUrUVtHxC/NtHVmvoNz989hPIzEGzkKrWTnFoZIyyEqiNKBpuhVbXOzIF iSbnHQ9S4pfVUowl+wSpyNLHg0fy5icZOpMsMnpVUxci3YRgYrv2duIMT11c2PcCQ4Jb gNbvnpOeiUKmZFEsHv84mRMrET1Z1TZGU9rSFlXZUp0gwPvq5VICTBD1oDDiqNx69Inq rrpG9pZo/178LMsvG7POGbs7iAZm/+PS3ghRz0P4MZJ+8SC0nDFZNKcnNyf69A6D0zub fezA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170902d4c500b00158eb7e5fcasi6955404plg.313.2022.04.21.12.02.18; Thu, 21 Apr 2022 12:02:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382597AbiDULyx (ORCPT + 99 others); Thu, 21 Apr 2022 07:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230158AbiDULyu (ORCPT ); Thu, 21 Apr 2022 07:54:50 -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 EA5592C656; Thu, 21 Apr 2022 04:51:59 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0VAf1GfK_1650541911; Received: from B-P7TQMD6M-0146.local(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VAf1GfK_1650541911) by smtp.aliyun-inc.com(127.0.0.1); Thu, 21 Apr 2022 19:51:54 +0800 Date: Thu, 21 Apr 2022 19:51:51 +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, tianzichen@kuaishou.com, fannaihao@baidu.com, zhangjiachen.jaycee@bytedance.com Subject: Re: [PATCH v9 20/21] 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, tianzichen@kuaishou.com, fannaihao@baidu.com, zhangjiachen.jaycee@bytedance.com References: <20220415123614.54024-1-jefflexu@linux.alibaba.com> <20220415123614.54024-21-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220415123614.54024-21-jefflexu@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham 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 Fri, Apr 15, 2022 at 08:36:13PM +0800, Jeffle Xu wrote: > Implement 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 | 86 ++++++++++++++++++++++++++++++++++++++++++++++ > fs/erofs/super.c | 4 +++ > 2 files changed, 90 insertions(+) > > diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c > index 08849c15500f..eaa50692ddba 100644 > --- a/fs/erofs/fscache.c > +++ b/fs/erofs/fscache.c > @@ -163,12 +163,98 @@ static int erofs_fscache_readpage(struct file *file, struct page *page) > return ret; > } > > +static void erofs_fscache_unlock_folios(struct readahead_control *rac, > + size_t len) > +{ > + while (len) { > + struct folio *folio = readahead_folio(rac); > + > + len -= folio_size(folio); > + folio_mark_uptodate(folio); > + folio_unlock(folio); > + } > +} > + > +static void erofs_fscache_readahead(struct readahead_control *rac) > +{ > + struct inode *inode = rac->mapping->host; > + struct super_block *sb = inode->i_sb; > + size_t len, count, done = 0; > + erofs_off_t pos; > + loff_t start, offset; > + int ret; > + > + if (!readahead_count(rac)) > + return; > + > + start = readahead_pos(rac); > + len = readahead_length(rac); > + > + do { > + struct erofs_map_blocks map; > + struct erofs_map_dev mdev; > + > + pos = start + done; > + map.m_la = pos; > + > + ret = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW); > + if (ret) > + return; > + > + offset = start + done; > + count = min_t(size_t, map.m_llen - (pos - map.m_la), > + len - done); > + > + if (!(map.m_flags & EROFS_MAP_MAPPED)) { > + struct iov_iter iter; > + > + iov_iter_xarray(&iter, READ, &rac->mapping->i_pages, > + offset, count); > + iov_iter_zero(count, &iter); > + > + erofs_fscache_unlock_folios(rac, count); > + ret = count; > + continue; > + } > + > + if (map.m_flags & EROFS_MAP_META) { > + struct folio *folio = readahead_folio(rac); > + > + ret = erofs_fscache_readpage_inline(folio, &map); > + if (!ret) { > + folio_mark_uptodate(folio); > + ret = folio_size(folio); > + } > + > + folio_unlock(folio); > + continue; > + } > + > + mdev = (struct erofs_map_dev) { > + .m_deviceid = map.m_deviceid, > + .m_pa = map.m_pa, > + }; > + ret = erofs_map_dev(sb, &mdev); > + if (ret) > + return; > + > + ret = erofs_fscache_read_folios(mdev.m_fscache->cookie, > + rac->mapping, offset, count, > + mdev.m_pa + (pos - map.m_la)); > + if (!ret) { > + erofs_fscache_unlock_folios(rac, count); > + ret = count; > + } I think this really needs a comment why we don't need to unlock folios for the error cases. Thanks, Gao Xiang > + } while (ret > 0 && ((done += ret) < len)); > +} > +