Skip to contentSkip to conversation

f2fs: support soft block reservation

PATCH RESEND In review Chao Yu 3 participants 6 messages Oct 26, 2017 – Oct 27, 2017 F2FS file system

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH RESEND 1/1 f2fs: support soft block reservation

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

---
 Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
 fs/f2fs/f2fs.h                          | 13 +++++++++++--
 fs/f2fs/super.c                         |  3 ++-
 fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
 Date:		June 2017
 Contact:	"Chao Yu" <[email protected]>
 Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
 What:		/sys/fs/f2fs/<disk>/gc_urgent
 Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
 	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);
 	f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
 	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +14 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
 	return len;
 }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 			struct f2fs_sb_info *sbi, char *buf)
 {
 	unsigned char *ptr = NULL;
 	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
 	ptr = __struct_ptr(sbi, a->struct_type);
 	if (!ptr)
 		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
 			spin_unlock(&sbi->stat_lock);
 			return -EINVAL;
 		}
 		*ui = t;
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
+				sbi->user_block_count - valid_user_blocks(sbi));
 		spin_unlock(&sbi->stat_lock);
 		return count;
 	}
Signature · 6 lines
2.13.1.388.g69e6b9b4f4a9


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer
#1 lore raw
Quoted 5 lines · Chao Yu

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

So, how can we change sbi->reserved_blocks?
Could you please summarize how reserved_blocks and current_reserved_blocks are different?

What does current_reserved_blocks mean? Isn't "reserved_blocks" current? We have to make sysfs entry show just one value without any string.

Thanks,

Quoted 143 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
 fs/f2fs/f2fs.h                          | 13 +++++++++++--
 fs/f2fs/super.c                         |  3 ++-
 fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
 Date:		June 2017
 Contact:	"Chao Yu" <[email protected]>
 Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
 What:		/sys/fs/f2fs/<disk>/gc_urgent
 Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
 	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);
 	f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
 	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +14 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
 	return len;
 }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 			struct f2fs_sb_info *sbi, char *buf)
 {
 	unsigned char *ptr = NULL;
 	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
 	ptr = __struct_ptr(sbi, a->struct_type);
 	if (!ptr)
 		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
 			spin_unlock(&sbi->stat_lock);
 			return -EINVAL;
 		}
 		*ui = t;
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
+				sbi->user_block_count - valid_user_blocks(sbi));
 		spin_unlock(&sbi->stat_lock);
 		return count;
 	}
Signature · 1 line
2.13.1.388.g69e6b9b4f4a9

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

author
#2 lore raw
Quoted 10 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

So, how can we change sbi->reserved_blocks?
Could you please summarize how reserved_blocks and current_reserved_blocks are different?

Okay, let me explain this:

Previously, we just support hard reservation of blocks, it means if system has 200MB free blocks, we only can reserve <= 200MB free blocks through sysfs, otherwise, reserving will fail.

In this patch, we begin to support soft one, it can reserve blocks exceeding free blocks, which means, if system has 200MB free blocks, we can reserve > 200MB free blocks.

Quoted 2 lines

What does current_reserved_blocks mean? Isn't "reserved_blocks" current?

So, reserved_blocks means the target block number we want to reserve, and current_reserved_blocks is current block number we have reserved. Meanwhile blocks are freed by user, we will reserve more free blocks until current_reserved_blocks touching the target reserved_blocks.

Quoted 1 line

We have to make sysfs entry show just one value without any string.

For better analysis? So we need another sysfs entry for current_reserved_blocks if we can support this feature?

Thanks,

Quoted 140 lines

Thanks,

Quoted 137 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
 fs/f2fs/f2fs.h                          | 13 +++++++++++--
 fs/f2fs/super.c                         |  3 ++-
 fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
 Date:		June 2017
 Contact:	"Chao Yu" <[email protected]>
 Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
 What:		/sys/fs/f2fs/<disk>/gc_urgent
 Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
 	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);
 	f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
 	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +13 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
 	return len;
 }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 			struct f2fs_sb_info *sbi, char *buf)
 {
 	unsigned char *ptr = NULL;
 	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
 	ptr = __struct_ptr(sbi, a->struct_type);
 	if (!ptr)
 		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
 			spin_unlock(&sbi->stat_lock);
 			return -EINVAL;
 		}
 		*ui = t;
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
Quoted 9 lines
Quoted 6 lines
fs/f2fs/sysfs.c +1 -0
+				sbi->user_block_count - valid_user_blocks(sbi));
 		spin_unlock(&sbi->stat_lock);
 		return count;
 	}
Signature · 1 line
2.13.1.388.g69e6b9b4f4a9

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot

#3 lore raw

Besides, it is useful for kernel update. For example, android want to set reserved_blocks as 200M in its kernel. And when this kernel update pushes to the users, if the user now has only 100M free space, then there will be mistake using reserved_blocks. In this case, we can use cur_reserved_blocks and set its value to 100M, and increase its value to the target 200M gradually when users delete files. This is what "soft" means.

If sysfs entry should be entry without any string, we can add cur_reserved_blocks as an entry like my v2 patch version.

Quoted 181 lines · Chao Yu
Quoted 9 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

So, how can we change sbi->reserved_blocks?
Could you please summarize how reserved_blocks and current_reserved_blocks are different?

Okay, let me explain this:

Previously, we just support hard reservation of blocks, it means if system has 200MB free blocks, we only can reserve <= 200MB free blocks through sysfs, otherwise, reserving will fail.

In this patch, we begin to support soft one, it can reserve blocks exceeding free blocks, which means, if system has 200MB free blocks, we can reserve > 200MB free blocks.

Quoted 1 line

What does current_reserved_blocks mean? Isn't "reserved_blocks" current?

So, reserved_blocks means the target block number we want to reserve, and current_reserved_blocks is current block number we have reserved. Meanwhile blocks are freed by user, we will reserve more free blocks until current_reserved_blocks touching the target reserved_blocks.

Quoted 1 line

We have to make sysfs entry show just one value without any string.

For better analysis? So we need another sysfs entry for current_reserved_blocks if we can support this feature?

Thanks,

Quoted 137 lines

Thanks,

Quoted 135 lines
---
  Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
  fs/f2fs/f2fs.h                          | 13 +++++++++++--
  fs/f2fs/super.c                         |  3 ++-
  fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
  4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
  Date:		June 2017
  Contact:	"Chao Yu" <[email protected]>
  Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
  What:		/sys/fs/f2fs/<disk>/gc_urgent
  Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
  	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);
  	f2fs_i_blocks_write(inode, count, false, true);
  }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
  	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +12 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
  	return len;
  }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
  static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
  			struct f2fs_sb_info *sbi, char *buf)
  {
  	unsigned char *ptr = NULL;
  	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
  	ptr = __struct_ptr(sbi, a->struct_type);
  	if (!ptr)
  		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
  #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
  			spin_unlock(&sbi->stat_lock);
  			return -EINVAL;
  		}
  		*ui = t;
Quoted 9 lines
Quoted 7 lines
fs/f2fs/sysfs.c +2 -0
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
+				sbi->user_block_count - valid_user_blocks(sbi));
  		spin_unlock(&sbi->stat_lock);
  		return count;
  	}
Signature · 1 line
2.13.1.388.g69e6b9b4f4a9

.

.

Signature · 2 lines
Thanks,
Yunlong Song
maintainer
#4 lore raw
In reply to Chao Yu
Quoted 22 lines · Chao Yu
Quoted 10 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

So, how can we change sbi->reserved_blocks?
Could you please summarize how reserved_blocks and current_reserved_blocks are different?

Okay, let me explain this:

Previously, we just support hard reservation of blocks, it means if system has 200MB free blocks, we only can reserve <= 200MB free blocks through sysfs, otherwise, reserving will fail.

In this patch, we begin to support soft one, it can reserve blocks exceeding free blocks, which means, if system has 200MB free blocks, we can reserve > 200MB free blocks.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

What does current_reserved_blocks mean? Isn't "reserved_blocks" current?

So, reserved_blocks means the target block number we want to reserve, and current_reserved_blocks is current block number we have reserved. Meanwhile blocks are freed by user, we will reserve more free blocks until current_reserved_blocks touching the target reserved_blocks.

So, what about target_reserved_blocks and current_reserved_blocks? Then, after user deletes some files, can we update current_reserved_blocks automatically? We're able to update it in dev_valid_blocks(), as I guess.

Please update the description in the patch, and use two sysfs entries to change each of values.

Thanks,

Quoted 157 lines
Quoted 2 lines

We have to make sysfs entry show just one value without any string.

For better analysis? So we need another sysfs entry for current_reserved_blocks if we can support this feature?

Thanks,

Quoted 149 lines

Thanks,

Quoted 143 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
 fs/f2fs/f2fs.h                          | 13 +++++++++++--
 fs/f2fs/super.c                         |  3 ++-
 fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
 Date:		June 2017
 Contact:	"Chao Yu" <[email protected]>
 Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
 What:		/sys/fs/f2fs/<disk>/gc_urgent
 Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
 	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);
 	f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
 	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +14 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
 	return len;
 }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 			struct f2fs_sb_info *sbi, char *buf)
 {
 	unsigned char *ptr = NULL;
 	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
 	ptr = __struct_ptr(sbi, a->struct_type);
 	if (!ptr)
 		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
 			spin_unlock(&sbi->stat_lock);
 			return -EINVAL;
 		}
 		*ui = t;
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
+				sbi->user_block_count - valid_user_blocks(sbi));
 		spin_unlock(&sbi->stat_lock);
 		return count;
 	}
Signature · 1 line
2.13.1.388.g69e6b9b4f4a9

.

author
#5 lore raw
Quoted 23 lines · Jaegeuk Kim
Quoted 22 lines · Chao Yu
Quoted 10 lines · Jaegeuk Kim
Quoted 5 lines · Chao Yu

From: Yunlong Song <[email protected]>

It supports to extend reserved_blocks sysfs interface to be soft threshold, which allows user configure it exceeding current available user space.

So, how can we change sbi->reserved_blocks?
Could you please summarize how reserved_blocks and current_reserved_blocks are different?

Okay, let me explain this:

Previously, we just support hard reservation of blocks, it means if system has 200MB free blocks, we only can reserve <= 200MB free blocks through sysfs, otherwise, reserving will fail.

In this patch, we begin to support soft one, it can reserve blocks exceeding free blocks, which means, if system has 200MB free blocks, we can reserve > 200MB free blocks.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

What does current_reserved_blocks mean? Isn't "reserved_blocks" current?

So, reserved_blocks means the target block number we want to reserve, and current_reserved_blocks is current block number we have reserved. Meanwhile blocks are freed by user, we will reserve more free blocks until current_reserved_blocks touching the target reserved_blocks.

So, what about target_reserved_blocks and current_reserved_blocks? Then, after

Better. :)

Quoted 2 lines

user deletes some files, can we update current_reserved_blocks automatically? We're able to update it in dev_valid_blocks(), as I guess.

Yup.

Quoted 3 lines

Please update the description in the patch, and use two sysfs entries to change each of values.

OK, let me update this patch.

Thanks,

Quoted 161 lines

Thanks,

Quoted 157 lines
Quoted 2 lines

We have to make sysfs entry show just one value without any string.

For better analysis? So we need another sysfs entry for current_reserved_blocks if we can support this feature?

Thanks,

Quoted 149 lines

Thanks,

Quoted 143 lines
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  3 ++-
 fs/f2fs/f2fs.h                          | 13 +++++++++++--
 fs/f2fs/super.c                         |  3 ++-
 fs/f2fs/sysfs.c                         | 16 ++++++++++++++--
 4 files changed, 29 insertions(+), 6 deletions(-)
Documentation/ABI/testing/sysfs-fs-f2fs +2 -1
index 11b7f4ebea7c..ba282ca5eb15 100644
@@ -138,7 +138,8 @@ What:		/sys/fs/f2fs/<disk>/reserved_blocks
 Date:		June 2017
 Contact:	"Chao Yu" <[email protected]>
 Description:
-		 Controls current reserved blocks in system.
+		 Controls current reserved blocks in system, the threshold
+		 is soft, it could exceed current available user space.
 
 What:		/sys/fs/f2fs/<disk>/gc_urgent
 Date:		August 2017
fs/f2fs/f2fs.h +11 -2
index 6d2984abc50f..6680da47fb1a 100644
@@ -1094,6 +1094,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 */
 
@@ -1575,7 +1576,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;
@@ -1609,6 +1611,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, inode->i_blocks < sectors);
 	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);
 	f2fs_i_blocks_write(inode, count, false, true);
 }
@@ -1755,7 +1761,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;
@@ -1798,6 +1804,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 < sbi->reserved_blocks)
+		sbi->current_reserved_blocks++;
 
 	spin_unlock(&sbi->stat_lock);
 
fs/f2fs/super.c +2 -1
index 3fd62ee53eb7..3fd846ac7268 100644
@@ -983,7 +983,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;
 
@@ -2450,6 +2450,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[i]);
fs/f2fs/sysfs.c +14 -2
index 751964da2bca..87487ca8f62e 100644
@@ -107,12 +107,23 @@ static ssize_t features_show(struct f2fs_attr *a,
 	return len;
 }
 
+static ssize_t f2fs_reserved_blocks_show(struct f2fs_attr *a,
+					struct f2fs_sb_info *sbi, char *buf)
+{
+	return snprintf(buf, PAGE_SIZE,
+			"expected:	%u\ncurrent:	%u\n",
+			sbi->reserved_blocks, sbi->current_reserved_blocks);
+}
+
 static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
 			struct f2fs_sb_info *sbi, char *buf)
 {
 	unsigned char *ptr = NULL;
 	unsigned int *ui;
 
+	if (a->struct_type == RESERVED_BLOCKS)
+		return f2fs_reserved_blocks_show(a, sbi, buf);
+
 	ptr = __struct_ptr(sbi, a->struct_type);
 	if (!ptr)
 		return -EINVAL;
@@ -146,12 +157,13 @@ static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
 #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) {
+		if (t > (unsigned long)sbi->user_block_count) {
 			spin_unlock(&sbi->stat_lock);
 			return -EINVAL;
 		}
 		*ui = t;
+		sbi->current_reserved_blocks = min(sbi->reserved_blocks,
+				sbi->user_block_count - valid_user_blocks(sbi));
 		spin_unlock(&sbi->stat_lock);
 		return count;
 	}
Signature · 1 line
2.13.1.388.g69e6b9b4f4a9

.

Quoted 2 lines

.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot