linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Yongpeng Yang <yangyongpeng.storage@gmail.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Yongpeng Yang <yangyongpeng@xiaomi.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH] f2fs: ensure minimum trim granularity accounts for all devices
Date: Mon, 27 Oct 2025 16:35:03 +0800	[thread overview]
Message-ID: <c0689523-a265-47ce-b443-b4fe4ae7d823@kernel.org> (raw)
In-Reply-To: <20251024143746.187140-1-yangyongpeng.storage@gmail.com>

On 10/24/25 22:37, Yongpeng Yang wrote:
> From: Yongpeng Yang <yangyongpeng@xiaomi.com>
> 
> When F2FS uses multiple block devices, each device may have a
> different discard granularity. The minimum trim granularity must be
> at least the maximum discard granularity of all devices, excluding
> zoned devices. Use max_t instead of the max() macro to compute the
> maximum value.
> 
> Signed-off-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
> ---
>  fs/f2fs/f2fs.h | 12 ++++++++++++
>  fs/f2fs/file.c | 12 ++++++------
>  2 files changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 32fb2e7338b7..064bdbf463f7 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -4762,6 +4762,18 @@ static inline bool f2fs_hw_support_discard(struct f2fs_sb_info *sbi)
>  	return false;
>  }
>  
> +static inline unsigned int f2fs_hw_discard_granularity(struct f2fs_sb_info *sbi)
> +{
> +	int i = 1;
> +	unsigned int discard_granularity = bdev_discard_granularity(sbi->sb->s_bdev);

Yongpeng,

The patch makes sense to me.

One extra question, if a zoned device contains both conventional zones and
sequential zones, what discard granularity will it exposes?

Thanks,

> +
> +	if (f2fs_is_multi_device(sbi))
> +		for (; i < sbi->s_ndevs && !bdev_is_zoned(FDEV(i).bdev); i++)
> +			discard_granularity = max_t(unsigned int, discard_granularity,
> +						bdev_discard_granularity(FDEV(i).bdev));
> +	return discard_granularity;
> +}
> +
>  static inline bool f2fs_realtime_discard_enable(struct f2fs_sb_info *sbi)
>  {
>  	return (test_opt(sbi, DISCARD) && f2fs_hw_support_discard(sbi)) ||
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 6d42e2d28861..ced0f78532c9 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -2588,14 +2588,14 @@ static int f2fs_keep_noreuse_range(struct inode *inode,
>  static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg)
>  {
>  	struct inode *inode = file_inode(filp);
> -	struct super_block *sb = inode->i_sb;
> +	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
>  	struct fstrim_range range;
>  	int ret;
>  
>  	if (!capable(CAP_SYS_ADMIN))
>  		return -EPERM;
>  
> -	if (!f2fs_hw_support_discard(F2FS_SB(sb)))
> +	if (!f2fs_hw_support_discard(sbi))
>  		return -EOPNOTSUPP;
>  
>  	if (copy_from_user(&range, (struct fstrim_range __user *)arg,
> @@ -2606,9 +2606,9 @@ static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg)
>  	if (ret)
>  		return ret;
>  
> -	range.minlen = max((unsigned int)range.minlen,
> -			   bdev_discard_granularity(sb->s_bdev));
> -	ret = f2fs_trim_fs(F2FS_SB(sb), &range);
> +	range.minlen = max_t(unsigned int, range.minlen,
> +			f2fs_hw_discard_granularity(sbi));
> +	ret = f2fs_trim_fs(sbi, &range);
>  	mnt_drop_write_file(filp);
>  	if (ret < 0)
>  		return ret;
> @@ -2616,7 +2616,7 @@ static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg)
>  	if (copy_to_user((struct fstrim_range __user *)arg, &range,
>  				sizeof(range)))
>  		return -EFAULT;
> -	f2fs_update_time(F2FS_I_SB(inode), REQ_TIME);
> +	f2fs_update_time(sbi, REQ_TIME);
>  	return 0;
>  }
>  



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2025-10-27  8:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-24 14:37 [f2fs-dev] [PATCH] f2fs: ensure minimum trim granularity accounts for all devices Yongpeng Yang
2025-10-27  8:35 ` Chao Yu via Linux-f2fs-devel [this message]
2025-10-27 13:06   ` Yongpeng Yang
2025-10-28  2:30     ` Chao Yu via Linux-f2fs-devel
2025-10-28  9:27       ` Yongpeng Yang
2025-10-29  9:42 ` Chao Yu via Linux-f2fs-devel

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=c0689523-a265-47ce-b443-b4fe4ae7d823@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=yangyongpeng.storage@gmail.com \
    --cc=yangyongpeng@xiaomi.com \
    /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;
as well as URLs for NNTP newsgroup(s).