linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: avoid race condition for shinker count
@ 2020-11-09 17:00 Jaegeuk Kim
  2020-11-10  2:15 ` [f2fs-dev] " Chao Yu
  2020-11-12  5:34 ` [PATCH v2] " Jaegeuk Kim
  0 siblings, 2 replies; 13+ messages in thread
From: Jaegeuk Kim @ 2020-11-09 17:00 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel, kernel-team; +Cc: Jaegeuk Kim, Light Hsieh

Light reported sometimes shinker gets nat_cnt < dirty_nat_cnt resulting in
wrong do_shinker work. Basically the two counts should not happen like that.

So, I suspect this race condtion where:
- f2fs_try_to_free_nats            __flush_nat_entry_set
 nat_cnt=2, dirty_nat_cnt=2
                                   __clear_nat_cache_dirty
                                    spin_lock(nat_list_lock)
                                    list_move()
                                    spin_unlock(nat_list_lock)
 spin_lock(nat_list_lock)
 list_del()
 spin_unlock(nat_list_lock)
 nat_cnt=1, dirty_nat_cnt=2
                                   nat_cnt=1, dirty_nat_cnt=1

Reported-by: Light Hsieh <Light.Hsieh@mediatek.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/node.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 42394de6c7eb..e8ec65e40f06 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -269,11 +269,10 @@ static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,
 {
 	spin_lock(&nm_i->nat_list_lock);
 	list_move_tail(&ne->list, &nm_i->nat_entries);
-	spin_unlock(&nm_i->nat_list_lock);
-
 	set_nat_flag(ne, IS_DIRTY, false);
 	set->entry_cnt--;
 	nm_i->dirty_nat_cnt--;
+	spin_unlock(&nm_i->nat_list_lock);
 }
 
 static unsigned int __gang_lookup_nat_set(struct f2fs_nm_info *nm_i,
-- 
2.29.2.222.g5d2a92d10f8-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-12-03  8:17 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 17:00 [PATCH] f2fs: avoid race condition for shinker count Jaegeuk Kim
2020-11-10  2:15 ` [f2fs-dev] " Chao Yu
2020-11-10  4:19   ` Jaegeuk Kim
2020-11-10  6:04     ` Chao Yu
2020-11-12  5:31       ` Jaegeuk Kim
2020-11-12  5:34 ` [PATCH v2] " Jaegeuk Kim
2020-11-12  5:40   ` [f2fs-dev] [PATCH v3] " Jaegeuk Kim
2020-11-12  6:57     ` Chao Yu
2020-11-17 16:40       ` Jaegeuk Kim
2020-12-03  6:07     ` Jaegeuk Kim
2020-12-03  6:55       ` Chao Yu
2020-12-03  7:55         ` Jaegeuk Kim
2020-12-03  8:16           ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).