Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2970625pxa; Tue, 18 Aug 2020 03:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTB7czF71XBxIQ5Ec3JKkmk70oMdAZCptMr4YO90AcpZzZTWe5ricM0VfMwVb03plmCSI8 X-Received: by 2002:a50:c089:: with SMTP id k9mr18496285edf.110.1597745083903; Tue, 18 Aug 2020 03:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597745083; cv=none; d=google.com; s=arc-20160816; b=zeb/27/6VQotfcTaQCZylJ6woTdQp5LiuZ1Aj2TyrFA6AP/TqB8MbosrM8U3mMh6yi iCCotqHrS71CKTvYTq02fX0op0b6ftqqpr3qGR1SxRLLCEAEeeb9UPkclwIeHgdxMbP/ t87OFC1JcWdHLlZILOEN2AOILSMQJS1JbF4y+o49+Nh+2+CMSCAyF2jom+P8gfq0j9ow PEKuLb9EQehrktgmzgf7l4lFZcwuGz6OY1UNKYoKNN8FnRUWFoBeZ34wq70ksYJz56V0 nHJ43xzCpcuTn0u0kvFwZDv9sVb4dULASxFrH/tHG0dAA++wFfb73YJvEAtEATJEO+N4 qzQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=OqwJFNfrDh4cOW0++Owrw8FOG4qwjUVORRkax/e4zKA=; b=y5A1SH9mNZnyY0vgKELanb5VnbEFLThfkXUdTrjfWaFm76stK/NkxR36EclcthpreO Fl6HsNaqtiaxqnIl05rrGf0pcTIAgAGQabEusPFnd5bLihL1dsSvuEwAJIC+NLUhf7Nc UChd5/9gLTrEcBJGq7C6KmSmLLP9DSXJarYVHtQFlNk1dVYq2OHVoKx6WPE5vymvuUr5 otpt596cW9UOZZwyLWkeNnGwuT5S94DEti6dP0UPEKidjJN03gjEjs7IO61Rpw7FtFnv PnyztmTx4SjEyPTgr4bb9MPHL8Oj2xmotseGugkT2VX/sND3AopH4RAkvTUCC+YTb8wN G7Og== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si13195579edr.500.2020.08.18.03.04.20; Tue, 18 Aug 2020 03:04:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726451AbgHRKBm (ORCPT + 99 others); Tue, 18 Aug 2020 06:01:42 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:9758 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726145AbgHRKBm (ORCPT ); Tue, 18 Aug 2020 06:01:42 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 39D7F7C5D9FE4F502BC5; Tue, 18 Aug 2020 18:01:38 +0800 (CST) Received: from [10.136.114.67] (10.136.114.67) by smtp.huawei.com (10.3.19.202) with Microsoft SMTP Server (TLS) id 14.3.487.0; Tue, 18 Aug 2020 18:01:33 +0800 Subject: Re: [PATCH] f2fs: fix indefinite loop scanning for free nid To: Sahitya Tummala CC: Jaegeuk Kim , , References: <1597392335-4998-1-git-send-email-stummala@codeaurora.org> <20200818095547.GA5062@codeaurora.org> From: Chao Yu Message-ID: Date: Tue, 18 Aug 2020 18:01:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200818095547.GA5062@codeaurora.org> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.136.114.67] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/8/18 17:55, Sahitya Tummala wrote: > On Tue, Aug 18, 2020 at 04:29:05PM +0800, Chao Yu wrote: >> On 2020/8/14 16:05, Sahitya Tummala wrote: >>> If the sbi->ckpt->next_free_nid is not NAT block aligned and if there >>> are free nids in that NAT block between the start of the block and >>> next_free_nid, then those free nids will not be scanned in scan_nat_page(). >>> This results into mismatch between nm_i->available_nids and the sum of >>> nm_i->free_nid_count of all NAT blocks scanned. And nm_i->available_nids >>> will always be greater than the sum of free nids in all the blocks. >>> Under this condition, if we use all the currently scanned free nids, >>> then it will loop forever in f2fs_alloc_nid() as nm_i->available_nids >>> is still not zero but nm_i->free_nid_count of that partially scanned >>> NAT block is zero. >>> >>> Fix this to align the nm_i->next_scan_nid to the first nid of the >>> corresponding NAT block. >>> >>> Signed-off-by: Sahitya Tummala >>> --- >>> fs/f2fs/node.c | 2 ++ >>> 1 file changed, 2 insertions(+) >>> >>> diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c >>> index 9bbaa26..d615e59 100644 >>> --- a/fs/f2fs/node.c >>> +++ b/fs/f2fs/node.c >>> @@ -2402,6 +2402,8 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, >>> if (IS_ERR(page)) { >>> ret = PTR_ERR(page); >>> } else { >>> + if (nid % NAT_ENTRY_PER_BLOCK) >>> + nid = NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK; >> >> How about moving this logic to the beginning of __f2fs_build_free_nids(), >> after nid reset? >> > > Sure, I will move it. > >> BTW, it looks we can add unlikely in this judgment condition? > > But it may not be an unlikely as it can happen whenever checkpoint is done, > based on the next available free nid in function next_free_nid(), which can happen > quite a few times, right? Oh, yes, I missed that place, please ignore that suggestion.. :) Thanks, > > Hitting the loop forever issue condition due to this could be a rare/difficult to > reproduce but this check itself may not be unlikely in my opinion. > > Thanks, > >> >> Thanks, >> >>> ret = scan_nat_page(sbi, page, nid); >>> f2fs_put_page(page, 1); >>> } >>> >