linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] f2fs: introduce background_gc=sync mount option
@ 2015-10-05 22:43 Jaegeuk Kim
  2015-10-05 22:43 ` [PATCH 2/3] f2fs: add a tracepoint for background gc Jaegeuk Kim
  2015-10-05 22:44 ` [PATCH 3/3] f2fs: introduce a periodic checkpoint flow Jaegeuk Kim
  0 siblings, 2 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2015-10-05 22:43 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch introduce background_gc=sync enabling synchronous cleaning in
background.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 Documentation/filesystems/f2fs.txt |  3 ++-
 fs/f2fs/f2fs.h                     |  1 +
 fs/f2fs/gc.c                       |  2 +-
 fs/f2fs/segment.h                  |  4 +++-
 fs/f2fs/super.c                    | 21 +++++++++++++++------
 5 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index e2d5105..b102b43 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -102,7 +102,8 @@ background_gc=%s       Turn on/off cleaning operations, namely garbage
                        collection, triggered in background when I/O subsystem is
                        idle. If background_gc=on, it will turn on the garbage
                        collection and if background_gc=off, garbage collection
-                       will be truned off.
+                       will be truned off. If background_gc=sync, it will turn
+                       on synchronous garbage collection running in background.
                        Default value for this option is on. So garbage
                        collection is on by default.
 disable_roll_forward   Disable the roll-forward recovery routine
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 18e5902..00bd470 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -53,6 +53,7 @@
 #define F2FS_MOUNT_NOBARRIER		0x00000800
 #define F2FS_MOUNT_FASTBOOT		0x00001000
 #define F2FS_MOUNT_EXTENT_CACHE		0x00002000
+#define F2FS_MOUNT_FORCE_FG_GC		0x00004000
 
 #define clear_opt(sbi, option)	(sbi->mount_opt.opt &= ~F2FS_MOUNT_##option)
 #define set_opt(sbi, option)	(sbi->mount_opt.opt |= F2FS_MOUNT_##option)
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 830d277..e627c19 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -78,7 +78,7 @@ static int gc_thread_func(void *data)
 		stat_inc_bggc_count(sbi);
 
 		/* if return value is not zero, no victim was selected */
