Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3996411pxb; Tue, 17 Nov 2020 08:44:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJySR8XcH/1CMEKhIvmVtNcEbJ2BPFBzGx4u8WnY2dkDpZAp8W7CP2PdRomg+pGu250g4pxV X-Received: by 2002:a05:6402:b8e:: with SMTP id cf14mr20687727edb.86.1605631479432; Tue, 17 Nov 2020 08:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605631479; cv=none; d=google.com; s=arc-20160816; b=r+vuJrzqb+oRqU9rZPWrbZORsPBzd/g+t2OBhd7OfStrLDYi/tBCsrw1eq2cqBTa+j YMlbNVp5cxY1T267uK8f1yaXBhcacjXofqxBR2K8yyi7WtdkfzLwqwTJ9vYeoXySAdcQ Nbh2wfXT3oSZg2qC4hB273B3S52rKDZkS+Obxg3l9KPKm+kVDqYwMWJUz2XPQ/j8whoZ tZvWm6vFmr/69RLrLAdH0kD4xraNFxIjad+WSPEfzP+gGvo1k4QT2wb11rTE8OhcN3SF Urj1oqru0bmtvY+tnw9XJslX/lswVu9zgN/A+cgi6eliuCEO8uBz7dmcliyj4EpNQGl2 nUYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=G4nJyWOOgFVPNjN26OQYXP+EpUr8BtD9ZArelFtwfVM=; b=hg/6XFutoz+CXIcz3LNlqFsTw2NJWTB/ti5fUVpjVC6ECyakz6tp2hF5uNOIAsG3ER YM40Ci/2UpyjaEe1JyOTYWcrHk6kiboE9wFzxKbqPAeSrZRFh6bd7b4AVC1wQKsngveF M9uDDt45IhP7Lk7IyBkG1TOlm1Gg/8C9E1a0wx8PvLKwnNfreoTqExln+GAIlae1Cj6p E0vMM5okXAZ4xfDwBqGH7t8WG0p2vWDjIuwgPkzSwn8rcEqpAiTQ72VMpGGH6pZrwPKC TpYRShhtLDJIspuoTIFTjd1f6j3lCob6TJadNWsblCx+enBkRMh2+Va4cAM1/r3G+PUW JfyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AplUYdKV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m26si15531935edp.196.2020.11.17.08.44.15; Tue, 17 Nov 2020 08:44:39 -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; dkim=pass header.i=@kernel.org header.s=default header.b=AplUYdKV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbgKQQkY (ORCPT + 99 others); Tue, 17 Nov 2020 11:40:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:33278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725808AbgKQQkY (ORCPT ); Tue, 17 Nov 2020 11:40:24 -0500 Received: from google.com (unknown [104.132.1.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AE6CA21D7E; Tue, 17 Nov 2020 16:40:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605631224; bh=dVxDFAXp6FT9+XWoqU4EDdf3Oe33FE/vSylhfLqTJVk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AplUYdKVw+5q2guEA+7SSOzhDI0mbCO+QtVbEflBbv070cX030TV4iVc6rUOziYdB 27J3C+KSf4VJoMOGT0Nk5yUbx4D4xdvGG/KAwfqz3OZScMP4MBGXPAllELo+2XtJhJ kMzl/pywyeWOgjdAhxxyB8m69EHSLWVV/GlQjQRo= Date: Tue, 17 Nov 2020 08:40:21 -0800 From: Jaegeuk Kim To: Chao Yu Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Light Hsieh Subject: Re: [f2fs-dev] [PATCH v3] f2fs: avoid race condition for shinker count Message-ID: <20201117164021.GA1636127@google.com> References: <20201109170012.2129411-1-jaegeuk@kernel.org> <20201112053414.GB3826485@google.com> <20201112054051.GA4092972@google.com> <4aae85c2-1829-06c0-8fd1-4148100dc0b9@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4aae85c2-1829-06c0-8fd1-4148100dc0b9@huawei.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/12, Chao Yu wrote: > 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. Yeah, but let me keep this just in case. > > Anyway, > > Reviewed-by: Chao Yu > > Thanks, > > Thanks, > > > } > >