Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp105356pxb; Wed, 11 Nov 2020 21:45:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJwa+ONjZ+aGmBbxbNfCztS0XbjYNNYYZQJxdsw+MttYxHXhAhUMbgIrTP1RHYU9c64M4X36 X-Received: by 2002:a17:906:1e0c:: with SMTP id g12mr5962398ejj.115.1605159941966; Wed, 11 Nov 2020 21:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605159941; cv=none; d=google.com; s=arc-20160816; b=dUXahj31XvI4rStWjukHtwtynn5fsMuyk+9N9EeZzgWWSLZRUeqoG2NBnPRkfL84cq bly2A/tkPEIrKkAYWTTSTXg9h2JI3t/wEIKiLD04sBukFgCujwpq1ai8G4B/BanQFv5X ZywhsSznGOtclN8iwlqjiYBfoh2QgervXyQVQtjb799jTLsedF+rQHZDFMcUcORKH2pG Nia4gDHNCJqcaGDgep3vfbn98zyBKicxTNlVE6oJD+hbUloKVZkr9pGKe3W4P0LUq1Kh 41UNcjajP9TZSEbIEmkxJ4Kd8e0Dpgr+En3OxEza8k1zEQtCPWxmymuicZ9KWo0VabwJ jifA== 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=ZBSX/EIeNSI0wkno4qCaUlGyYH2qNvUKH3YAkYEaRGg=; b=d721dSk+IBJLk9EsSXHp1maxJE4u5ffAVG+1V/JVQoBNWK//+5lYpfujTQS25hOD08 Utf+aghwr8u1KtSU3QWsOGWhXVPGDKMppbr/AX0S7Z98Ig13EuVq9q2hwtUawyKHt0hT tQYsEr6jqXIdqYQxYBe39ZVHhZNVYwB9LeBGcJjyjqatyA3/gPZRIj/sny1gYYusH3uJ fXyskVC0pckdx5Lgd1cZ6T+6JdaDDLu08MnSkosGqBx2L/NpCReO3zM9ImfWORF9etL7 20GTFMmeuIwKmXvMa/twLPsFUXODUByZUlcL0ygikuGOJxx15MmQiEggw7s/c9NbM78t W9fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HJHcsZG4; 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 d14si3248383edu.275.2020.11.11.21.45.18; Wed, 11 Nov 2020 21:45:41 -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=HJHcsZG4; 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 S1727227AbgKLFmw (ORCPT + 99 others); Thu, 12 Nov 2020 00:42:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:54218 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728674AbgKLFeQ (ORCPT ); Thu, 12 Nov 2020 00:34:16 -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 9A8EE2076E; Thu, 12 Nov 2020 05:34:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605159255; bh=RR8tEZfeMTPWIeuF8jnjdhsKpk0uEkjI9YIlVtLy2Z8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HJHcsZG4oqKpJ00Cxo0SuPCErWUj06VNCY3Gcpn7Wy0coE6ebLG7pseJYOjMh0nMi TrZsYyVXrEHh0cRpK+LsOFtf3UjqZFrEwhFIJyxd0Mo4f5jnZvBtF2sqx3fs/hqVQ3 2ld478cO5eA1b+vc89TLNJa3VmUu5zI1ttlPX6fI= Date: Wed, 11 Nov 2020 21:34:14 -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: [PATCH v2] f2fs: avoid race condition for shinker count Message-ID: <20201112053414.GB3826485@google.com> References: <20201109170012.2129411-1-jaegeuk@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201109170012.2129411-1-jaegeuk@kernel.org> 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 --- 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..d42245ab07f4 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->nat_tree_lock); + count = NM_I(sbi)->nat_cnt - NM_I(sbi)->dirty_nat_cnt; + up_read(&nm_i->nat_tree_lock); return count > 0 ? count : 0; } -- 2.29.2.299.gdc1121823c-goog