-		if (f2fs_gc(sbi, false))
+		if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC)))
 			wait_ms = gc_th->no_gc_sleep_time;
 
 		/* balancing f2fs's metadata periodically */
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index a294da7..e9afb58 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -137,10 +137,12 @@ enum {
 /*
  * BG_GC means the background cleaning job.
  * FG_GC means the on-demand cleaning job.
+ * FORCE_FG_GC means on-demand cleaning job in background.
  */
 enum {
 	BG_GC = 0,
-	FG_GC
+	FG_GC,
+	FORCE_FG_GC,
 };
 
 /* for a function parameter to select a victim segment */
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 16442ec..ba058d0 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -292,11 +292,16 @@ static int parse_options(struct super_block *sb, char *options)
 
 			if (!name)
 				return -ENOMEM;
-			if (strlen(name) == 2 && !strncmp(name, "on", 2))
+			if (strlen(name) == 2 && !strncmp(name, "on", 2)) {
 				set_opt(sbi, BG_GC);
-			else if (strlen(name) == 3 && !strncmp(name, "off", 3))
+				clear_opt(sbi, FORCE_FG_GC);
+			} else if (strlen(name) == 3 && !strncmp(name, "off", 3)) {
 				clear_opt(sbi, BG_GC);
-			else {
+				clear_opt(sbi, FORCE_FG_GC);
+			} else if (strlen(name) == 4 && !strncmp(name, "sync", 4)) {
+				set_opt(sbi, BG_GC);
+				set_opt(sbi, FORCE_FG_GC);
+			} else {
 				kfree(name);
 				return -EINVAL;
 			}
@@ -631,10 +636,14 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
 {
 	struct f2fs_sb_info *sbi = F2FS_SB(root->d_sb);
 
-	if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC))
-		seq_printf(seq, ",background_gc=%s", "on");
-	else
+	if (!f2fs_readonly(sbi->sb) && test_opt(sbi, BG_GC)) {
+		if (test_opt(sbi, FORCE_FG_GC))
+			seq_printf(seq, ",background_gc=%s", "sync");
+		else
+			seq_printf(seq, ",background_gc=%s", "on");
+	} else {
 		seq_printf(seq, ",background_gc=%s", "off");
+	}
 	if (test_opt(sbi, DISABLE_ROLL_FORWARD))
 		seq_puts(seq, ",disable_roll_forward");
 	if (test_opt(sbi, DISCARD))
-- 
2.1.1


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

* [PATCH 2/3] f2fs: add a tracepoint for background gc
  2015-10-05 22:43 [PATCH 1/3] f2fs: introduce background_gc=sync mount option Jaegeuk Kim
@ 2015-10-05 22:43 ` Jaegeuk Kim
  2015-10-10  7:08   ` [f2fs-dev] " He YunLei
  2015-10-05 22:44 ` [PATCH 3/3] f2fs: introduce a periodic checkpoint flow Jaegeuk Kim
  1 sibling, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2015-10-05 22:43 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch introduces a tracepoint to monitor background gc behaviors.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/gc.c                |  3 +++
 include/trace/events/f2fs.h | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index e627c19..e7cec86 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -77,6 +77,9 @@ static int gc_thread_func(void *data)
 
 		stat_inc_bggc_count(sbi);
 
+		trace_f2fs_background_gc(sbi->sb, wait_ms,
+				prefree_segments(sbi), free_segments(sbi));
+
 		/* if return value is not zero, no victim was selected */
 		if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC)))
 			wait_ms = gc_th->no_gc_sleep_time;
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 6aa63d9..7de751d 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -514,6 +514,34 @@ TRACE_EVENT(f2fs_map_blocks,
 		__entry->ret)
 );
 
+TRACE_EVENT(f2fs_background_gc,
+
+	TP_PROTO(struct super_block *sb, long wait_ms,
+			unsigned int prefree, unsigned int free),
+
+	TP_ARGS(sb, wait_ms, prefree, free),
+
+	TP_STRUCT__entry(
+		__field(dev_t,	dev)
+		__field(long,	wait_ms)
+		__field(unsigned int,	prefree)
+		__field(unsigned int,	free)
+	),
+
+	TP_fast_assign(
+		__entry->dev		= sb->s_dev;
+		__entry->wait_ms	= wait_ms;
+		__entry->prefree	= prefree;
+		__entry->free		= free;
+	),
+
+	TP_printk("dev = (%d,%d), wait_ms = %ld, prefree = %u, free = %u",
+		show_dev(__entry),
+		__entry->wait_ms,
+		__entry->prefree,
+		__entry->free)
+);
+
 TRACE_EVENT(f2fs_get_victim,
 
 	TP_PROTO(struct super_block *sb, int type, int gc_type,
-- 
2.1.1


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

* [PATCH 3/3] f2fs: introduce a periodic checkpoint flow
  2015-10-05 22:43 [PATCH 1/3] f2fs: introduce background_gc=sync mount option Jaegeuk Kim
  2015-10-05 22:43 ` [PATCH 2/3] f2fs: add a tracepoint for background gc Jaegeuk Kim
@ 2015-10-05 22:44 ` Jaegeuk Kim
  2015-10-06 14:54   ` [f2fs-dev] " Chao Yu
  1 sibling, 1 reply; 7+ messages in thread
From: Jaegeuk Kim @ 2015-10-05 22:44 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch introduces a periodic checkpoint feature.
Note that, this is not enforcing to conduct checkpoints very strictly in terms
of trigger timing, instead just hope to help user experiences.
The default value is 60 seconds.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++++++
 fs/f2fs/checkpoint.c                    | 3 +++
 fs/f2fs/f2fs.h                          | 2 ++
 fs/f2fs/segment.c                       | 4 +++-
 fs/f2fs/super.c                         | 3 +++
 5 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 2c4cc42..e066281d 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -80,3 +80,9 @@ Date:		February 2015
 Contact:	"Jaegeuk Kim" <jaegeuk@kernel.org>
 Description:
 		 Controls the trimming rate in batch mode.
+
+What:		/sys/fs/f2fs/<disk>/cp_interval
+Date:		October 2015
+Contact:	"Jaegeuk Kim" <jaegeuk@kernel.org>
+Description:
+		 Controls the checkpoint timing.
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index da5ee7e..70a4780 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1120,6 +1120,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	if (cpc->reason == CP_RECOVERY)
 		f2fs_msg(sbi->sb, KERN_NOTICE,
 			"checkpoint: version = %llx", ckpt_ver);
+
+	/* do checkpoint periodically */
+	sbi->cp_expires = round_jiffies_up(jiffies + HZ * sbi->cp_interval);
 out:
 	mutex_unlock(&sbi->cp_mutex);
 	trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish checkpoint");
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 00bd470..aad4720 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -124,6 +124,7 @@ enum {
 		(SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
 #define BATCHED_TRIM_BLOCKS(sbi)	\
 		(BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
+#define DEF_CP_INTERVAL			60	/* 60 secs */
 
 struct cp_control {
 	int reason;
@@ -734,6 +735,7 @@ struct f2fs_sb_info {
 	struct rw_semaphore node_write;		/* locking node writes */
 	struct mutex writepages;		/* mutex for writepages() */
 	wait_queue_head_t cp_wait;
+	long cp_expires, cp_interval;		/* next expected periodic cp */
 
 	struct inode_management im[MAX_INO_ENTRY];      /* manage inode cache */
 
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index 6b8edf2..1d86a35 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -15,6 +15,7 @@
 #include <linux/prefetch.h>
 #include <linux/kthread.h>
 #include <linux/swap.h>
+#include <linux/timer.h>
 
 #include "f2fs.h"
 #include "segment.h"
@@ -315,7 +316,8 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
 	/* checkpoint is the only way to shrink partial cached entries */
 	if (!available_free_memory(sbi, NAT_ENTRIES) ||
 			excess_prefree_segs(sbi) ||
-			!available_free_memory(sbi, INO_ENTRIES))
+			!available_free_memory(sbi, INO_ENTRIES) ||
+			jiffies > sbi->cp_expires)
 		f2fs_sync_fs(sbi->sb, true);
 }
 
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index ba058d0..e275634 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -215,6 +215,7 @@ F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
 F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
 F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, cp_interval);
 
 #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
 static struct attribute *f2fs_attrs[] = {
@@ -231,6 +232,7 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(max_victim_search),
 	ATTR_LIST(dir_level),
 	ATTR_LIST(ram_thresh),
+	ATTR_LIST(cp_interval),
 	NULL,
 };
 
@@ -1014,6 +1016,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
 		atomic_set(&sbi->nr_pages[i], 0);
 
 	sbi->dir_level = DEF_DIR_LEVEL;
+	sbi->cp_interval = DEF_CP_INTERVAL;
 	clear_sbi_flag(sbi, SBI_NEED_FSCK);
 
 	INIT_LIST_HEAD(&sbi->s_list);
-- 
2.1.1


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

* RE: [f2fs-dev] [PATCH 3/3] f2fs: introduce a periodic checkpoint flow
  2015-10-05 22:44 ` [PATCH 3/3] f2fs: introduce a periodic checkpoint flow Jaegeuk Kim
@ 2015-10-06 14:54   ` Chao Yu
  2015-10-06 23:25     ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: Chao Yu @ 2015-10-06 14:54 UTC (permalink / raw)
  To: 'Jaegeuk Kim'; +Cc: linux-kernel, linux-fsdevel, linux-f2fs-devel

Hi Jaegeuk,

> -----Original Message-----
> From: Jaegeuk Kim [mailto:jaegeuk@kernel.org]
> Sent: Tuesday, October 06, 2015 6:44 AM
> To: linux-kernel@vger.kernel.org; linux-fsdevel@vger.kernel.org;
> linux-f2fs-devel@lists.sourceforge.net
> Cc: Jaegeuk Kim
> Subject: [f2fs-dev] [PATCH 3/3] f2fs: introduce a periodic checkpoint flow
> 
> This patch introduces a periodic checkpoint feature.
> Note that, this is not enforcing to conduct checkpoints very strictly in terms
> of trigger timing, instead just hope to help user experiences.
> The default value is 60 seconds.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

Looks good to me except one minor thing that it's better to add a cp_expires
initialization.

Please append all patches of patch set with:
Reviewed-by: Chao Yu <chao2.yu@samsung.com>

Thanks,

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

* Re: [f2fs-dev] [PATCH 3/3] f2fs: introduce a periodic checkpoint flow
  2015-10-06 14:54   ` [f2fs-dev] " Chao Yu
@ 2015-10-06 23:25     ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2015-10-06 23:25 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-kernel, linux-fsdevel, linux-f2fs-devel

On Tue, Oct 06, 2015 at 10:54:47PM +0800, Chao Yu wrote:
> Hi Jaegeuk,
> 
> > -----Original Message-----
> > From: Jaegeuk Kim [mailto:jaegeuk@kernel.org]
> > Sent: Tuesday, October 06, 2015 6:44 AM
> > To: linux-kernel@vger.kernel.org; linux-fsdevel@vger.kernel.org;
> > linux-f2fs-devel@lists.sourceforge.net
> > Cc: Jaegeuk Kim
> > Subject: [f2fs-dev] [PATCH 3/3] f2fs: introduce a periodic checkpoint flow
> > 
> > This patch introduces a periodic checkpoint feature.
> > Note that, this is not enforcing to conduct checkpoints very strictly in terms
> > of trigger timing, instead just hope to help user experiences.
> > The default value is 60 seconds.
> > 
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> 
> Looks good to me except one minor thing that it's better to add a cp_expires
> initialization.

Added. Thanks. :)

> 
> Please append all patches of patch set with:
> Reviewed-by: Chao Yu <chao2.yu@samsung.com>
> 
> Thanks,

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

* Re: [f2fs-dev] [PATCH 2/3] f2fs: add a tracepoint for background gc
  2015-10-05 22:43 ` [PATCH 2/3] f2fs: add a tracepoint for background gc Jaegeuk Kim
@ 2015-10-10  7:08   ` He YunLei
  2015-10-13 17:03     ` Jaegeuk Kim
  0 siblings, 1 reply; 7+ messages in thread
From: He YunLei @ 2015-10-10  7:08 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-kernel, linux-fsdevel, linux-f2fs-devel

On 2015/10/6 6:43, Jaegeuk Kim wrote:
> This patch introduces a tracepoint to monitor background gc behaviors.
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> ---
>   fs/f2fs/gc.c                |  3 +++
>   include/trace/events/f2fs.h | 28 ++++++++++++++++++++++++++++
>   2 files changed, 31 insertions(+)
>
> diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> index e627c19..e7cec86 100644
> --- a/fs/f2fs/gc.c
> +++ b/fs/f2fs/gc.c
> @@ -77,6 +77,9 @@ static int gc_thread_func(void *data)
>
>   		stat_inc_bggc_count(sbi);
>
> +		trace_f2fs_background_gc(sbi->sb, wait_ms,
> +				prefree_segments(sbi), free_segments(sbi));
> +
>   		/* if return value is not zero, no victim was selected */
>   		if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC)))
>   			wait_ms = gc_th->no_gc_sleep_time;
> diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
> index 6aa63d9..7de751d 100644
> --- a/include/trace/events/f2fs.h
> +++ b/include/trace/events/f2fs.h
> @@ -514,6 +514,34 @@ TRACE_EVENT(f2fs_map_blocks,
>   		__entry->ret)
>   );
>
> +TRACE_EVENT(f2fs_background_gc,
> +
> +	TP_PROTO(struct super_block *sb, long wait_ms,
> +			unsigned int prefree, unsigned int free),
> +
> +	TP_ARGS(sb, wait_ms, prefree, free),
> +
> +	TP_STRUCT__entry(
> +		__field(dev_t,	dev)
> +		__field(long,	wait_ms)
> +		__field(unsigned int,	prefree)
> +		__field(unsigned int,	free)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->dev		= sb->s_dev;
> +		__entry->wait_ms	= wait_ms;
> +		__entry->prefree	= prefree;
> +		__entry->free		= free;
> +	),
> +
> +	TP_printk("dev = (%d,%d), wait_ms = %ld, prefree = %u, free = %u",
> +		show_dev(__entry),
> +		__entry->wait_ms,
> +		__entry->prefree,
> +		__entry->free)
> +);
> +
hi,
     I open f2fs_background_gc and f2fs_get_victim trace points, first, the partition has no dirty segment, so no victim is
