Skip to contentSkip to conversation

f2fs: fix wrong bfree and bavail

PATCH In review Jaegeuk Kim 3 participants 6 messages Sep 5, 2017 – Sep 6, 2017

Subsystems (3)
lore
Share & tools
lore

Jaegeuk Kim

author maintainer
#0 lore raw

PATCH 1/1 f2fs: fix wrong bfree and bavail

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +2 -2
index 7e29db227910..17cca4cb93af 100644
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
 						sbi->reserved_blocks;
 
 	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
Signature · 1 line
2.14.0.rc1.383.gd1ce394fe2-goog
#1 lore raw
Quoted 21 lines · Jaegeuk Kim

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
fs/f2fs/super.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 7e29db227910..17cca4cb93af 100644

fs/f2fs/super.c static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 960

Quoted 8 lines
fs/f2fs/super.c +2 -2
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
 						sbi->reserved_blocks;

To keep the statfs data more consistent, you could use:

	buf->f_bavail = buf->f_bfree - ovp_count - sbi->reserved_blocks;

That avoids the extra subtraction, and avoids (minor) issues if these values change while this syscall is running.

Cheers, Andreas

author maintainer
#2 lore raw
Quoted 33 lines · Andreas Dilger
Quoted 21 lines · Jaegeuk Kim

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
fs/f2fs/super.c | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 7e29db227910..17cca4cb93af 100644

fs/f2fs/super.c static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 960

Quoted 8 lines
fs/f2fs/super.c +2 -2
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
 						sbi->reserved_blocks;

To keep the statfs data more consistent, you could use:

Quoted 4 lines
	buf->f_bavail = buf->f_bfree - ovp_count - sbi->reserved_blocks;

That avoids the extra subtraction, and avoids (minor) issues if these values change while this syscall is running.

Much better. Thank you so much for correcting me.

Quoted 7 lines

Cheers, Andreas

#3 lore raw
In reply to Jaegeuk Kim
Quoted 20 lines · Jaegeuk Kim

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 7e29db227910..17cca4cb93af 100644

fs/f2fs/super.c static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 959

Quoted 7 lines
fs/f2fs/super.c +2 -2
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
			get_cp(overprov_segment_count)) * c.blks_per_seg));

As we calculated in mkfs, we have removed ovp_count in user_block_count, so shouldn't we add ovp_count for f_bfree here?

Thanks,

Quoted 4 lines
fs/f2fs/super.c +0 -0
 						sbi->reserved_blocks;
 
 	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
author maintainer
#4 lore raw
Quoted 32 lines · Chao Yu
Quoted 20 lines · Jaegeuk Kim

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 7e29db227910..17cca4cb93af 100644

fs/f2fs/super.c static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 959

Quoted 7 lines
fs/f2fs/super.c +2 -2
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
			get_cp(overprov_segment_count)) * c.blks_per_seg));
Quoted 2 lines

As we calculated in mkfs, we have removed ovp_count in user_block_count, so shouldn't we add ovp_count for f_bfree here?

Hehe, I already dropped this. :P
It seems like something wrong with df in android.

Quoted 7 lines

Thanks,

Quoted 4 lines
fs/f2fs/super.c +0 -0
 						sbi->reserved_blocks;
 
 	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
#5 lore raw
Quoted 33 lines · Jaegeuk Kim
Quoted 32 lines · Chao Yu
Quoted 20 lines · Jaegeuk Kim

This patch fixes bavail and bfree finally.

long    f_bfree;    /* free blocks in fs */
long    f_bavail;   /* free blocks avail to non-superuser */

So, bfree represents all the reserved blocks, while bavail does the space only visible to normal user.

Fix: 3e6d0b4d9c1c ("f2fs: fix incorrect f_bfree calculation in ->statfs")

---
 fs/f2fs/super.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/f2fs/super.c +0 -0
index 7e29db227910..17cca4cb93af 100644

fs/f2fs/super.c static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 959

Quoted 7 lines
fs/f2fs/super.c +2 -2
@@ -955,8 +955,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 	buf->f_bsize = sbi->blocksize;
 
 	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_bfree = user_block_count - valid_user_blocks(sbi);
+	buf->f_bavail = user_block_count - valid_user_blocks(sbi) - ovp_count -
	set_cp(user_block_count, ((get_cp(free_segment_count) + 6 -
			get_cp(overprov_segment_count)) * c.blks_per_seg));
Quoted 4 lines
Quoted 2 lines

As we calculated in mkfs, we have removed ovp_count in user_block_count, so shouldn't we add ovp_count for f_bfree here?

Hehe, I already dropped this. :P

Alright. :)

Quoted 1 line

It seems like something wrong with df in android.

Maybe its version is too old?

Thanks,

Quoted 11 lines
Quoted 8 lines

Thanks,

Quoted 4 lines
fs/f2fs/super.c +0 -0
 						sbi->reserved_blocks;
 
 	avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;

.