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

Commit ae105fcb authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

f2fs: introduce reserved_blocks in sysfs



commit daeb433e42de97c79622f58681972200eec1d8da upstream.

In this patch, we add a new sysfs interface, with it, we can control
number of reserved blocks in system which could not be used by user,
it enable f2fs to let user to configure for adjusting over-provision
ratio dynamically instead of changing it by mkfs.

So we can expect it will help to reserve more free space for relieving
GC in both filesystem and flash device.

Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent c1984d0e
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -74,3 +74,59 @@ Date: March 2014
Contact:	"Jaegeuk Kim" <jaegeuk.kim@samsung.com>
Description:
		 Controls the memory footprint used by f2fs.

What:		/sys/fs/f2fs/<disk>/trim_sections
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.

What:		/sys/fs/f2fs/<disk>/idle_interval
Date:		January 2016
Contact:	"Jaegeuk Kim" <jaegeuk@kernel.org>
Description:
		 Controls the idle timing.

What:		/sys/fs/f2fs/<disk>/ra_nid_pages
Date:		October 2015
Contact:	"Chao Yu" <chao2.yu@samsung.com>
Description:
		 Controls the count of nid pages to be readaheaded.

What:		/sys/fs/f2fs/<disk>/dirty_nats_ratio
Date:		January 2016
Contact:	"Chao Yu" <chao2.yu@samsung.com>
Description:
		 Controls dirty nat entries ratio threshold, if current
		 ratio exceeds configured threshold, checkpoint will
		 be triggered for flushing dirty nat entries.

What:		/sys/fs/f2fs/<disk>/lifetime_write_kbytes
Date:		January 2016
Contact:	"Shuoran Liu" <liushuoran@huawei.com>
Description:
		 Shows total written kbytes issued to disk.

What:		/sys/fs/f2fs/<disk>/inject_rate
Date:		May 2016
Contact:	"Sheng Yong" <shengyong1@huawei.com>
Description:
		 Controls the injection rate.

What:		/sys/fs/f2fs/<disk>/inject_type
Date:		May 2016
Contact:	"Sheng Yong" <shengyong1@huawei.com>
Description:
		 Controls the injection type.

What:		/sys/fs/f2fs/<disk>/reserved_blocks
Date:		June 2017
Contact:	"Chao Yu" <yuchao0@huawei.com>
Description:
		 Controls current reserved blocks in system.
+9 −4
Original line number Diff line number Diff line
@@ -1065,6 +1065,8 @@ struct f2fs_sb_info {
	block_t total_valid_block_count;	/* # of valid blocks */
	block_t discard_blks;			/* discard command candidats */
	block_t last_valid_block_count;		/* for recovery */
	block_t reserved_blocks;		/* configurable reserved blocks */

	u32 s_next_generation;			/* for NFS support */

	/* # of pages, see count_type */
@@ -1475,6 +1477,7 @@ static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
				 struct inode *inode, blkcnt_t *count)
{
	blkcnt_t diff;
	block_t avail_user_block_count;

#ifdef CONFIG_F2FS_FAULT_INJECTION
	if (time_to_inject(sbi, FAULT_BLOCK)) {
@@ -1490,10 +1493,11 @@ static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,

	spin_lock(&sbi->stat_lock);
	sbi->total_valid_block_count += (block_t)(*count);
	if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) {
		diff = sbi->total_valid_block_count - sbi->user_block_count;
	avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
	if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
		diff = sbi->total_valid_block_count - avail_user_block_count;
		*count -= diff;
		sbi->total_valid_block_count = sbi->user_block_count;
		sbi->total_valid_block_count = avail_user_block_count;
		if (!*count) {
			spin_unlock(&sbi->stat_lock);
			percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
@@ -1655,7 +1659,8 @@ static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi,
	spin_lock(&sbi->stat_lock);

	valid_block_count = sbi->total_valid_block_count + 1;
	if (unlikely(valid_block_count > sbi->user_block_count)) {
	if (unlikely(valid_block_count + sbi->reserved_blocks >
						sbi->user_block_count)) {
		spin_unlock(&sbi->stat_lock);
		return false;
	}
+3 −1
Original line number Diff line number Diff line
@@ -679,7 +679,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)

	buf->f_blocks = total_count - start_count;
	buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
	buf->f_bavail = user_block_count - valid_user_blocks(sbi);
	buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
						sbi->reserved_blocks;

	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;

@@ -1761,6 +1762,7 @@ try_onemore:
	sbi->total_valid_block_count =
				le64_to_cpu(sbi->ckpt->valid_block_count);
	sbi->last_valid_block_count = sbi->total_valid_block_count;
	sbi->reserved_blocks = 0;

	for (i = 0; i < NR_INODE_TYPE; i++) {
		INIT_LIST_HEAD(&sbi->inode_list[i]);
+15 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ enum {
	FAULT_INFO_RATE,	/* struct f2fs_fault_info */
	FAULT_INFO_TYPE,	/* struct f2fs_fault_info */
#endif
	RESERVED_BLOCKS,
};

struct f2fs_attr {
@@ -51,7 +52,7 @@ static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
		return (unsigned char *)SM_I(sbi)->dcc_info;
	else if (struct_type == NM_INFO)
		return (unsigned char *)NM_I(sbi);
	else if (struct_type == F2FS_SBI)
	else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
		return (unsigned char *)sbi;
#ifdef CONFIG_F2FS_FAULT_INJECTION
	else if (struct_type == FAULT_INFO_RATE ||
@@ -111,6 +112,17 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
	if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
		return -EINVAL;
#endif
	if (a->struct_type == RESERVED_BLOCKS) {
		spin_lock(&sbi->stat_lock);
		if ((unsigned long)sbi->total_valid_block_count + t >
				(unsigned long)sbi->user_block_count) {
			spin_unlock(&sbi->stat_lock);
			return -EINVAL;
		}
		*ui = t;
		spin_unlock(&sbi->stat_lock);
		return count;
	}
	*ui = t;
	return count;
}
@@ -165,6 +177,7 @@ F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
@@ -208,6 +221,7 @@ static struct attribute *f2fs_attrs[] = {
	ATTR_LIST(inject_type),
#endif
	ATTR_LIST(lifetime_write_kbytes),
	ATTR_LIST(reserved_blocks),
	NULL,
};