Commit 7f3037a5 authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: check free_sections for defragmentation

Fix wrong condition check for defragmentation of a file.
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent ed214a11
...@@ -1293,7 +1293,7 @@ static int f2fs_write_data_page(struct page *page, ...@@ -1293,7 +1293,7 @@ static int f2fs_write_data_page(struct page *page,
if (!wbc->for_reclaim) if (!wbc->for_reclaim)
need_balance_fs = true; need_balance_fs = true;
else if (has_not_enough_free_secs(sbi, 0)) else if (has_not_enough_free_secs(sbi, 0, 0))
goto redirty_out; goto redirty_out;
err = -EAGAIN; err = -EAGAIN;
...@@ -1625,7 +1625,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, ...@@ -1625,7 +1625,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping,
if (err) if (err)
goto fail; goto fail;
if (need_balance && has_not_enough_free_secs(sbi, 0)) { if (need_balance && has_not_enough_free_secs(sbi, 0, 0)) {
unlock_page(page); unlock_page(page);
f2fs_balance_fs(sbi, true); f2fs_balance_fs(sbi, true);
lock_page(page); lock_page(page);
......
...@@ -1961,7 +1961,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, ...@@ -1961,7 +1961,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
* avoid defragment running in SSR mode when free section are allocated * avoid defragment running in SSR mode when free section are allocated
* intensively * intensively
*/ */
if (has_not_enough_free_secs(sbi, sec_num)) { if (has_not_enough_free_secs(sbi, 0, sec_num)) {
err = -EAGAIN; err = -EAGAIN;
goto out; goto out;
} }
......
...@@ -439,7 +439,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi, ...@@ -439,7 +439,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
struct node_info ni; struct node_info ni;
/* stop BG_GC if there is not enough free sections. */ /* stop BG_GC if there is not enough free sections. */
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0)) if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
return; return;
if (check_valid_map(sbi, segno, off) == 0) if (check_valid_map(sbi, segno, off) == 0)
...@@ -715,7 +715,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, ...@@ -715,7 +715,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
nid_t nid = le32_to_cpu(entry->nid); nid_t nid = le32_to_cpu(entry->nid);
/* stop BG_GC if there is not enough free sections. */ /* stop BG_GC if there is not enough free sections. */
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0)) if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
return; return;
if (check_valid_map(sbi, segno, off) == 0) if (check_valid_map(sbi, segno, off) == 0)
...@@ -916,7 +916,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync) ...@@ -916,7 +916,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync)
goto stop; goto stop;
} }
if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed)) { if (gc_type == BG_GC && has_not_enough_free_secs(sbi, sec_freed, 0)) {
gc_type = FG_GC; gc_type = FG_GC;
/* /*
* If there is no victim and no prefree segment but still not * If there is no victim and no prefree segment but still not
...@@ -927,7 +927,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync) ...@@ -927,7 +927,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync)
prefree_segments(sbi)) { prefree_segments(sbi)) {
write_checkpoint(sbi, &cpc); write_checkpoint(sbi, &cpc);
segno = NULL_SEGNO; segno = NULL_SEGNO;
} else if (has_not_enough_free_secs(sbi, 0)) { } else if (has_not_enough_free_secs(sbi, 0, 0)) {
write_checkpoint(sbi, &cpc); write_checkpoint(sbi, &cpc);
} }
} }
...@@ -944,7 +944,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync) ...@@ -944,7 +944,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync)
sbi->cur_victim_sec = NULL_SEGNO; sbi->cur_victim_sec = NULL_SEGNO;
if (!sync) { if (!sync) {
if (has_not_enough_free_secs(sbi, sec_freed)) if (has_not_enough_free_secs(sbi, sec_freed, 0))
goto gc_more; goto gc_more;
if (gc_type == FG_GC) if (gc_type == FG_GC)
......
...@@ -356,7 +356,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) ...@@ -356,7 +356,7 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
* We should do GC or end up with checkpoint, if there are so many dirty * We should do GC or end up with checkpoint, if there are so many dirty
* dir/node pages without enough free segments. * dir/node pages without enough free segments.
*/ */
if (has_not_enough_free_secs(sbi, 0)) { if (has_not_enough_free_secs(sbi, 0, 0)) {
mutex_lock(&sbi->gc_mutex); mutex_lock(&sbi->gc_mutex);
f2fs_gc(sbi, false); f2fs_gc(sbi, false);
} }
...@@ -1278,7 +1278,7 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type) ...@@ -1278,7 +1278,7 @@ static int get_ssr_segment(struct f2fs_sb_info *sbi, int type)
struct curseg_info *curseg = CURSEG_I(sbi, type); struct curseg_info *curseg = CURSEG_I(sbi, type);
const struct victim_selection *v_ops = DIRTY_I(sbi)->v_ops; const struct victim_selection *v_ops = DIRTY_I(sbi)->v_ops;
if (IS_NODESEG(type) || !has_not_enough_free_secs(sbi, 0)) if (IS_NODESEG(type) || !has_not_enough_free_secs(sbi, 0, 0))
return v_ops->get_victim(sbi, return v_ops->get_victim(sbi,
&(curseg)->next_segno, BG_GC, type, SSR); &(curseg)->next_segno, BG_GC, type, SSR);
...@@ -1477,7 +1477,7 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, ...@@ -1477,7 +1477,7 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
/* direct_io'ed data is aligned to the segment for better performance */ /* direct_io'ed data is aligned to the segment for better performance */
if (direct_io && curseg->next_blkoff && if (direct_io && curseg->next_blkoff &&
!has_not_enough_free_secs(sbi, 0)) !has_not_enough_free_secs(sbi, 0, 0))
__allocate_new_segments(sbi, type); __allocate_new_segments(sbi, type);
*new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); *new_blkaddr = NEXT_FREE_BLKADDR(sbi, curseg);
......
...@@ -479,7 +479,8 @@ static inline bool need_SSR(struct f2fs_sb_info *sbi) ...@@ -479,7 +479,8 @@ static inline bool need_SSR(struct f2fs_sb_info *sbi)
reserved_sections(sbi) + 1); reserved_sections(sbi) + 1);
} }
static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi,
int freed, int needed)
{ {
int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES); int node_secs = get_blocktype_secs(sbi, F2FS_DIRTY_NODES);
int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS); int dent_secs = get_blocktype_secs(sbi, F2FS_DIRTY_DENTS);
...@@ -489,8 +490,8 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed) ...@@ -489,8 +490,8 @@ static inline bool has_not_enough_free_secs(struct f2fs_sb_info *sbi, int freed)
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
return false; return false;
return (free_sections(sbi) + freed) <= (node_secs + 2 * dent_secs + return (free_sections(sbi) + freed) <=
reserved_sections(sbi)); (node_secs + 2 * dent_secs + reserved_sections(sbi) + needed);
} }
static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi) static inline bool excess_prefree_segs(struct f2fs_sb_info *sbi)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment