Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp104672pxb; Wed, 11 Nov 2020 21:44:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/Ly1f7PHBjrjyuxlA1ps/vNt3qRZoFmR32WinzUTSXLajgeUFSaS5/f3GcMKV4H1CiFop X-Received: by 2002:a17:906:3a1a:: with SMTP id z26mr27999048eje.519.1605159845887; Wed, 11 Nov 2020 21:44:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605159845; cv=none; d=google.com; s=arc-20160816; b=ecFeuDbFN6MBedURk1YfAfzjnvI/3MMjcQGggVsjqNcZofIlgWaU1hAeoSWiSSZu6f Fhfn/GqIFfMeGWM6HmlR3HuNVXAGwCis0nOjnHIlztgG7dziO+mxtQ+8vvsk/VJmY1aN EMpSkzWJ77iWQvhXjlyByWZPIYsM9nYa/go+gTudCRfoJAfaPhrM1yPuTf8bhs452YnT q2C58FeTowB0zjKTagUvEsEipeluB2Pc/cidIJlQSitE2+LLm3+TpCOqXD3uIyG6DW15 sgd1a4jbx4tPM0JaAOWf/qCiqVtDbxKUaKbzyzFt3Vfy5wD77pa7qc5GUXF2f7XLGpfy Xg9Q== 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=U8G0ha90t1H5cLyuGdlEV3MH/sAgCPVpXdU4qvQUHM4=; b=Sz1cqcnhc944J4d5NF00hWelAnLOFr2idyyuPrbQC2OcpMxSW8jvbC6WQU3Y7INmdr eGBW+I6vKL+Mb65g1DQg41f4cVH7AohsfAbBmWs0HqCDcRUqpC/R6W5aH1obQvkUSksm 5LUUOFa2RCbQcUUZV4C88MfuUiP6S7KbWTjlZ7+ZJCf93EqUa/7FbBPlTp8HDqA7y0Rf Yma6+5cT6xNqUFsJTgHTxNY3R2Mqv85XoBEfqfC0HGoHtNMn8bEOveBnE+gUrgPorQjd K4CSg4EstZs3QSK/zVBKPgLjo4ebdBn1wsOwnkz5FjozpalHh4ObEksfNhPmIHiOg75p O1tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PiKTEyLd; 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 yl23si3254490ejb.441.2020.11.11.21.43.43; Wed, 11 Nov 2020 21:44:05 -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=PiKTEyLd; 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 S1728088AbgKLFm3 (ORCPT + 99 others); Thu, 12 Nov 2020 00:42:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:58762 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728370AbgKLFky (ORCPT ); Thu, 12 Nov 2020 00:40:54 -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 7D8D92076E; Thu, 12 Nov 2020 05:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605159653; bh=9ibzdXZrtU/gfZtcBKAW2NIKugLvAG+ui+6e39ewi8E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PiKTEyLd7zkM4dAJL0JwkU4r8FD/1zGISnh1O2j6Fgg7nxWHgiYKmk3Ofx5Iv4H8m CsVnvtp7UU6/v96eoYFTXpasUuFfJTiwmfNHWYS1DNFFZxwuiaZoheJVlrB8npDOnm p8iTb8HE0bzhqzXGbmCRpxFi8RC2S3V/hN+6B/0I= Date: Wed, 11 Nov 2020 21:40:51 -0800 From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Light Hsieh Subject: Re: [f2fs-dev] [PATCH v3] f2fs: avoid race condition for shinker count Message-ID: <20201112054051.GA4092972@google.com> References: <20201109170012.2129411-1-jaegeuk@kernel.org> <20201112053414.GB3826485@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201112053414.GB3826485@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.29.2.299.gdc1121823c-goog