From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEABBC433FE for ; Mon, 7 Feb 2022 10:58:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237343AbiBGK5g (ORCPT ); Mon, 7 Feb 2022 05:57:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239777AbiBGKwn (ORCPT ); Mon, 7 Feb 2022 05:52:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13EE7C043188 for ; Mon, 7 Feb 2022 02:52:42 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id D1612B81155 for ; Mon, 7 Feb 2022 10:52:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B21CC004E1; Mon, 7 Feb 2022 10:52:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644231157; bh=4ATjmwQWrWNsd8mIpMoQ9gflII5gdGxVmQOUkiK1jeI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Viwljx2pyN+bCAmT6+rE8UPCHx6KT2MK0nbAsJN81Q/PIsT/4WUZdHDNQ09XqVixG L65EM2DQI4E5ugy5XltyVMTna6ZhZaS6xdrZEx2QgL51gqZHfGcozbavK3HXqV484C jQsJo8u8SJDtKoiUYKGD8Q3H8zYAlFfKGP7SJ/dMEWIHnNwyYGuXf9hkU1US6wB9e4 ZkbZWDA2gkiw20YTHGLLmV3LCLmp5SGfOfsm5sCg7o88zA6O1zg/7yI1AaBGx9uAwS TRkP3gLDWnP8L6VSczJbQ2oI4XXtZwWUbdP51kclpfRq6J+YPTrRy5nom6kz7ZLirk SjzUe2Kl0kjYg== Date: Mon, 7 Feb 2022 10:52:34 +0000 From: Filipe Manana To: Qu Wenruo Cc: linux-btrfs@vger.kernel.org Subject: Re: [PATCH] btrfs: populate extent_map::generation when reading from disk Message-ID: References: <817e735ee9c225268f17bee906c871b1fd965c4f.1644051267.git.wqu@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <817e735ee9c225268f17bee906c871b1fd965c4f.1644051267.git.wqu@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org On Sat, Feb 05, 2022 at 04:55:47PM +0800, Qu Wenruo wrote: > [WEIRD BEHAVIOR] > > When btrfs_get_extent() tries to get some file extent from disk, it > never populates extent_map::generation , leaving the value to be 0. > > On the other hand, for extent map generated by IO, it will get its > generation properly set at finish_ordered_io() > > finish_ordered_io() > |- unpin_extent_cache(gen = trans->transid) > |- em->generation = gen; > > [REGRESSION?] > I have no idea when such behavior is introduced, but at least in v5.15 > this incorrect behavior is already there. The extent map generation is basically only used by the fsync code, but as it deals only with modified extents, it always sees non-zero generation. > > [AFFECT] > Not really sure if there is any behavior really get affected. affect -> effect No, I don't think it affects anything. > > Sure there are locations like extent map merging, but there is no value > smaller than 0 for u64, thus it won't really cause a difference. > > For autodefrag, although it's checking em->generation to determine if we > need to defrag a range, but that @new_than value is always from IO, thus This is confusing. You mean the minimum generation threshold for autodefrag. Referring to a function parameter (and it's named "newer_than") out of context, is hard to follow. > all those extent maps with 0 generation will just be skipped, and that's > the expected behavior anyway. > > For manual defrag, @newer_than is 0, and our check is to skip generation > smaller than @newer_than, thus it still makes no difference. Same here, saying the minimum generation threshold for defrag is more informative than referring to the name of a function parameter. A function that is not even touched by the patch makes it hard to understand. > > [FIX] > To make things less weird, let us populate extent_map::generation in > btrfs_extent_item_to_extent_map(). Looks good. Though I don't think this fixes anything. As I pointed out in the other thread, the extent map generation is basically only I used by fsync, which doesn't use extent maps that are not the in the list of modified extents (and those always have a generation > 0). Thnaks. > > Signed-off-by: Qu Wenruo > --- > fs/btrfs/file-item.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c > index 90c5c38836ab..9a3de652ada8 100644 > --- a/fs/btrfs/file-item.c > +++ b/fs/btrfs/file-item.c > @@ -1211,6 +1211,7 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode, > extent_start = key.offset; > extent_end = btrfs_file_extent_end(path); > em->ram_bytes = btrfs_file_extent_ram_bytes(leaf, fi); > + em->generation = btrfs_file_extent_generation(leaf, fi); > if (type == BTRFS_FILE_EXTENT_REG || > type == BTRFS_FILE_EXTENT_PREALLOC) { > em->start = extent_start; > -- > 2.35.0 >