Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b59d0bae authored by Namjae Jeon's avatar Namjae Jeon Committed by Jaegeuk Kim
Browse files

f2fs: add sysfs support for controlling the gc_thread



Add sysfs entries to control the timing parameters for
f2fs gc thread.

Various Sysfs options introduced are:
gc_min_sleep_time: Min Sleep time for GC in ms
gc_max_sleep_time: Max Sleep time for GC in ms
gc_no_gc_sleep_time: Default Sleep time for GC in ms

Cc: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: default avatarNamjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: default avatarPankaj Kumar <pankaj.km@samsung.com>
Reviewed-by: default avatarGu Zheng <guz.fnst@cn.fujitsu.com>
[Jaegeuk Kim: fix an umount bug and some minor changes]
Signed-off-by: default avatarJaegeuk Kim <jaegeuk.kim@samsung.com>
parent f0c5e565
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
What:		/sys/fs/f2fs/<disk>/gc_max_sleep_time
Date:		July 2013
Contact:	"Namjae Jeon" <namjae.jeon@samsung.com>
Description:
		 Controls the maximun sleep time for gc_thread. Time
		 is in milliseconds.

What:		/sys/fs/f2fs/<disk>/gc_min_sleep_time
Date:		July 2013
Contact:	"Namjae Jeon" <namjae.jeon@samsung.com>
Description:
		 Controls the minimum sleep time for gc_thread. Time
		 is in milliseconds.

What:		/sys/fs/f2fs/<disk>/gc_no_gc_sleep_time
Date:		July 2013
Contact:	"Namjae Jeon" <namjae.jeon@samsung.com>
Description:
		 Controls the default sleep time for gc_thread. Time
		 is in milliseconds.
+26 −0
Original line number Diff line number Diff line
@@ -132,6 +132,32 @@ f2fs. Each file shows the whole f2fs information.
 - average SIT information about whole segments
 - current memory footprint consumed by f2fs.

================================================================================
SYSFS ENTRIES
================================================================================

Information about mounted f2f2 file systems can be found in
/sys/fs/f2fs.  Each mounted filesystem will have a directory in
/sys/fs/f2fs based on its device name (i.e., /sys/fs/f2fs/sda).
The files in each per-device directory are shown in table below.

Files in /sys/fs/f2fs/<devname>
(see also Documentation/ABI/testing/sysfs-fs-f2fs)
..............................................................................
 File                         Content

 gc_max_sleep_time            This tuning parameter controls the maximum sleep
                              time for the garbage collection thread. Time is
                              in milliseconds.

 gc_min_sleep_time            This tuning parameter controls the minimum sleep
                              time for the garbage collection thread. Time is
                              in milliseconds.

 gc_no_gc_sleep_time          This tuning parameter controls the default sleep
                              time for the garbage collection thread. Time is
                              in milliseconds.

================================================================================
USAGE
================================================================================
+4 −0
Original line number Diff line number Diff line
@@ -430,6 +430,10 @@ struct f2fs_sb_info {
#endif
	unsigned int last_victim[2];		/* last victim segment # */
	spinlock_t stat_lock;			/* lock for stat operations */

	/* For sysfs suppport */
	struct kobject s_kobj;
	struct completion s_kobj_unregister;
};

