mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Qi Han <hanqi@vivo.com>, jaegeuk@kernel.org
Cc: Chao Yu <chao@kernel.org>,
	linux-f2fs-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] f2fs: modify f2fs_is_checkpoint_ready logic to allow more data to be written with the CP disable
Date: Tue, 22 Oct 2024 10:53:13 +0800	[thread overview]
Message-ID: <3fdd8fdd-8b80-4989-8cfd-78051bd85936@kernel.org> (raw)
In-Reply-To: <20241009102745.1390935-1-hanqi@vivo.com>

On 2024/10/9 18:27, 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=55
> mkfs.f2fs -f f2fs.img
> mount f2fs.img f2fs_dir -o checkpoint=disable:10%
> cd f2fs_dir
> dd if=/dev/zero of=bigfile bs=1M count=50
> sync
> rm bigfile
> 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
> stat -f ./
> 
> 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 | 21 +++++++++++++++++++++
>   1 file changed, 21 insertions(+)
> 
> diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
> index 71adb4a43bec..9bf0cf3a6a31 100644
> --- a/fs/f2fs/segment.h
> +++ b/fs/f2fs/segment.h
> @@ -637,12 +637,33 @@ 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_available_blocks(struct f2fs_sb_info *sbi)
> +{
> +	unsigned int total_free_blocks = sbi->user_block_count -
> +					valid_user_blocks(sbi) -
> +					sbi->current_reserved_blocks;
> +
> +	if (total_free_blocks <= sbi->unusable_block_count)
> +		total_free_blocks = 0;
> +	else
> +		total_free_blocks -= sbi->unusable_block_count;
> +
> +	if (total_free_blocks > F2FS_OPTION(sbi).root_reserved_blocks)
> +		total_free_blocks -= F2FS_OPTION(sbi).root_reserved_blocks;
> +	else
> +		total_free_blocks = 0;
> +
> +	return (total_free_blocks > 0) ? true : false;

Can you please reuse get_available_block_count() as much as possible?
and cover it w/ stat_lock?

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_available_blocks(sbi)))
> +		return true;
>   	return false;
>   }
>   


  parent reply	other threads:[~2024-10-22  2:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 10:27 Qi Han
2024-10-17  9:54 ` Chao Yu
2024-10-18  1:52   ` [f2fs-dev] " Zhiguo Niu
2024-10-21  3:43     ` 韩棋
2024-10-22  2:53 ` Chao Yu [this message]
2024-10-22  3:14   ` 韩棋
2024-10-22  3:39     ` Chao Yu
2024-10-22  3:45       ` 韩棋

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3fdd8fdd-8b80-4989-8cfd-78051bd85936@kernel.org \
    --to=chao@kernel.org \
    --cc=hanqi@vivo.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®