selected, wait_ms is equal to 300s.

     f2fs_gc-8:33-2827  [001] ....  5014.608396: f2fs_background_gc: dev = (8,33), wait_ms = 300000, prefree = 0, free = 73
     f2fs_gc-8:33-2827  [000] ....  5314.793436: f2fs_background_gc: dev = (8,33), wait_ms = 300000, prefree = 0, free = 73

     then I made the partition satisfied the condition of has_enough_invalid_blocks, gc can get a victim and do garbage collection, wait_ms = 30s

     f2fs_gc-8:33-2827  [001] ....  5614.978486: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 54
     f2fs_gc-8:33-2827  [001] ....  5614.978538: f2fs_get_victim: dev = (8,33), type = No TYPE, policy = (Background GC, LFS-mode, Cost-Benefit), victim = 441 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 54
     f2fs_gc-8:33-2827  [000] ....  5644.996989: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 54
     f2fs_gc-8:33-2827  [000] ....  5644.997027: f2fs_get_victim: dev = (8,33), type = No TYPE, policy = (Background GC, LFS-mode, Cost-Benefit), victim = 97 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 54

     when there no dirty segments left, I think wait_ms could turn back to 300s

     f2fs_gc-8:33-2827  [000] ....  6305.596205: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 1, free = 64
     f2fs_gc-8:33-2827  [001] ....  6605.781281: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
     f2fs_gc-8:33-2827  [000] ....  6905.966301: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
     f2fs_gc-8:33-2827  [001] ....  7206.151344: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
	
     here, background gc triggers every 300s, but wait_ms is still 30s, I don't know why?

