Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp61358lfe; Fri, 15 Apr 2022 19:33:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDwb/SoSwZ9BSHcHNm6BuuPEXOMQa5wg6xYwDY3mzsBqqZCwKYsrdC/mWQgxDoZILC4zdM X-Received: by 2002:a17:902:bc8c:b0:156:bc64:fa47 with SMTP id bb12-20020a170902bc8c00b00156bc64fa47mr1721608plb.135.1650076385443; Fri, 15 Apr 2022 19:33:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076385; cv=none; d=google.com; s=arc-20160816; b=pvPtqmuFHKo0jR284f0/a7xIv/nLkB4XzNRpvNwxK3xcujws4LUIWPZpcU6IdWSJtG z9VpOM9eeqytH89xuVS6ot5a1t/MrKaBGUNHXoHriCWo6qzdgylP54pfa1dISIK7eGtz F2of8NKbqroSwbO4YBdhfiiikQTcPt9ORTchdMayQAf4jw8dyFsGH5vg6Nt5CTxT+WzG DlcRqlzwE++LtN05ljjPzZNsbZOlaCu+blSXXExcdzKxDE3nUyKC4YBywIMiSjftRz1q t7H3K6UMpjuXW6SMbAoQKRp11UE9sFxVNsyXUtiUEsbMdeXkBLIE3x49EK/tX6TarYRX 8npw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7Lj/lzqgsK2QrSo+2NNYAhzupuoopz21Y86HhIcM5i4=; b=myz2EEtdnyB0UO/0DszEu3pHRY7sn3mSCXCQyFaKNB4zO3SDCXVmp6d9fdnltP9xdR 1vfO++6cpqsQepUH+pbI8y72bVpzCs3YHmxkDFXwTnF1tWdsxki0aHeTkTc7Gj8SMI3H 5wIGqf/pz3Ubb9yioYOi1b3qlDf+Gogc5PteSSVIYfmpF9dVj4bokro1VZcZrl2TtD4Q 35GuCrPQX5jwFe36zhF/xMm34KSSI1rtjQKDLXaq+/z1ux9zQ9beuF6ur8McoW4SXJH6 umgLaG49GKnQPlO4EZDpMwmBoel0RS1xxnlr+sO/dDsaW7YdQlc/QmrJqUWUq37zjwuU GWWw== 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:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d9-20020a056a00198900b004fb806eb0e6si3448646pfl.80.2022.04.15.19.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:33:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 19A44FFF49; Fri, 15 Apr 2022 18:42:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353525AbiDOMkv (ORCPT + 99 others); Fri, 15 Apr 2022 08:40:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353674AbiDOMjb (ORCPT ); Fri, 15 Apr 2022 08:39:31 -0400 Received: from out30-133.freemail.mail.aliyun.com (out30-133.freemail.mail.aliyun.com [115.124.30.133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE7D3C90C1; Fri, 15 Apr 2022 05:36:51 -0700 (PDT) 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=e01e04423;MF=jefflexu@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0VA7VPV2_1650026207; Received: from localhost(mailfrom:jefflexu@linux.alibaba.com fp:SMTPD_---0VA7VPV2_1650026207) by smtp.aliyun-inc.com(127.0.0.1); Fri, 15 Apr 2022 20:36:48 +0800 From: Jeffle Xu To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org, chao@kernel.org, linux-erofs@lists.ozlabs.org Cc: 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: [PATCH v9 20/21] erofs: implement fscache-based data readahead Date: Fri, 15 Apr 2022 20:36:13 +0800 Message-Id: <20220415123614.54024-21-jefflexu@linux.alibaba.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20220415123614.54024-1-jefflexu@linux.alibaba.com> References: <20220415123614.54024-1-jefflexu@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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; + } + } 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 c6755bcae4a6..f68ba929100d 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -619,6 +619,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; } else { if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) { erofs_err(sb, "failed to set erofs blksize"); -- 2.27.0