Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp832078rdb; Sat, 7 Oct 2023 00:41:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGgAoiMZyLflFI28kVbbwj2kUAQ3hgYiRDmpihBm1rE4scquq+/XqPERBeeKvt1g+t/ucDi X-Received: by 2002:a05:620a:2408:b0:765:a77c:7219 with SMTP id d8-20020a05620a240800b00765a77c7219mr12286027qkn.0.1696664460354; Sat, 07 Oct 2023 00:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696664460; cv=none; d=google.com; s=arc-20160816; b=moDCFGTGfzCt6x96NyjXlZ4ksmEi2GSs/lZQLbfzlioLhZW+wTu1BPOMyR0CAWGYRd VKpMRnNZn7YJOinXvD0biSP9VlLW9AfibtGUIsZqbb1Iv/ZbueQoh5yrMZGljRuTP8Yz 8i5AH5rEIZIiArstZLZPv5/Yern1YgltfHWLxJzdIuv7Np07piR5JZ2oSsX042ua0Yw/ JoKVEejEzrDBXmUwug1ytqsop7o7MZhKUPTbB6QZJipMCVGF4YgeBN+GosudMxeYvsrJ xJMHQLSrPTynzjHYLyI8G40QHC0G/RYfxJX7JW47MnOnlbap4rTfEHxuZlq/JoRhXILA Ma9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=sBenpsV+sBSDlZFeO1XdnFRWCHx5t1Ml7axEpMKUykk=; fh=PHq4OuhOUUP7V1I+gDdMCZNzaT4vH9shSoLBu78e8bA=; b=oWf6uuLaIs0IkpmW9zyvg9YdY01umDG55zUCja7fNnnXEFsabixE0PxiToXq4cmHZf 1Nl1Z/8ODhp7Tm6TNyz1QMzZYbeGiyhdporsinvNXTvbDBdfUgxKP5uROQUgxzV/a1/1 flgljCW3BCkfh2s1vmu+Gvu2QQq5SZdmzqxwxNRwlT56VMMyIuuQWs/oc4fBKzSgXQjD Ntxah5bz1f8AsQpDM14n4D+cryMEwu6Srm0ypY/iYUPc0fhodTSyoXa60NPLaqRY8nOp 17XuFiuDW60c/Te89F1DWws95wtngZUdW1vE34EPiKBJOkIqPOq11Fll9n4sMGCkMuaW 45NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZD6BHLVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id e20-20020a656894000000b0057787e286c4si2956461pgt.680.2023.10.07.00.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 07 Oct 2023 00:41:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZD6BHLVL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 773C48077458; Sat, 7 Oct 2023 00:40:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343702AbjJGHkm (ORCPT + 99 others); Sat, 7 Oct 2023 03:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343690AbjJGHkk (ORCPT ); Sat, 7 Oct 2023 03:40:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4F6BB9 for ; Sat, 7 Oct 2023 00:40:39 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65BF4C433C7; Sat, 7 Oct 2023 07:40:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696664439; bh=QNdP6CzhDYNi4kZoC6kQSoWNk4vaR0KoYKoMwwnfCk0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=ZD6BHLVLeAO36MPjUMFZlQ3Ecnh8qiTLRZdfejreYwLcgJmWLK9rR7NhpFwqBrau8 4oFjd8xleln0VttlWWN0zcesnyf1iDRE59q82+INdEIFVpY2ZpxCBQDubDevB/sCpE J+45YDh/Bg8prgEqziRTMus8rCDdN2/KsipcCnJNfSk33of/M6NsoOdE1V8yiVBkrr SfG1CMPMpG0/Wbovjo1oy5iKFxY5sj5nJ8WfcjbbNJ4m50CTQN1rMOpj/UllFVvAs2 ExA8ZJPV6VqYdzEetODqywayAPc1DJEV5uZEjw0bPTz2CBiE/hR2nBbg46URxq1ig9 xQVMrZL075N0A== Message-ID: Date: Sat, 7 Oct 2023 15:40:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [f2fs-dev] [PATCH] f2fs: stop iterating f2fs_map_block if hole exists Content-Language: en-US To: Jaegeuk Kim , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net References: <20231003225208.1936359-1-jaegeuk@kernel.org> From: Chao Yu In-Reply-To: <20231003225208.1936359-1-jaegeuk@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=1.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 07 Oct 2023 00:40:57 -0700 (PDT) X-Spam-Level: * On 2023/10/4 6:52, Jaegeuk Kim wrote: > Let's avoid unnecessary f2fs_map_block calls to load extents. > > # f2fs_io fadvise willneed 0 4096 /data/local/tmp/test > > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 386, start blkaddr = 0x34ac00, len = 0x1400, flags = 2, > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 5506, start blkaddr = 0x34c200, len = 0x1000, flags = 2, > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 9602, start blkaddr = 0x34d600, len = 0x1200, flags = 2, > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 14210, start blkaddr = 0x34ec00, len = 0x400, flags = 2, > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 15235, start blkaddr = 0x34f401, len = 0xbff, flags = 2, > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 18306, start blkaddr = 0x350200, len = 0x1200, flags = 2 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 22915, start blkaddr = 0x351601, len = 0xa7d, flags = 2 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 25600, start blkaddr = 0x351601, len = 0x0, flags = 0 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 25601, start blkaddr = 0x351601, len = 0x0, flags = 0 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 25602, start blkaddr = 0x351601, len = 0x0, flags = 0 > ... > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 1037188, start blkaddr = 0x351601, len = 0x0, flags = 0 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 1038206, start blkaddr = 0x351601, len = 0x0, flags = 0 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 1039224, start blkaddr = 0x351601, len = 0x0, flags = 0 > f2fs_map_blocks: dev = (254,51), ino = 85845, file offset = 2075548, start blkaddr = 0x351601, len = 0x0, flags = 0 Jaegeuk, Not sure, but it looks it's due to f2fs_precache_extents() will traverse file w/ range [0, max_file_blocks), since data which exceeds EOF will always be zero, so it's not necessary to precache its mapping info, so we'd better adjust upper boundary to i_size rather than max_file_blocks(). > > Signed-off-by: Jaegeuk Kim > --- > fs/f2fs/file.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c > index 161826c6e200..2403fd1de5a0 100644 > --- a/fs/f2fs/file.c > +++ b/fs/f2fs/file.c > @@ -3270,7 +3270,7 @@ int f2fs_precache_extents(struct inode *inode) > f2fs_down_write(&fi->i_gc_rwsem[WRITE]); > err = f2fs_map_blocks(inode, &map, F2FS_GET_BLOCK_PRECACHE); > f2fs_up_write(&fi->i_gc_rwsem[WRITE]); > - if (err) > + if (err || !map.m_len) Well, if there is a hole in the head of file, it may break here rather than precaching following valid map info. What about passing parameter offset|len from f2fs_file_fadvise() to f2fs_precache_extents(), and then precaching mapping info on demand. Thanks, > return err; > > map.m_lblk = m_next_extent;