Przeglądaj źródła

f2fs: fix to search whole dirty segmap when get_victim

In ->get_victim we get max_search value from dirty_i->nr_dirty without
protection of seglist_lock, after that, nr_dirty can be increased/decreased
before we hold seglist_lock lock.
Then in main loop we attempt to traverse all dirty section one time to find
victim section, but it's not accurate to use max_search as the total loop count,
because we might lose checking several sections or check sections redundantly
for the case of nr_dirty are increased or decreased previously.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Chao Yu 11 lat temu
rodzic
commit
210f41bc04
1 zmienionych plików z 2 dodań i 2 usunięć
  1. 2 2
      fs/f2fs/gc.c

+ 2 - 2
fs/f2fs/gc.c

@@ -263,14 +263,14 @@ static int get_victim_by_default(struct f2fs_sb_info *sbi,
 	unsigned int secno, max_cost;
 	unsigned int secno, max_cost;
 	int nsearched = 0;
 	int nsearched = 0;
 
 
+	mutex_lock(&dirty_i->seglist_lock);
+
 	p.alloc_mode = alloc_mode;
 	p.alloc_mode = alloc_mode;
 	select_policy(sbi, gc_type, type, &p);
 	select_policy(sbi, gc_type, type, &p);
 
 
 	p.min_segno = NULL_SEGNO;
 	p.min_segno = NULL_SEGNO;
 	p.min_cost = max_cost = get_max_cost(sbi, &p);
 	p.min_cost = max_cost = get_max_cost(sbi, &p);
 
 
-	mutex_lock(&dirty_i->seglist_lock);
-
 	if (p.alloc_mode == LFS && gc_type == FG_GC) {
 	if (p.alloc_mode == LFS && gc_type == FG_GC) {
 		p.min_segno = check_bg_victims(sbi);
 		p.min_segno = check_bg_victims(sbi);
 		if (p.min_segno != NULL_SEGNO)
 		if (p.min_segno != NULL_SEGNO)