Best wishes,
Thanks
>   TRACE_EVENT(f2fs_get_victim,
>
>   	TP_PROTO(struct super_block *sb, int type, int gc_type,
>


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

* Re: [f2fs-dev] [PATCH 2/3] f2fs: add a tracepoint for background gc
  2015-10-10  7:08   ` [f2fs-dev] " He YunLei
@ 2015-10-13 17:03     ` Jaegeuk Kim
  0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2015-10-13 17:03 UTC (permalink / raw)
  To: He YunLei; +Cc: linux-fsdevel, linux-kernel, linux-f2fs-devel

On Sat, Oct 10, 2015 at 03:08:26PM +0800, He YunLei wrote:
> On 2015/10/6 6:43, Jaegeuk Kim wrote:
> > This patch introduces a tracepoint to monitor background gc behaviors.
> >
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
> > ---
> >   fs/f2fs/gc.c                |  3 +++
> >   include/trace/events/f2fs.h | 28 ++++++++++++++++++++++++++++
> >   2 files changed, 31 insertions(+)
> >
> > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
> > index e627c19..e7cec86 100644
> > --- a/fs/f2fs/gc.c
> > +++ b/fs/f2fs/gc.c
> > @@ -77,6 +77,9 @@ static int gc_thread_func(void *data)
> >
> >   		stat_inc_bggc_count(sbi);
> >
> > +		trace_f2fs_background_gc(sbi->sb, wait_ms,
> > +				prefree_segments(sbi), free_segments(sbi));
> > +
> >   		/* if return value is not zero, no victim was selected */
> >   		if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC)))
> >   			wait_ms = gc_th->no_gc_sleep_time;
> > diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
> > index 6aa63d9..7de751d 100644
> > --- a/include/trace/events/f2fs.h
> > +++ b/include/trace/events/f2fs.h
> > @@ -514,6 +514,34 @@ TRACE_EVENT(f2fs_map_blocks,
> >   		__entry->ret)
> >   );
> >
> > +TRACE_EVENT(f2fs_background_gc,
> > +
> > +	TP_PROTO(struct super_block *sb, long wait_ms,
> > +			unsigned int prefree, unsigned int free),
> > +
> > +	TP_ARGS(sb, wait_ms, prefree, free),
> > +
> > +	TP_STRUCT__entry(
> > +		__field(dev_t,	dev)
> > +		__field(long,	wait_ms)
> > +		__field(unsigned int,	prefree)
> > +		__field(unsigned int,	free)
> > +	),
> > +
> > +	TP_fast_assign(
> > +		__entry->dev		= sb->s_dev;
> > +		__entry->wait_ms	= wait_ms;
> > +		__entry->prefree	= prefree;
> > +		__entry->free		= free;
> > +	),
> > +
> > +	TP_printk("dev = (%d,%d), wait_ms = %ld, prefree = %u, free = %u",
> > +		show_dev(__entry),
> > +		__entry->wait_ms,
> > +		__entry->prefree,
> > +		__entry->free)
> > +);
> > +
> hi,
>      I open f2fs_background_gc and f2fs_get_victim trace points, first, the partition has no dirty segment, so no victim is
> selected, wait_ms is equal to 300s.
> 
>      f2fs_gc-8:33-2827  [001] ....  5014.608396: f2fs_background_gc: dev = (8,33), wait_ms = 300000, prefree = 0, free = 73
>      f2fs_gc-8:33-2827  [000] ....  5314.793436: f2fs_background_gc: dev = (8,33), wait_ms = 300000, prefree = 0, free = 73
> 
>      then I made the partition satisfied the condition of has_enough_invalid_blocks, gc can get a victim and do garbage collection, wait_ms = 30s
> 
>      f2fs_gc-8:33-2827  [001] ....  5614.978486: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 54
>      f2fs_gc-8:33-2827  [001] ....  5614.978538: f2fs_get_victim: dev = (8,33), type = No TYPE, policy = (Background GC, LFS-mode, Cost-Benefit), victim = 441 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 54
>      f2fs_gc-8:33-2827  [000] ....  5644.996989: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 54
>      f2fs_gc-8:33-2827  [000] ....  5644.997027: f2fs_get_victim: dev = (8,33), type = No TYPE, policy = (Background GC, LFS-mode, Cost-Benefit), victim = 97 ofs_unit = 1, pre_victim_secno = -1, prefree = 0, free = 54
> 
>      when there no dirty segments left, I think wait_ms could turn back to 300s
> 
>      f2fs_gc-8:33-2827  [000] ....  6305.596205: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 1, free = 64
>      f2fs_gc-8:33-2827  [001] ....  6605.781281: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
>      f2fs_gc-8:33-2827  [000] ....  6905.966301: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
>      f2fs_gc-8:33-2827  [001] ....  7206.151344: f2fs_background_gc: dev = (8,33), wait_ms = 30000, prefree = 0, free = 65
> 	
>      here, background gc triggers every 300s, but wait_ms is still 30s, I don't know why?

