* [f2fs-dev] [PATCH v2] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable
@ 2024-10-22 9:15 Qi Han via Linux-f2fs-devel
2024-10-23 1:50 ` Chao Yu via Linux-f2fs-devel
0 siblings, 1 reply; 2+ messages in thread
From: Qi Han via Linux-f2fs-devel @ 2024-10-22 9:15 UTC (permalink / raw)
To: jaegeuk, chao; +Cc: Qi Han, linux-kernel, linux-f2fs-devel
When the free segment is used up during CP disable, many write or
ioctl operations will get ENOSPC error codes, even if there are
still many blocks available. We can reproduce it in the following
steps:
dd if=/dev/zero of=f2fs.img bs=1M count=65
mkfs.f2fs -f f2fs.img
mount f2fs.img f2fs_dir -o checkpoint=disable:10%
cd f2fs_dir
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done
sync
i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
-s 1K $file_name); i=$((i+1)); done
sync
i=1; while [[ $i -lt 10000000 ]]; do (file_name=./file$i; dd \
if=/dev/random of=$file_name bs=1M count=0); i=$((i+1)); done
In f2fs_need_SSR() function, it is allowed to use SSR to allocate
blocks when CP is disabled, so in f2fs_is_checkpoint_ready function,
can we judge the number of invalid blocks when free segment is not
enough, and return ENOSPC only if the number of invalid blocks is
also not enough?
Signed-off-by: Qi Han <hanqi@vivo.com>
---
fs/f2fs/segment.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 71adb4a43bec..b7af84a07435 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -637,12 +637,31 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,
return !has_not_enough_free_secs(sbi, freed, needed);
}
+static inline bool has_enough_free_blks(struct f2fs_sb_info *sbi)
+{
+ long long total_free_blocks = 0;
+ block_t avail_user_block_count;
+ block_t valid_block_count;
+
+ spin_lock(&sbi->stat_lock);
+
+ avail_user_block_count = get_available_block_count(sbi, NULL, true);
+ valid_block_count = valid_user_blocks(sbi);
+ total_free_blocks = avail_user_block_count - valid_block_count;
+
+ spin_unlock(&sbi->stat_lock);
+
+ return (total_free_blocks > 0) ? true : false;
+}
+
static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
{
if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
return true;
if (likely(has_enough_free_secs(sbi, 0, 0)))
return true;
+ if (likely(has_enough_free_blks(sbi)))
+ return true;
return false;
}
--
2.39.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [f2fs-dev] [PATCH v2] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable
2024-10-22 9:15 [f2fs-dev] [PATCH v2] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable Qi Han via Linux-f2fs-devel
@ 2024-10-23 1:50 ` Chao Yu via Linux-f2fs-devel
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu via Linux-f2fs-devel @ 2024-10-23 1:50 UTC (permalink / raw)
To: Qi Han, jaegeuk; +Cc: linux-kernel, linux-f2fs-devel
On 2024/10/22 17:15, Qi Han wrote:
> When the free segment is used up during CP disable, many write or
> ioctl operations will get ENOSPC error codes, even if there are
> still many blocks available. We can reproduce it in the following
> steps:
>
> dd if=/dev/zero of=f2fs.img bs=1M count=65
> mkfs.f2fs -f f2fs.img
> mount f2fs.img f2fs_dir -o checkpoint=disable:10%
> cd f2fs_dir
> i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; dd \
> if=/dev/random of=$file_name bs=1M count=2); i=$((i+1)); done
> sync
> i=1 ; while [[ $i -lt 50 ]] ; do (file_name=./2M_file$i ; truncate \
> -s 1K $file_name); i=$((i+1)); done
> sync
> i=1; while [[ $i -lt 10000000 ]]; do (file_name=./file$i; dd \
> if=/dev/random of=$file_name bs=1M count=0); i=$((i+1)); done
'dd if=/dev/zero of=./file bs=1M count=20' will be more quick to
trigger SSR allocation.
>
> In f2fs_need_SSR() function, it is allowed to use SSR to allocate
> blocks when CP is disabled, so in f2fs_is_checkpoint_ready function,
> can we judge the number of invalid blocks when free segment is not
> enough, and return ENOSPC only if the number of invalid blocks is
> also not enough?
>
> Signed-off-by: Qi Han <hanqi@vivo.com>
> ---
> fs/f2fs/segment.h | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index 71adb4a43bec..b7af84a07435 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -637,12 +637,31 @@ static inline bool has_enough_free_secs(struct f2fs_sb_info *sbi,
> return !has_not_enough_free_secs(sbi, freed, needed);
> }
>
> +static inline bool has_enough_free_blks(struct f2fs_sb_info *sbi)
> +{
> + long long total_free_blocks = 0;
> + block_t avail_user_block_count;
long long avail_user_block_count;
> + block_t valid_block_count;
> +
> + spin_lock(&sbi->stat_lock);
> +
> + avail_user_block_count = get_available_block_count(sbi, NULL, true);
> + valid_block_count = valid_user_blocks(sbi);
> + total_free_blocks = avail_user_block_count - valid_block_count;
total_free_blocks =
avail_user_block_count - (long long)valid_user_blocks(sbi);
Then, we can avoid allocating & assigning valid_block_count variable.
> +
> + spin_unlock(&sbi->stat_lock);
> +
> + return (total_free_blocks > 0) ? true : false;
return total_free_blocks > 0;
Thanks,
> +}
> +
> static inline bool f2fs_is_checkpoint_ready(struct f2fs_sb_info *sbi)
> {
> if (likely(!is_sbi_flag_set(sbi, SBI_CP_DISABLED)))
> return true;
> if (likely(has_enough_free_secs(sbi, 0, 0)))
> return true;
> + if (likely(has_enough_free_blks(sbi)))
> + return true;
> return false;
> }
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-23 1:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 9:15 [f2fs-dev] [PATCH v2] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable Qi Han via Linux-f2fs-devel
2024-10-23 1:50 ` Chao Yu via Linux-f2fs-devel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).