Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp39845pxh; Thu, 7 Apr 2022 13:19:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4BInwf9s7I7eshbjwNiquEvfwx/4s8DQZLOFXt+mGb70xAvaFVkPAz9Iel856vdeZyMmS X-Received: by 2002:a05:6a00:e0b:b0:4fa:a167:5b35 with SMTP id bq11-20020a056a000e0b00b004faa1675b35mr16035192pfb.69.1649362746629; Thu, 07 Apr 2022 13:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649362746; cv=none; d=google.com; s=arc-20160816; b=le625x0+fBCpKgKJGzqPkHtJwinIxJlQ1OW8vTQPQ3D+YrjBvEmBMECNY4hhCNG/Qn 3pGf3P2JsIq4hZAUtG6GL3w3E3oR+nh6L5HVphiuUDppHxhqw6jlkHKVsG8v4G5rga6A 8G9DrsX1JS0Sme5DYMIHPkAW4UQQkqKpqQI6NqUsOOCVXnE6oymmYga70V3iF+SoITFT aCvumG5mM4dAy62NOabSGsp07iMZQFLvxQv8PklhMFbeIgyuhEfrUopeUYh4+9rpP5xR omC5Z4K6Hp972g83Df94rWG0KE3ezZKqxh9Foaqxb3IboD3kONXo2SPj8LoLebdQeAWz d5Iw== 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 :dkim-signature; bh=Sl7dO/jlhmn2v8RJkBCTalXCl2H0gke36wj05RuRdbU=; b=zN9bP+zWnRj9Ydu0G7BNmYpzZKm/nT1KV0lWud2CBEEQ5Z4RUDlZwGcKHmkTr/3Wh/ pyc8Brf+dU61GcozS0ctcHO1BYJFqiuyDwN5MjxodsC062tQesUg0TOJqozanoVVcT8i f/4JwyjoF3alZJaSGcwffezd5fYfzP7FMcNAzEcfDCJn8aP8UjYjVqrLcvrMlX6Sq/Sv B/Qm6ucHcHpOiHkEUFSKOqiwbwGbbQ4iedmMeYki9IaEj2QGN5o1Wuq6nvIbzyYKj3GI e6XHJhONIBd/MVpIP/xEUiH7bijH5fHli64q+xQlmIne3eaUYjbop8leDTmJ5S9ZzNCQ n59A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=prdLhdwW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y21-20020a056a00191500b004fa3a8dffc8si20802659pfi.127.2022.04.07.13.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:19:06 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=prdLhdwW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1B56B319A1A; Thu, 7 Apr 2022 12:37:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344114AbiDGOi7 (ORCPT + 99 others); Thu, 7 Apr 2022 10:38:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343935AbiDGOi4 (ORCPT ); Thu, 7 Apr 2022 10:38:56 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57D34168083; Thu, 7 Apr 2022 07:36:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7908ACE27B0; Thu, 7 Apr 2022 14:36:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75840C385A5; Thu, 7 Apr 2022 14:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649342211; bh=5+bk4CcEaJUSJAT88KegWTZKhFaoE5MAk1IU5Pfy8lw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=prdLhdwWpe2/mj0TsH26rPRdwQ2O7CAJEScgSz4yZPvPj0DznoTvWdFlHoGNsHETP bM0xB2CvHAXc4fMNceLCKL/wL9TzKsvUyth5kRsEbBT99fBh3QIHK/vG08ZSNeNvFG Q45wFK8Av8QYu84lRIbD3xojYHrL/U5Cokm5hLJ4YgmkO94cdaaTessd0RFo0BCQf7 ozdbgG5fV/fIIk/wXbPVBdtnYm/M40miSWd5iR4MzYlRBc4xos6Pb0YRZY5AI3jDZQ EPXXC3YU92bacJIT2byUS1vD/DDCbwJSY0jxEtMwnJlPgAowbHmvBjscDfKNSg/yL6 UBWIO1dujRJvA== Date: Thu, 7 Apr 2022 22:36:42 +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 Subject: Re: [PATCH v8 19/20] 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 References: <20220406075612.60298-1-jefflexu@linux.alibaba.com> <20220406075612.60298-20-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220406075612.60298-20-jefflexu@linux.alibaba.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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, Apr 06, 2022 at 03:56:11PM +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 | 94 ++++++++++++++++++++++++++++++++++++++++++++++ > fs/erofs/super.c | 4 ++ > 2 files changed, 98 insertions(+) > > diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c > index d32cb5840c6d..620d44210809 100644 > --- a/fs/erofs/fscache.c > +++ b/fs/erofs/fscache.c > @@ -148,12 +148,106 @@ static int erofs_fscache_readpage(struct file *file, struct page *page) > return ret; > } > > +static inline 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; > + > + /* > + * 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. > + */ I think such comment is really unneeded, we should calculate like below as always. Also I don't find o_la here anymore. > + offset = start + done; > + count = min_t(size_t, map.m_llen - (pos - map.m_la), len - done); > + > + /* Read-ahead Hole */ > + 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; > + } > + > + /* Read-ahead Inline */ Unnecessary comment. > + 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; > + } > + > + /* Read-ahead No-inline */ Same here. Thanks, Gao Xiang > + 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; > + } > + } while (ret > 0 && ((done += ret) < len)); > +} > + > static const struct address_space_operations erofs_fscache_meta_aops = { > .readpage = erofs_fscache_meta_readpage, > }; > > const struct address_space_operations erofs_fscache_access_aops = { > .readpage = erofs_fscache_readpage, > + .readahead = erofs_fscache_readahead, > }; > > /* > diff --git a/fs/erofs/super.c b/fs/erofs/super.c > index 8c7181cd37e6..a5e4de60a0d8 100644 > --- a/fs/erofs/super.c > +++ b/fs/erofs/super.c > @@ -621,6 +621,10 @@ static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc) > sbi->opt.fsid, true); > if (err) > return err; > + > + err = super_setup_bdi(sb); > + if (err) > + return err; > } > > err = erofs_read_superblock(sb); > -- > 2.27.0 >