Oh, it's due to the tracepoint timing.
In gc_thread_func(),
	do {
		wait with wait_ms = 300s

		decrease_sleep_time(&wait_ms); -> wait_ms = 30s
		tracepoint with wait_ms = 30s

		after f2fs_gc() call, wait_ms becomes 300s again.
	}

So, this patch should fix that.

>From 84e4214f0868ae77771837d0ed4cc6eff10738ba Mon Sep 17 00:00:00 2001
From: Jaegeuk Kim <jaegeuk@kernel.org>
Date: Tue, 13 Oct 2015 10:00:53 -0700
Subject: [PATCH] f2fs: relocate the tracepoint for background_gc

Once f2fs_gc is done, wait_ms is changed once more.
So, its tracepoint would be located after it.

Reported-by: He YunLei <heyunlei@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fs/f2fs/gc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index af7c24c..fedbf67 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -77,13 +77,13 @@ static int gc_thread_func(void *data)
 
 		stat_inc_bggc_count(sbi);
 
-		trace_f2fs_background_gc(sbi->sb, wait_ms,
-				prefree_segments(sbi), free_segments(sbi));
-
 		/* if return value is not zero, no victim was selected */
 		if (f2fs_gc(sbi, test_opt(sbi, FORCE_FG_GC)))
 			wait_ms = gc_th->no_gc_sleep_time;
 
+		trace_f2fs_background_gc(sbi->sb, wait_ms,
+				prefree_segments(sbi), free_segments(sbi));
+
 		/* balancing f2fs's metadata periodically */
 		f2fs_balance_fs_bg(sbi);
 
-- 
2.1.1



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

end of thread, other threads:[~2015-10-13 17:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-05 22:43 [PATCH 1/3] f2fs: introduce background_gc=sync mount option Jaegeuk Kim
2015-10-05 22:43 ` [PATCH 2/3] f2fs: add a tracepoint for background gc Jaegeuk Kim
2015-10-10  7:08   ` [f2fs-dev] " He YunLei
2015-10-13 17:03     ` Jaegeuk Kim
2015-10-05 22:44 ` [PATCH 3/3] f2fs: introduce a periodic checkpoint flow Jaegeuk Kim
2015-10-06 14:54   ` [f2fs-dev] " Chao Yu
2015-10-06 23:25     ` Jaegeuk Kim

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).