From: Chao Yu <chao@kernel.org>
To: Theodore Ts'o <tytso@mit.edu>
Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
linux-kernel@vger.kernel.org, Lukas Czerner <lczerner@redhat.com>
Subject: Re: [PATCH] ext4: fix to report fstrim.minlen back to userspace
Date: Sun, 12 Mar 2023 18:15:42 +0800 [thread overview]
Message-ID: <265f6c37-fae7-6ab2-594f-e7785aedb4e6@kernel.org> (raw)
In-Reply-To: <20230311031843.GF860405@mit.edu>
On 2023/3/11 11:18, Theodore Ts'o wrote:
> Unfortunately, this patch is not correct. The units of struct
> fstrim_range's minlen (here, range->minlen) is bytes.
Oh, that's right, sorry for the mistake.
>
> However the minlen variable in ext4_trim_fs is in units of *clusters*.
> And so it gets rounded up two places. The first time is when it is
> converted into units of a cluster:
>
> minlen = EXT4_NUM_B2C(EXT4_SB(sb),
> range->minlen >> sb->s_blocksize_bits);
IIUC, if range->minlen is smaller than block size of ext4, above calculation
may return a wrong value, due to it looks EXT4_NUM_B2C() expects a non-zero
in-parameter.
So it needs to round up minlen to block size first and then round up block
size to cluster size:
minlen = EXT4_NUM_B2C(EXT4_SB(sb),
EXT4_BLOCK_ALIGN(range->minlen, sb->s_blocksize_bits));
Or do the conversion at a time as you reminded:
minlen = (range->minlen + EXT4_CLUSTER_SIZE(sb) - 1) >>
(sb->s_blocksize_bits + EXT4_CLUSTER_BITS(sb));
>
> And the second time is when it is rounded up to the block device's
> discard granularity.
>
> So after that if statement, we need to convert minlen from clusters to
> bytes, like so:
>
> range->minlen = EXT4_C2B(EXT4_SB(sb), minlen) << sb->s_blocksize_bits);
Thanks for the detailed explanation and reminder. :)
Thanks,
prev parent reply other threads:[~2023-03-12 10:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-08 1:18 [PATCH] ext4: fix to report fstrim.minlen back to userspace Chao Yu
2023-03-11 3:18 ` Theodore Ts'o
2023-03-12 10:15 ` Chao Yu [this message]
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=265f6c37-fae7-6ab2-594f-e7785aedb4e6@kernel.org \
--to=chao@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=lczerner@redhat.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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).