f2fs: support soft block reservation
It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space. This patch also introduces a new sysfs interface called current_reserved_blocks, which shows the current blocks that have already been reserved. Signed-off-by: Yunlong Song <yunlong.song@huawei.com> Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
bf9c142785
commit
80d4214501
4 changed files with 37 additions and 7 deletions
|
@ -138,7 +138,18 @@ What: /sys/fs/f2fs/<disk>/reserved_blocks
|
||||||
Date: June 2017
|
Date: June 2017
|
||||||
Contact: "Chao Yu" <yuchao0@huawei.com>
|
Contact: "Chao Yu" <yuchao0@huawei.com>
|
||||||
Description:
|
Description:
|
||||||
Controls current reserved blocks in system.
|
Controls target reserved blocks in system, the threshold
|
||||||
|
is soft, it could exceed current available user space.
|
||||||
|
|
||||||
|
What: /sys/fs/f2fs/<disk>/current_reserved_blocks
|
||||||
|
Date: October 2017
|
||||||
|
Contact: "Yunlong Song" <yunlong.song@huawei.com>
|
||||||
|
Contact: "Chao Yu" <yuchao0@huawei.com>
|
||||||
|
Description:
|
||||||
|
Shows current reserved blocks in system, it may be temporarily
|
||||||
|
smaller than target_reserved_blocks, but will gradually
|
||||||
|
increase to target_reserved_blocks when more free blocks are
|
||||||
|
freed by user later.
|
||||||
|
|
||||||
What: /sys/fs/f2fs/<disk>/gc_urgent
|
What: /sys/fs/f2fs/<disk>/gc_urgent
|
||||||
Date: August 2017
|
Date: August 2017
|
||||||
|
|
|
@ -1082,6 +1082,7 @@ struct f2fs_sb_info {
|
||||||
block_t discard_blks; /* discard command candidats */
|
block_t discard_blks; /* discard command candidats */
|
||||||
block_t last_valid_block_count; /* for recovery */
|
block_t last_valid_block_count; /* for recovery */
|
||||||
block_t reserved_blocks; /* configurable reserved blocks */
|
block_t reserved_blocks; /* configurable reserved blocks */
|
||||||
|
block_t current_reserved_blocks; /* current reserved blocks */
|
||||||
|
|
||||||
u32 s_next_generation; /* for NFS support */
|
u32 s_next_generation; /* for NFS support */
|
||||||
|
|
||||||
|
@ -1557,7 +1558,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
|
||||||
|
|
||||||
spin_lock(&sbi->stat_lock);
|
spin_lock(&sbi->stat_lock);
|
||||||
sbi->total_valid_block_count += (block_t)(*count);
|
sbi->total_valid_block_count += (block_t)(*count);
|
||||||
avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
|
avail_user_block_count = sbi->user_block_count -
|
||||||
|
sbi->current_reserved_blocks;
|
||||||
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
|
if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
|
||||||
diff = sbi->total_valid_block_count - avail_user_block_count;
|
diff = sbi->total_valid_block_count - avail_user_block_count;
|
||||||
*count -= diff;
|
*count -= diff;
|
||||||
|
@ -1591,6 +1593,10 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
|
||||||
f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
|
f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
|
||||||
f2fs_bug_on(sbi, inode->i_blocks < sectors);
|
f2fs_bug_on(sbi, inode->i_blocks < sectors);
|
||||||
sbi->total_valid_block_count -= (block_t)count;
|
sbi->total_valid_block_count -= (block_t)count;
|
||||||
|
if (sbi->reserved_blocks &&
|
||||||
|
sbi->current_reserved_blocks < sbi->reserved_blocks)
|
||||||
|
sbi->current_reserved_blocks = min(sbi->reserved_blocks,
|
||||||
|
sbi->current_reserved_blocks + count);
|
||||||
spin_unlock(&sbi->stat_lock);
|
spin_unlock(&sbi->stat_lock);
|
||||||
f2fs_i_blocks_write(inode, count, false, true);
|
f2fs_i_blocks_write(inode, count, false, true);
|
||||||
}
|
}
|
||||||
|
@ -1737,7 +1743,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
|
||||||
spin_lock(&sbi->stat_lock);
|
spin_lock(&sbi->stat_lock);
|
||||||
|
|
||||||
valid_block_count = sbi->total_valid_block_count + 1;
|
valid_block_count = sbi->total_valid_block_count + 1;
|
||||||
if (unlikely(valid_block_count + sbi->reserved_blocks >
|
if (unlikely(valid_block_count + sbi->current_reserved_blocks >
|
||||||
sbi->user_block_count)) {
|
sbi->user_block_count)) {
|
||||||
spin_unlock(&sbi->stat_lock);
|
spin_unlock(&sbi->stat_lock);
|
||||||
goto enospc;
|
goto enospc;
|
||||||
|
@ -1780,6 +1786,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
|
||||||
|
|
||||||
sbi->total_valid_node_count--;
|
sbi->total_valid_node_count--;
|
||||||
sbi->total_valid_block_count--;
|
sbi->total_valid_block_count--;
|
||||||
|
if (sbi->reserved_blocks &&
|
||||||
|
sbi->current_reserved_blocks < sbi->reserved_blocks)
|
||||||
|
sbi->current_reserved_blocks++;
|
||||||
|
|
||||||
spin_unlock(&sbi->stat_lock);
|
spin_unlock(&sbi->stat_lock);
|
||||||
|
|
||||||
|
|
|
@ -987,7 +987,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
|
||||||
buf->f_blocks = total_count - start_count;
|
buf->f_blocks = total_count - start_count;
|
||||||
buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_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;
|
sbi->current_reserved_blocks;
|
||||||
|
|
||||||
avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
|
avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
|
||||||
|
|
||||||
|
@ -2458,6 +2458,7 @@ try_onemore:
|
||||||
le64_to_cpu(sbi->ckpt->valid_block_count);
|
le64_to_cpu(sbi->ckpt->valid_block_count);
|
||||||
sbi->last_valid_block_count = sbi->total_valid_block_count;
|
sbi->last_valid_block_count = sbi->total_valid_block_count;
|
||||||
sbi->reserved_blocks = 0;
|
sbi->reserved_blocks = 0;
|
||||||
|
sbi->current_reserved_blocks = 0;
|
||||||
|
|
||||||
for (i = 0; i < NR_INODE_TYPE; i++) {
|
for (i = 0; i < NR_INODE_TYPE; i++) {
|
||||||
INIT_LIST_HEAD(&sbi->inode_list[i]);
|
INIT_LIST_HEAD(&sbi->inode_list[i]);
|
||||||
|
|
|
@ -30,7 +30,7 @@ enum {
|
||||||
FAULT_INFO_RATE, /* struct f2fs_fault_info */
|
FAULT_INFO_RATE, /* struct f2fs_fault_info */
|
||||||
FAULT_INFO_TYPE, /* struct f2fs_fault_info */
|
FAULT_INFO_TYPE, /* struct f2fs_fault_info */
|
||||||
#endif
|
#endif
|
||||||
RESERVED_BLOCKS,
|
RESERVED_BLOCKS, /* struct f2fs_sb_info */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct f2fs_attr {
|
struct f2fs_attr {
|
||||||
|
@ -114,6 +114,12 @@ static ssize_t features_show(struct f2fs_attr *a,
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ssize_t current_reserved_blocks_show(struct f2fs_attr *a,
|
||||||
|
struct f2fs_sb_info *sbi, char *buf)
|
||||||
|
{
|
||||||
|
return snprintf(buf, PAGE_SIZE, "%u\n", sbi->current_reserved_blocks);
|
||||||
|
}
|
||||||
|
|
||||||
static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
|
static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
|
||||||
struct f2fs_sb_info *sbi, char *buf)
|
struct f2fs_sb_info *sbi, char *buf)
|
||||||
{
|
{
|
||||||
|
@ -153,12 +159,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
|
||||||
#endif
|
#endif
|
||||||
if (a->struct_type == RESERVED_BLOCKS) {
|
if (a->struct_type == RESERVED_BLOCKS) {
|
||||||
spin_lock(&sbi->stat_lock);
|
spin_lock(&sbi->stat_lock);
|
||||||
if ((unsigned long)sbi->total_valid_block_count + t >
|
if (t > (unsigned long)sbi->user_block_count) {
|
||||||
(unsigned long)sbi->user_block_count) {
|
|
||||||
spin_unlock(&sbi->stat_lock);
|
spin_unlock(&sbi->stat_lock);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
*ui = t;
|
*ui = t;
|
||||||
|
sbi->current_reserved_blocks = min(sbi->reserved_blocks,
|
||||||
|
sbi->user_block_count - valid_user_blocks(sbi));
|
||||||
spin_unlock(&sbi->stat_lock);
|
spin_unlock(&sbi->stat_lock);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
@ -293,6 +300,7 @@ F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
|
||||||
F2FS_GENERAL_RO_ATTR(dirty_segments);
|
F2FS_GENERAL_RO_ATTR(dirty_segments);
|
||||||
F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
|
F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
|
||||||
F2FS_GENERAL_RO_ATTR(features);
|
F2FS_GENERAL_RO_ATTR(features);
|
||||||
|
F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
|
||||||
|
|
||||||
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
||||||
F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
|
F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
|
||||||
|
@ -338,6 +346,7 @@ static struct attribute *f2fs_attrs[] = {
|
||||||
ATTR_LIST(lifetime_write_kbytes),
|
ATTR_LIST(lifetime_write_kbytes),
|
||||||
ATTR_LIST(features),
|
ATTR_LIST(features),
|
||||||
ATTR_LIST(reserved_blocks),
|
ATTR_LIST(reserved_blocks),
|
||||||
|
ATTR_LIST(current_reserved_blocks),
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue