Skip to content

Commit 287b140

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: introduce excess_dirty_threshold()
This patch enables f2fs_balance_fs_bg() to check all metadatas' dirty threshold rather than just checking node block's, so that checkpoint() from background can be triggered more frequently to avoid heaping up too much dirty metadatas. Threshold value by default: race with foreground ops single type global No 16MB 24MB Yes 24MB 36MB In addtion, let f2fs_balance_fs_bg() be aware of roll-forward sapce as well as fsync(). Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c02599f commit 287b140

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

fs/f2fs/f2fs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,9 @@ enum {
561561

562562
#define MAX_DIR_RA_PAGES 4 /* maximum ra pages of dir */
563563

564+
/* dirty segments threshold for triggering CP */
565+
#define DEFAULT_DIRTY_THRESHOLD 4
566+
564567
/* for in-memory extent cache entry */
565568
#define F2FS_MIN_EXTENT_LEN 64 /* minimum extent length */
566569

fs/f2fs/node.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ static inline bool excess_cached_nats(struct f2fs_sb_info *sbi)
138138
return NM_I(sbi)->nat_cnt[TOTAL_NAT] >= DEF_NAT_CACHE_THRESHOLD;
139139
}
140140

141-
static inline bool excess_dirty_nodes(struct f2fs_sb_info *sbi)
142-
{
143-
return get_pages(sbi, F2FS_DIRTY_NODES) >= sbi->blocks_per_seg * 8;
144-
}
145-
146141
enum mem_type {
147142
FREE_NIDS, /* indicates the free nid list */
148143
NAT_ENTRIES, /* indicates the cached nat entry */

fs/f2fs/segment.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,25 @@ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need)
529529
}
530530
}
531531

532+
static inline bool excess_dirty_threshold(struct f2fs_sb_info *sbi)
533+
{
534+
int factor = rwsem_is_locked(&sbi->cp_rwsem) ? 3 : 2;
535+
unsigned int dents = get_pages(sbi, F2FS_DIRTY_DENTS);
536+
unsigned int qdata = get_pages(sbi, F2FS_DIRTY_QDATA);
537+
unsigned int nodes = get_pages(sbi, F2FS_DIRTY_NODES);
538+
unsigned int meta = get_pages(sbi, F2FS_DIRTY_META);
539+
unsigned int imeta = get_pages(sbi, F2FS_DIRTY_IMETA);
540+
unsigned int threshold = sbi->blocks_per_seg * factor *
541+
DEFAULT_DIRTY_THRESHOLD;
542+
unsigned int global_threshold = threshold * 3 / 2;
543+
544+
if (dents >= threshold || qdata >= threshold ||
545+
nodes >= threshold || meta >= threshold ||
546+
imeta >= threshold)
547+
return true;
548+
return dents + qdata + nodes + meta + imeta > global_threshold;
549+
}
550+
532551
void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)
533552
{
534553
if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
@@ -547,8 +566,8 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg)
547566
else
548567
f2fs_build_free_nids(sbi, false, false);
549568

550-
if (excess_dirty_nats(sbi) || excess_dirty_nodes(sbi) ||
551-
excess_prefree_segs(sbi))
569+
if (excess_dirty_nats(sbi) || excess_dirty_threshold(sbi) ||
570+
excess_prefree_segs(sbi) || !f2fs_space_for_roll_forward(sbi))
552571
goto do_sync;
553572

554573
/* there is background inflight IO or foreground operation recently */

0 commit comments

Comments
 (0)