Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp139655pxb; Wed, 11 Nov 2020 23:01:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxl5SjIBmCiFbJfhKQTfZ5w/cGs4RLg+TOmqdOJQlsRaprE6k36GonDhCEt8w4obLlr+2HD X-Received: by 2002:a50:d582:: with SMTP id v2mr3717446edi.218.1605164495330; Wed, 11 Nov 2020 23:01:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605164495; cv=none; d=google.com; s=arc-20160816; b=X1C7XeLoJe1WMEpAPmQuycYh+gRPl7BjPjFuDKHJwjWMp4kqPAV2xY/w/eYAvusWD3 2CMhkG40Bzjc696qED7BUlsZ3RT9bw8CNF8SLcdEd1cCNGP2kPy6I9D4yrIp7XUqMPz3 pGZbimF3faX9WPRT6Mwu4wljWZ+E6HJKRP9jnyvEcgwdXiwSy/Qo5DnRIp27oXut8O8E HuDmVWU/WmoIXchDGic3K6SS0RbBDIpksIJSZ39wRBbdIevwAsOVwZOnuCXcSeOJxSv7 3EIvgW0RTaPtG8543lWlToXm5Dgw9e/0ZJukyYKNTKlQaFfQQQ2w7IX41zEM4lE4BOqB ZBtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=yL6Q11T32rKbSLFINtSC0Jx47hKoGRRO4rMIhccA//I=; b=uQZtUj8afRVlU61/MgUS/01p7KJPBANYXK4myh/L/2oKyAa17VPIIBBtnUQJZSK4vf /bwdo/lISNS4r/2Rb2njX9w9kNtqgGP+9I4LgVVxptkKX7jyJowerKvYIemYWYsy1VgX TMwUQysmdDmZ+QlVIJ/FLhYjWjOfV9QR6k0DX2XKmcZAef7go4w2Eoc2ygHuUbjLgdOM 8pyerAdREQudXq7dDPMzYOgFXKcg2X/R4iLYO/2wf1GIwclaC8Y0+yvE9m/eNU6nHkEB 9Gs2JXILBPscoW9GaYbGO1vQlxlVAoi8a+yUPsAg4MR3Kg/mxoXSXm7JqYwr0QjloNla B5Tw== 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 a3si3034068ejx.273.2020.11.11.23.01.10; Wed, 11 Nov 2020 23:01:35 -0800 (PST) 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 S1726774AbgKLG5e (ORCPT + 99 others); Thu, 12 Nov 2020 01:57:34 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:8067 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725898AbgKLG53 (ORCPT ); Thu, 12 Nov 2020 01:57:29 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CWspy39nHzLxcb; Thu, 12 Nov 2020 14:57:14 +0800 (CST) Received: from [10.136.114.67] (10.136.114.67) by smtp.huawei.com (10.3.19.201) with Microsoft SMTP Server (TLS) id 14.3.487.0; Thu, 12 Nov 2020 14:57:22 +0800 Subject: Re: [f2fs-dev] [PATCH v3] f2fs: avoid race condition for shinker count To: Jaegeuk Kim , , , CC: Light Hsieh References: <20201109170012.2129411-1-jaegeuk@kernel.org> <20201112053414.GB3826485@google.com> <20201112054051.GA4092972@google.com> From: Chao Yu Message-ID: <4aae85c2-1829-06c0-8fd1-4148100dc0b9@huawei.com> Date: Thu, 12 Nov 2020 14:57:22 +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: <20201112054051.GA4092972@google.com> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/11/12 13:40, Jaegeuk Kim wrote: > Light reported sometimes shinker gets nat_cnt < dirty_nat_cnt resulting in > wrong do_shinker work. Let's avoid to get stale data by using nat_tree_lock. > > Reported-by: Light Hsieh > Signed-off-by: Jaegeuk Kim > --- > v3: > - fix to use NM_I(sbi) > > fs/f2fs/shrinker.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c > index d66de5999a26..555712ba06d8 100644 > --- a/fs/f2fs/shrinker.c > +++ b/fs/f2fs/shrinker.c > @@ -18,7 +18,11 @@ static unsigned int shrinker_run_no; > > static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi) > { > - long count = NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt; > + long count; > + > + down_read(&NM_I(sbi)->nat_tree_lock); > + count = NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt; > + up_read(&NM_I(sbi)->nat_tree_lock); > > return count > 0 ? count : 0; Minor thing, Just return count is enough? since count should never be smaller than 0. Anyway, Reviewed-by: Chao Yu Thanks, Thanks, > } >