From: Changman Lee Subject: [PATCH] f2fs: change the reference of backgournd gc interval Date: Wed, 06 Feb 2013 17:56:37 +0900 Message-ID: <1360140997-17996-1-git-send-email-cm224.lee@samsung.com> Cc: Changman Lee To: linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Return-path: Received: from mailout1.samsung.com ([203.254.224.24]:61494 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750756Ab3BFI6T (ORCPT ); Wed, 6 Feb 2013 03:58:19 -0500 Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MHS00I7RJKYFPM0@mailout1.samsung.com> for linux-fsdevel@vger.kernel.org; Wed, 06 Feb 2013 17:58:11 +0900 (KST) Received: from lcm.kh.semi.local ([12.52.124.222]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MHS009CJJKV6850@mmp1.samsung.com> for linux-fsdevel@vger.kernel.org; Wed, 06 Feb 2013 17:58:11 +0900 (KST) Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This patch controls gc interval time according to fragmented ratio. It is difference between total free segments and usable free segments due to fragmentation. Background gc is for defragmentation. Signed-off-by: Changman Lee --- fs/f2fs/gc.c | 2 +- fs/f2fs/gc.h | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 742135a..68694c7 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -71,7 +71,7 @@ static int gc_thread_func(void *data) continue; } - if (has_enough_invalid_blocks(sbi)) + if (fragmented_ratio(sbi) > GC_FRAGMENT_RATIO_REF) wait_ms = decrease_sleep_time(wait_ms); else wait_ms = increase_sleep_time(wait_ms); diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index 30b2db0..07ca40d 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h @@ -16,8 +16,7 @@ #define GC_THREAD_MIN_SLEEP_TIME 10000 /* milliseconds */ #define GC_THREAD_MAX_SLEEP_TIME 30000 #define GC_THREAD_NOGC_SLEEP_TIME 10000 -#define LIMIT_INVALID_BLOCK 40 /* percentage over total user space */ -#define LIMIT_FREE_BLOCK 40 /* percentage over invalid + free space */ +#define GC_FRAGMENT_RATIO_REF 30 /* Search max. number of dirty segments to select a victim segment */ #define MAX_VICTIM_SEARCH 20 @@ -44,18 +43,6 @@ static inline block_t free_user_blocks(struct f2fs_sb_info *sbi) << sbi->log_blocks_per_seg; } -static inline block_t limit_invalid_user_blocks(struct f2fs_sb_info *sbi) -{ - return (long)(sbi->user_block_count * LIMIT_INVALID_BLOCK) / 100; -} - -static inline block_t limit_free_user_blocks(struct f2fs_sb_info *sbi) -{ - block_t reclaimable_user_blocks = sbi->user_block_count - - written_block_count(sbi); - return (long)(reclaimable_user_blocks * LIMIT_FREE_BLOCK) / 100; -} - static inline long increase_sleep_time(long wait) { wait += GC_THREAD_MIN_SLEEP_TIME; @@ -72,19 +59,14 @@ static inline long decrease_sleep_time(long wait) return wait; } -static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi) +static inline int fragmented_ratio(struct f2fs_sb_info *sbi) { - block_t invalid_user_blocks = sbi->user_block_count - - written_block_count(sbi); - /* - * Background GC is triggered with the following condition. - * 1. There are a number of invalid blocks. - * 2. There is not enough free space. - */ - if (invalid_user_blocks > limit_invalid_user_blocks(sbi) && - free_user_blocks(sbi) < limit_free_user_blocks(sbi)) - return true; - return false; + int free_segs = SM_I(sbi)->main_segments - + (written_block_count(sbi) >> sbi->log_blocks_per_seg); + int avail_free_segs = free_segments(sbi); + int ratio = (free_segs - avail_free_segs) * 100 / free_segs; + + return ratio; } static inline int is_idle(struct f2fs_sb_info *sbi) -- 1.7.9.5