Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E27CC56201 for ; Thu, 19 Nov 2020 21:10:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB17D22255 for ; Thu, 19 Nov 2020 21:10:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726902AbgKSVK1 (ORCPT ); Thu, 19 Nov 2020 16:10:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:34732 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbgKSVK0 (ORCPT ); Thu, 19 Nov 2020 16:10:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 21588ABDE; Thu, 19 Nov 2020 21:10:25 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id D8F88DA701; Thu, 19 Nov 2020 22:08:38 +0100 (CET) Date: Thu, 19 Nov 2020 22:08:38 +0100 From: David Sterba To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH v2 03/24] btrfs: extent_io: replace extent_start/extent_len with better structure for end_bio_extent_readpage() Message-ID: <20201119210838.GL20563@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, Qu Wenruo , linux-btrfs@vger.kernel.org References: <20201113125149.140836-1-wqu@suse.com> <20201113125149.140836-4-wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201113125149.140836-4-wqu@suse.com> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Fri, Nov 13, 2020 at 08:51:28PM +0800, Qu Wenruo wrote: > In end_bio_extent_readpage() we had a strange dance around > extent_start/extent_len. > > Hides behind the strange dance is, it's just calling > endio_readpage_release_extent() on each bvec range. > > Here is an example to explain the original work flow: > Bio is for inode 257, containing 2 pages, for range [1M, 1M+8K) > > end_bio_extent_extent_readpage() entered > |- extent_start = 0; > |- extent_end = 0; > |- bio_for_each_segment_all() { > | |- /* Got the 1st bvec */ > | |- start = SZ_1M; > | |- end = SZ_1M + SZ_4K - 1; > | |- update = 1; > | |- if (extent_len == 0) { > | | |- extent_start = start; /* SZ_1M */ > | | |- extent_len = end + 1 - start; /* SZ_1M */ > | | } > | | > | |- /* Got the 2nd bvec */ > | |- start = SZ_1M + 4K; > | |- end = SZ_1M + 4K - 1; > | |- update = 1; > | |- if (extent_start + extent_len == start) { > | | |- extent_len += end + 1 - start; /* SZ_8K */ > | | } > | } /* All bio vec iterated */ > | > |- if (extent_len) { > |- endio_readpage_release_extent(tree, extent_start, extent_len, > update); > /* extent_start == SZ_1M, extent_len == SZ_8K, uptodate = 1 */ > > As the above flow shows, the existing code in end_bio_extent_readpage() > is just accumulate extent_start/extent_len, and when the contiguous range > breaks, call endio_readpage_release_extent() for the range. > > However current behavior has something not really considered: > - The inode can change > For bio, their pages don't need to have contig page_offset. > This means, even pages from different inode can be packed into one > bio. > > - Bvec cross page boundary > There is a feature called multi-page bvec, where bvec->bv_len can go > beyond bvec->bv_page boundary. > > - Poor readability > > This patch will address the problem by: > - Introduce a proper structure, processed_extent, to record processed > extent range > - Integrate inode/start/end/uptodate check into > endio_readpage_release_extent() > - Add more comment on each step. > This should greatly improve the readability, now in > end_bio_extent_readpage() there are only two > endio_readpage_release_extent() calls. > > - Add inode contig check > Now we also ensure the inode is the same before checking the range > contig. > > Signed-off-by: Qu Wenruo Added to misc-next.