f2fs: fix wrong bfree and bavail
Subsystems (3)
Jaegeuk Kim
maintainerPATCH 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
@@ -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
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 incorrectf_bfreecalculation in ->statfs")Cc <[email protected]> # 4.8+Signed-off-by Jaegeuk Kim <[email protected]>---
fs/f2fs/super.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0
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
Jaegeuk Kim
maintainerQuoted 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 incorrectf_bfreecalculation in ->statfs")Cc <[email protected]> # 4.8+Signed-off-by Jaegeuk Kim <[email protected]>---
fs/f2fs/super.c| 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0fs/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
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 incorrectf_bfreecalculation in ->statfs")Cc <[email protected]> # 4.8+Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0
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
-0sbi->reserved_blocks; avail_node_count = sbi->total_node_count -F2FS_RESERVED_NODE_NUM ;
Jaegeuk Kim
maintainerQuoted 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 incorrectf_bfreecalculation in ->statfs")Cc <[email protected]> # 4.8+Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0fs/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_countinuser_block_count, so shouldn't we addovp_countforf_bfreehere?
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
-0sbi->reserved_blocks; avail_node_count = sbi->total_node_count -F2FS_RESERVED_NODE_NUM ;
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 incorrectf_bfreecalculation in ->statfs")Cc <[email protected]> # 4.8+Signed-off-by Jaegeuk Kim <[email protected]>--- fs/f2fs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/f2fs/super.c +0
-0fs/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_countinuser_block_count, so shouldn't we addovp_countforf_bfreehere?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
-0sbi->reserved_blocks; avail_node_count = sbi->total_node_count -F2FS_RESERVED_NODE_NUM ;.