/*
+11 −6
Original line number Diff line number Diff line
@@ -29,10 +29,11 @@ static struct kmem_cache *winode_slab;
static int gc_thread_func(void *data)
{
	struct f2fs_sb_info *sbi = data;
	struct f2fs_gc_kthread *gc_th = sbi->gc_thread;
	wait_queue_head_t *wq = &sbi->gc_thread->gc_wait_queue_head;
	long wait_ms;

	wait_ms = GC_THREAD_MIN_SLEEP_TIME;
	wait_ms = gc_th->min_sleep_time;

	do {
		if (try_to_freeze())
@@ -45,7 +46,7 @@ static int gc_thread_func(void *data)
			break;

		if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) {
			wait_ms = GC_THREAD_MAX_SLEEP_TIME;
			wait_ms = increase_sleep_time(gc_th, wait_ms);
			continue;
		}

@@ -66,15 +67,15 @@ static int gc_thread_func(void *data)
			continue;

		if (!is_idle(sbi)) {
			wait_ms = increase_sleep_time(wait_ms);
			wait_ms = increase_sleep_time(gc_th, wait_ms);
			mutex_unlock(&sbi->gc_mutex);
			continue;
		}

		if (has_enough_invalid_blocks(sbi))
			wait_ms = decrease_sleep_time(wait_ms);
			wait_ms = decrease_sleep_time(gc_th, wait_ms);
		else
			wait_ms = increase_sleep_time(wait_ms);
			wait_ms = increase_sleep_time(gc_th, wait_ms);

#ifdef CONFIG_F2FS_STAT_FS
		sbi->bg_gc++;
@@ -82,7 +83,7 @@ static int gc_thread_func(void *data)

		/* if return value is not zero, no victim was selected */
		if (f2fs_gc(sbi))
			wait_ms = GC_THREAD_NOGC_SLEEP_TIME;
			wait_ms = gc_th->no_gc_sleep_time;
	} while (!kthread_should_stop());
	return 0;
}
@@ -101,6 +102,10 @@ int start_gc_thread(struct f2fs_sb_info *sbi)
		goto out;
	}

	gc_th->min_sleep_time = DEF_GC_THREAD_MIN_SLEEP_TIME;
	gc_th->max_sleep_time = DEF_GC_THREAD_MAX_SLEEP_TIME;
	gc_th->no_gc_sleep_time = DEF_GC_THREAD_NOGC_SLEEP_TIME;

	sbi->gc_thread = gc_th;
	init_waitqueue_head(&sbi->gc_thread->gc_wait_queue_head);
	sbi->gc_thread->f2fs_gc_task = kthread_run(gc_thread_func, sbi,
+19 −14
Original line number Diff line number Diff line
@@ -13,9 +13,9 @@
						 * whether IO subsystem is idle
						 * or not
						 */
#define GC_THREAD_MIN_SLEEP_TIME	30000	/* milliseconds */
#define GC_THREAD_MAX_SLEEP_TIME	60000
#define GC_THREAD_NOGC_SLEEP_TIME	300000	/* wait 5 min */
#define DEF_GC_THREAD_MIN_SLEEP_TIME	30000	/* milliseconds */
#define DEF_GC_THREAD_MAX_SLEEP_TIME	60000
#define DEF_GC_THREAD_NOGC_SLEEP_TIME	300000	/* wait 5 min */
#define LIMIT_INVALID_BLOCK	40 /* percentage over total user space */
#define LIMIT_FREE_BLOCK	40 /* percentage over invalid + free space */

@@ -25,6 +25,11 @@
struct f2fs_gc_kthread {
	struct task_struct *f2fs_gc_task;
	wait_queue_head_t gc_wait_queue_head;

	/* for gc sleep time */
	unsigned int min_sleep_time;
	unsigned int max_sleep_time;
	unsigned int no_gc_sleep_time;
};

struct inode_entry {
@@ -56,25 +61,25 @@ static inline block_t limit_free_user_blocks(struct f2fs_sb_info *sbi)
	return (long)(reclaimable_user_blocks * LIMIT_FREE_BLOCK) / 100;
}

static inline long increase_sleep_time(long wait)
static inline long increase_sleep_time(struct f2fs_gc_kthread *gc_th, long wait)
{
	if (wait == GC_THREAD_NOGC_SLEEP_TIME)
	if (wait == gc_th->no_gc_sleep_time)
		return wait;

	wait += GC_THREAD_MIN_SLEEP_TIME;
	if (wait > GC_THREAD_MAX_SLEEP_TIME)
		wait = GC_THREAD_MAX_SLEEP_TIME;
	wait += gc_th->min_sleep_time;
	if (wait > gc_th->max_sleep_time)
		wait = gc_th->max_sleep_time;
	return wait;
}

static inline long decrease_sleep_time(long wait)
static inline long decrease_sleep_time(struct f2fs_gc_kthread *gc_th, long wait)
{
	if (wait == GC_THREAD_NOGC_SLEEP_TIME)
		wait = GC_THREAD_MAX_SLEEP_TIME;
	if (wait == gc_th->no_gc_sleep_time)
		wait = gc_th->max_sleep_time;

	wait -= GC_THREAD_MIN_SLEEP_TIME;
	if (wait <= GC_THREAD_MIN_SLEEP_TIME)
		wait = GC_THREAD_MIN_SLEEP_TIME;
	wait -= gc_th->min_sleep_time;
	if (wait <= gc_th->min_sleep_time)
		wait = gc_th->min_sleep_time;
	return wait;
}

Loading