Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
Hi, Chao, ping... Please see the review comment below. And the change is already in the v3 patch. On 2017/8/18 23:16, Yunlong Song wrote: I send a v3 patch, please review, and the main difference is shown below. On 2017/8/18 18:20, Chao Yu wrote: Hi Yunlong, IMO, we don't need additional sysfs entry, how about changing a bit as below? >From 3fc8206871fe457859f1537c9dc8918b45f14601 Mon Sep 17 00:00:00 2001 From: Yunlong Song Date: Wed, 16 Aug 2017 23:01:56 +0800 Subject: [PATCH] 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. Signed-off-by: Yunlong Song Signed-off-by: Chao Yu --- Documentation/ABI/testing/sysfs-fs-f2fs | 3 ++- fs/f2fs/f2fs.h | 12 ++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 16 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4ebea7c..45c3d92f77c8 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -138,7 +138,8 @@ What: /sys/fs/f2fs//reserved_blocks Date:June 2017 Contact:"Chao Yu" Description: - Controls current reserved blocks in system. + Controls current reserved blocks in system, the threshold + is soft, it could exceed current avaible user space. What:/sys/fs/f2fs//gc_urgent Date:August 2017 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 336021b9b93e..a7b2d257e8ee 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1046,6 +1046,7 @@ struct f2fs_sb_info { block_t discard_blks;/* discard command candidats */ block_t last_valid_block_count;/* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ +block_t current_reserved_blocks;/* current reserved blocks */ u32 s_next_generation;/* for NFS support */ @@ -1520,7 +1521,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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)) { diff = sbi->total_valid_block_count - avail_user_block_count; *count -= diff; @@ -1554,6 +1556,9 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; +if (sbi->reserved_blocks) Add sbi->reserved_blocks != sbi->cur_reserved_blocks check +sbi->current_reserved_blocks = min(sbi->reserved_blocks, +sbi->current_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1700,7 +1705,7 @@ static inline int 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->reserved_blocks > +if (unlikely(valid_block_count + sbi->current_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1743,6 +1748,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; +if (sbi->reserved_blocks) +sbi->current_reserved_blocks = min(sbi->reserved_blocks, +sbi->current_reserved_blocks + 1); change to sbi->cur_reserved_blocks++; spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb94133..036f083bbf56 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - -sbi->reserved_blocks; +sbi->current_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->reserved_blocks = 0; +sbi->current_reserved_blocks = 0; for (i = 0; i < NR_INODE_TYPE; i++) {
Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
I send a v3 patch, please review, and the main difference is shown below. On 2017/8/18 18:20, Chao Yu wrote: Hi Yunlong, IMO, we don't need additional sysfs entry, how about changing a bit as below? >From 3fc8206871fe457859f1537c9dc8918b45f14601 Mon Sep 17 00:00:00 2001 From: Yunlong Song Date: Wed, 16 Aug 2017 23:01:56 +0800 Subject: [PATCH] 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. Signed-off-by: Yunlong Song Signed-off-by: Chao Yu --- Documentation/ABI/testing/sysfs-fs-f2fs | 3 ++- fs/f2fs/f2fs.h | 12 ++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 16 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4ebea7c..45c3d92f77c8 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -138,7 +138,8 @@ What: /sys/fs/f2fs//reserved_blocks Date: June 2017 Contact: "Chao Yu" Description: -Controls current reserved blocks in system. +Controls current reserved blocks in system, the threshold +is soft, it could exceed current avaible user space. What: /sys/fs/f2fs//gc_urgent Date: August 2017 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 336021b9b93e..a7b2d257e8ee 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1046,6 +1046,7 @@ struct f2fs_sb_info { block_t discard_blks; /* discard command candidats */ block_t last_valid_block_count; /* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ + block_t current_reserved_blocks;/* current reserved blocks */ u32 s_next_generation; /* for NFS support */ @@ -1520,7 +1521,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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)) { diff = sbi->total_valid_block_count - avail_user_block_count; *count -= diff; @@ -1554,6 +1556,9 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; + if (sbi->reserved_blocks) Add sbi->reserved_blocks != sbi->cur_reserved_blocks check + sbi->current_reserved_blocks = min(sbi->reserved_blocks, + sbi->current_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1700,7 +1705,7 @@ static inline int 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->reserved_blocks > + if (unlikely(valid_block_count + sbi->current_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1743,6 +1748,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; + if (sbi->reserved_blocks) + sbi->current_reserved_blocks = min(sbi->reserved_blocks, + sbi->current_reserved_blocks + 1); change to sbi->cur_reserved_blocks++; spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb94133..036f083bbf56 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - - sbi->reserved_blocks; + sbi->current_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_
Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
Hi Yunlong, IMO, we don't need additional sysfs entry, how about changing a bit as below? >From 3fc8206871fe457859f1537c9dc8918b45f14601 Mon Sep 17 00:00:00 2001 From: Yunlong Song Date: Wed, 16 Aug 2017 23:01:56 +0800 Subject: [PATCH] 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. Signed-off-by: Yunlong Song Signed-off-by: Chao Yu --- Documentation/ABI/testing/sysfs-fs-f2fs | 3 ++- fs/f2fs/f2fs.h | 12 ++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 16 ++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4ebea7c..45c3d92f77c8 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -138,7 +138,8 @@ What: /sys/fs/f2fs//reserved_blocks Date: June 2017 Contact: "Chao Yu" Description: -Controls current reserved blocks in system. +Controls current reserved blocks in system, the threshold +is soft, it could exceed current avaible user space. What: /sys/fs/f2fs//gc_urgent Date: August 2017 diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 336021b9b93e..a7b2d257e8ee 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1046,6 +1046,7 @@ struct f2fs_sb_info { block_t discard_blks; /* discard command candidats */ block_t last_valid_block_count; /* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ + block_t current_reserved_blocks;/* current reserved blocks */ u32 s_next_generation; /* for NFS support */ @@ -1520,7 +1521,8 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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)) { diff = sbi->total_valid_block_count - avail_user_block_count; *count -= diff; @@ -1554,6 +1556,9 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; + if (sbi->reserved_blocks) + sbi->current_reserved_blocks = min(sbi->reserved_blocks, + sbi->current_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1700,7 +1705,7 @@ static inline int 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->reserved_blocks > + if (unlikely(valid_block_count + sbi->current_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1743,6 +1748,9 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; + if (sbi->reserved_blocks) + sbi->current_reserved_blocks = min(sbi->reserved_blocks, + sbi->current_reserved_blocks + 1); spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb94133..036f083bbf56 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - - sbi->reserved_blocks; + sbi->current_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->reserved_blocks = 0; + sbi->current_reserved_blocks = 0; for (i = 0; i < NR_INODE_TYPE; i++) { INIT_LIST_HEAD(&sbi->inode_list
Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
ping... On 2017/8/15 12:08, Yunlong Song wrote: ping... On 2017/8/11 19:43, Yunlong Song wrote: In this patch, we add a new sysfs interface, we can use it to gradually achieve the reserved_blocks finally, even when reserved_blocks is initially set over user_block_count - total_valid_block_count. This is very useful, especially when we upgrade kernel with new reserved_blocks value, but old disk image unluckily has user_block_count - total_valid_block_count smaller than the desired reserved_blocks. With this patch, f2fs can try its best to reserve space and get close to the reserved_blocks, and the current value of achieved reserved_blocks can be shown in real time. To ensure there is enough space for supporting system's activation, we safely increase cur_reserved_blocks in dev_valid_block(,node)_count to only take up the blocks which are just obsoleted. Signed-off-by: Yunlong Song --- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++ fs/f2fs/f2fs.h | 9 +++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 15 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4e..bdbb9f3 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -151,3 +151,9 @@ Date:August 2017 Contact:"Jaegeuk Kim" Description: Controls sleep time of GC urgent mode + +What:/sys/fs/f2fs//cur_reserved_blocks +Date:August 2017 +Contact:"Yunlong Song" +Description: + Shows current reserved blocks in system. diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2f20b6b..62d7343 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1041,6 +1041,7 @@ struct f2fs_sb_info { block_t discard_blks;/* discard command candidats */ block_t last_valid_block_count;/* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ +block_t cur_reserved_blocks;/* current reserved blocks */ u32 s_next_generation;/* for NFS support */ @@ -1515,7 +1516,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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->cur_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; @@ -1549,6 +1550,8 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; +sbi->cur_reserved_blocks = min(sbi->reserved_blocks, +sbi->cur_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1695,7 +1698,7 @@ static inline int 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->reserved_blocks > +if (unlikely(valid_block_count + sbi->cur_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1738,6 +1741,8 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; +sbi->cur_reserved_blocks = min(sbi->reserved_blocks, +sbi->cur_reserved_blocks + 1); spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb..16a805f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - -sbi->reserved_blocks; +sbi->cur_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->reserved_blocks = 0; +sbi->cur_reserved_blocks = 0; for (i = 0; i < NR_INODE_TYPE; i++) { INIT_LIST_HEAD(&sbi->inode_list[i]); diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index a1be
Re: [PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
ping... On 2017/8/11 19:43, Yunlong Song wrote: In this patch, we add a new sysfs interface, we can use it to gradually achieve the reserved_blocks finally, even when reserved_blocks is initially set over user_block_count - total_valid_block_count. This is very useful, especially when we upgrade kernel with new reserved_blocks value, but old disk image unluckily has user_block_count - total_valid_block_count smaller than the desired reserved_blocks. With this patch, f2fs can try its best to reserve space and get close to the reserved_blocks, and the current value of achieved reserved_blocks can be shown in real time. To ensure there is enough space for supporting system's activation, we safely increase cur_reserved_blocks in dev_valid_block(,node)_count to only take up the blocks which are just obsoleted. Signed-off-by: Yunlong Song --- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++ fs/f2fs/f2fs.h | 9 +++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 15 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4e..bdbb9f3 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -151,3 +151,9 @@ Date: August 2017 Contact: "Jaegeuk Kim" Description: Controls sleep time of GC urgent mode + +What: /sys/fs/f2fs//cur_reserved_blocks +Date: August 2017 +Contact: "Yunlong Song" +Description: +Shows current reserved blocks in system. diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2f20b6b..62d7343 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1041,6 +1041,7 @@ struct f2fs_sb_info { block_t discard_blks; /* discard command candidats */ block_t last_valid_block_count; /* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ + block_t cur_reserved_blocks;/* current reserved blocks */ u32 s_next_generation; /* for NFS support */ @@ -1515,7 +1516,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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->cur_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; @@ -1549,6 +1550,8 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; + sbi->cur_reserved_blocks = min(sbi->reserved_blocks, + sbi->cur_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1695,7 +1698,7 @@ static inline int 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->reserved_blocks > + if (unlikely(valid_block_count + sbi->cur_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1738,6 +1741,8 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; + sbi->cur_reserved_blocks = min(sbi->reserved_blocks, + sbi->cur_reserved_blocks + 1); spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb..16a805f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - - sbi->reserved_blocks; + sbi->cur_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count;
[PATCH v2] f2fs: introduce cur_reserved_blocks in sysfs
In this patch, we add a new sysfs interface, we can use it to gradually achieve the reserved_blocks finally, even when reserved_blocks is initially set over user_block_count - total_valid_block_count. This is very useful, especially when we upgrade kernel with new reserved_blocks value, but old disk image unluckily has user_block_count - total_valid_block_count smaller than the desired reserved_blocks. With this patch, f2fs can try its best to reserve space and get close to the reserved_blocks, and the current value of achieved reserved_blocks can be shown in real time. To ensure there is enough space for supporting system's activation, we safely increase cur_reserved_blocks in dev_valid_block(,node)_count to only take up the blocks which are just obsoleted. Signed-off-by: Yunlong Song --- Documentation/ABI/testing/sysfs-fs-f2fs | 6 ++ fs/f2fs/f2fs.h | 9 +++-- fs/f2fs/super.c | 3 ++- fs/f2fs/sysfs.c | 15 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 11b7f4e..bdbb9f3 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -151,3 +151,9 @@ Date: August 2017 Contact: "Jaegeuk Kim" Description: Controls sleep time of GC urgent mode + +What: /sys/fs/f2fs//cur_reserved_blocks +Date: August 2017 +Contact: "Yunlong Song" +Description: +Shows current reserved blocks in system. diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2f20b6b..62d7343 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1041,6 +1041,7 @@ struct f2fs_sb_info { block_t discard_blks; /* discard command candidats */ block_t last_valid_block_count; /* for recovery */ block_t reserved_blocks;/* configurable reserved blocks */ + block_t cur_reserved_blocks;/* current reserved blocks */ u32 s_next_generation; /* for NFS support */ @@ -1515,7 +1516,7 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, spin_lock(&sbi->stat_lock); 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->cur_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; @@ -1549,6 +1550,8 @@ 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, inode->i_blocks < sectors); sbi->total_valid_block_count -= (block_t)count; + sbi->cur_reserved_blocks = min(sbi->reserved_blocks, + sbi->cur_reserved_blocks + count); spin_unlock(&sbi->stat_lock); f2fs_i_blocks_write(inode, count, false, true); } @@ -1695,7 +1698,7 @@ static inline int 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->reserved_blocks > + if (unlikely(valid_block_count + sbi->cur_reserved_blocks > sbi->user_block_count)) { spin_unlock(&sbi->stat_lock); goto enospc; @@ -1738,6 +1741,8 @@ static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, sbi->total_valid_node_count--; sbi->total_valid_block_count--; + sbi->cur_reserved_blocks = min(sbi->reserved_blocks, + sbi->cur_reserved_blocks + 1); spin_unlock(&sbi->stat_lock); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4c1bdcb..16a805f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -957,7 +957,7 @@ 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) - - sbi->reserved_blocks; + sbi->cur_reserved_blocks; avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; @@ -2411,6 +2411,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) le64_to_cpu(sbi->ckpt->valid_block_count); sbi->last_valid_block_count = sbi->total_valid_block_count; sbi->reserved_blocks