From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Zhiguo Niu <niuzhiguo84@gmail.com>
Cc: ke.wang@unisoc.com, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
Zhiguo Niu <zhiguo.niu@unisoc.com>,
jaegeuk@kernel.org, Hao_hao.Wang@unisoc.com
Subject: Re: [f2fs-dev] [PATCH V2] f2fs: fix to adjust appropriate length for fiemap
Date: Wed, 6 Nov 2024 10:16:20 +0800 [thread overview]
Message-ID: <9199e9fc-7b5b-4069-b79b-65ba5ae1b0f6@kernel.org> (raw)
In-Reply-To: <CAHJ8P3LddwapGLV5nKmw1ULTm7qp5OMk-kFBK3s_UptPPeph7w@mail.gmail.com>
On 2024/11/5 19:02, Zhiguo Niu wrote:
> Chao Yu <chao@kernel.org> 于2024年11月5日周二 18:39写道:
>>
>> On 2024/11/5 15:28, Zhiguo Niu wrote:
>>> Chao Yu <chao@kernel.org> 于2024年11月5日周二 15:04写道:
>>>>
>>>> On 2024/11/4 9:56, Zhiguo Niu wrote:
>>>>> If user give a file size as "length" parameter for fiemap
>>>>> operations, but if this size is non-block size aligned,
>>>>> it will show 2 segments fiemap results even this whole file
>>>>> is contiguous on disk, such as the following results:
>>>>>
>>>>> ./f2fs_io fiemap 0 19034 ylog/analyzer.py
>>>>> Fiemap: offset = 0 len = 19034
>>>>> logical addr. physical addr. length flags
>>>>> 0 0000000000000000 0000000020baa000 0000000000004000 00001000
>>>>> 1 0000000000004000 0000000020bae000 0000000000001000 00001001
>>>>>
>>>>> after this patch:
>>>>> ./f2fs_io fiemap 0 19034 ylog/analyzer.py
>>>>> Fiemap: offset = 0 len = 19034
>>>>> logical addr. physical addr. length flags
>>>>> 0 0000000000000000 00000000315f3000 0000000000005000 00001001
>>>>>
>>>>> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
>>>>> ---
>>>>> V2: correct commit msg according to Chao's questions
>>>>> f2fs_io has been modified for testing, the length for fiemap is
>>>>> real file size, not block number
>>>>> ---
>>>>> fs/f2fs/data.c | 4 ++--
>>>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
>>>>> index 306b86b0..9fc229d 100644
>>>>> --- a/fs/f2fs/data.c
>>>>> +++ b/fs/f2fs/data.c
>>>>> @@ -1966,8 +1966,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>>>>> goto out;
>>>>> }
>>>>>
>>>>> - if (bytes_to_blks(inode, len) == 0)
>>>>> - len = blks_to_bytes(inode, 1);
>>>>> + if (len & (blks_to_bytes(inode, 1) - 1))
>>>>> + len = round_up(len, blks_to_bytes(inode, 1));
>>>>
>>>> How do you think of getting rid of above alignment for len?
>>>>
>>>>>
>>>>> start_blk = bytes_to_blks(inode, start);
>>>>> last_blk = bytes_to_blks(inode, start + len - 1);
>>>>
>>>> And round up end position w/:
>>>>
>>>> last_blk = bytes_to_blks(inode, round_up(start + len - 1, F2FS_BLKSIZE));
>>> Hi Chao,
>>> I think this will change the current code logic
>>> -------------
>>> if (start_blk > last_blk)
>>> goto out;
>>> -------------
>>> for example, a file with size 19006, but the length from the user is 16384.
>>> before this modification, last_blk = bytes_to_blks(inode, start +
>>> len - 1) = (inode, 16383) = 3
>>> after the first f2fs_map_blocks(). start_blk change to be 4,
>>> after the second f2fs_map_blocks(), fiemap_fill_nex_exten will be
>>> called to fill user parameter and then
>>> will goto out because start_blk > last_blk, then fiemap flow finishes.
>>> but after this modification, last_blk will be 4
>>> will do f2fs_map_blocks() until reach the max_file_blocks(inode)
>>
>> Yes, you're right, however, w/ this patch, it may change last_blk, e.g.
>>
>> xfs_io file -c "fiemap -v 0 19006" vs xfs_io file -c "fiemap -v 2 19006"
>> start_blk and last_blk will be: 0, 4 and 0, 5.
> Hi Chao,
> yes, but w/o this patch , the original code still has the same situation??
> for example
> xfs_io file -c "fiemap -v 0 16384" vs xfs_io file -c "fiemap -v 2 16384"
> start_blk and last_blk will be: 0, 3 and 0, 4.
For the case "fiemap -v 2 19006", offset is 2, and length is 19006, so last_offset
is 19008, and last_blk should be 4 rather than 5, right?
And for you case, it calculates last_blk correctly.
Thanks,
> but overall last_blk will change loop counts but has not affect on the results.
>>
>> Should we round_up len after start_blk & last_blk calculation?
> I thinks it is ok ,but just a little bit redundant with the following
> handling about len.
>
> if (bytes_to_blks(inode, len) == 0)
> len = blks_to_bytes(inode, 1);
>
> Based on the above situation,
> do you have any other good suggestions? ^^
> thanks!
>
>>
>> Thanks,
>>
>>> thanks!
>>>>
>>>> Thanks,
>>>>
>>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
WARNING: multiple messages have this Message-ID (diff)
From: Chao Yu <chao@kernel.org>
To: Zhiguo Niu <niuzhiguo84@gmail.com>
Cc: Chao Yu <chao@kernel.org>, Zhiguo Niu <zhiguo.niu@unisoc.com>,
jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, ke.wang@unisoc.com,
Hao_hao.Wang@unisoc.com
Subject: Re: [PATCH V2] f2fs: fix to adjust appropriate length for fiemap
Date: Wed, 6 Nov 2024 10:16:20 +0800 [thread overview]
Message-ID: <9199e9fc-7b5b-4069-b79b-65ba5ae1b0f6@kernel.org> (raw)
In-Reply-To: <CAHJ8P3LddwapGLV5nKmw1ULTm7qp5OMk-kFBK3s_UptPPeph7w@mail.gmail.com>
On 2024/11/5 19:02, Zhiguo Niu wrote:
> Chao Yu <chao@kernel.org> 于2024年11月5日周二 18:39写道:
>>
>> On 2024/11/5 15:28, Zhiguo Niu wrote:
>>> Chao Yu <chao@kernel.org> 于2024年11月5日周二 15:04写道:
>>>>
>>>> On 2024/11/4 9:56, Zhiguo Niu wrote:
>>>>> If user give a file size as "length" parameter for fiemap
>>>>> operations, but if this size is non-block size aligned,
>>>>> it will show 2 segments fiemap results even this whole file
>>>>> is contiguous on disk, such as the following results:
>>>>>
>>>>> ./f2fs_io fiemap 0 19034 ylog/analyzer.py
>>>>> Fiemap: offset = 0 len = 19034
>>>>> logical addr. physical addr. length flags
>>>>> 0 0000000000000000 0000000020baa000 0000000000004000 00001000
>>>>> 1 0000000000004000 0000000020bae000 0000000000001000 00001001
>>>>>
>>>>> after this patch:
>>>>> ./f2fs_io fiemap 0 19034 ylog/analyzer.py
>>>>> Fiemap: offset = 0 len = 19034
>>>>> logical addr. physical addr. length flags
>>>>> 0 0000000000000000 00000000315f3000 0000000000005000 00001001
>>>>>
>>>>> Signed-off-by: Zhiguo Niu <zhiguo.niu@unisoc.com>
>>>>> ---
>>>>> V2: correct commit msg according to Chao's questions
>>>>> f2fs_io has been modified for testing, the length for fiemap is
>>>>> real file size, not block number
>>>>> ---
>>>>> fs/f2fs/data.c | 4 ++--
>>>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
>>>>> index 306b86b0..9fc229d 100644
>>>>> --- a/fs/f2fs/data.c
>>>>> +++ b/fs/f2fs/data.c
>>>>> @@ -1966,8 +1966,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
>>>>> goto out;
>>>>> }
>>>>>
>>>>> - if (bytes_to_blks(inode, len) == 0)
>>>>> - len = blks_to_bytes(inode, 1);
>>>>> + if (len & (blks_to_bytes(inode, 1) - 1))
>>>>> + len = round_up(len, blks_to_bytes(inode, 1));
>>>>
>>>> How do you think of getting rid of above alignment for len?
>>>>
>>>>>
>>>>> start_blk = bytes_to_blks(inode, start);
>>>>> last_blk = bytes_to_blks(inode, start + len - 1);
>>>>
>>>> And round up end position w/:
>>>>
>>>> last_blk = bytes_to_blks(inode, round_up(start + len - 1, F2FS_BLKSIZE));
>>> Hi Chao,
>>> I think this will change the current code logic
>>> -------------
>>> if (start_blk > last_blk)
>>> goto out;
>>> -------------
>>> for example, a file with size 19006, but the length from the user is 16384.
>>> before this modification, last_blk = bytes_to_blks(inode, start +
>>> len - 1) = (inode, 16383) = 3
>>> after the first f2fs_map_blocks(). start_blk change to be 4,
>>> after the second f2fs_map_blocks(), fiemap_fill_nex_exten will be
>>> called to fill user parameter and then
>>> will goto out because start_blk > last_blk, then fiemap flow finishes.
>>> but after this modification, last_blk will be 4
>>> will do f2fs_map_blocks() until reach the max_file_blocks(inode)
>>
>> Yes, you're right, however, w/ this patch, it may change last_blk, e.g.
>>
>> xfs_io file -c "fiemap -v 0 19006" vs xfs_io file -c "fiemap -v 2 19006"
>> start_blk and last_blk will be: 0, 4 and 0, 5.
> Hi Chao,
> yes, but w/o this patch , the original code still has the same situation??
> for example
> xfs_io file -c "fiemap -v 0 16384" vs xfs_io file -c "fiemap -v 2 16384"
> start_blk and last_blk will be: 0, 3 and 0, 4.
For the case "fiemap -v 2 19006", offset is 2, and length is 19006, so last_offset
is 19008, and last_blk should be 4 rather than 5, right?
And for you case, it calculates last_blk correctly.
Thanks,
> but overall last_blk will change loop counts but has not affect on the results.
>>
>> Should we round_up len after start_blk & last_blk calculation?
> I thinks it is ok ,but just a little bit redundant with the following
> handling about len.
>
> if (bytes_to_blks(inode, len) == 0)
> len = blks_to_bytes(inode, 1);
>
> Based on the above situation,
> do you have any other good suggestions? ^^
> thanks!
>
>>
>> Thanks,
>>
>>> thanks!
>>>>
>>>> Thanks,
>>>>
>>
next prev parent reply other threads:[~2024-11-06 2:16 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 1:56 [f2fs-dev] [PATCH V2] f2fs: fix to adjust appropriate length for fiemap Zhiguo Niu
2024-11-04 1:56 ` Zhiguo Niu
2024-11-05 3:15 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-05 3:15 ` Chao Yu
2024-11-05 4:02 ` [f2fs-dev] " Zhiguo Niu
2024-11-05 4:02 ` Zhiguo Niu
2024-11-05 6:56 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-05 6:56 ` Chao Yu
2024-11-05 7:04 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-05 7:04 ` Chao Yu
2024-11-05 7:28 ` [f2fs-dev] " Zhiguo Niu
2024-11-05 7:28 ` Zhiguo Niu
2024-11-05 10:39 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-05 10:39 ` Chao Yu
2024-11-05 11:02 ` [f2fs-dev] " Zhiguo Niu
2024-11-05 11:02 ` Zhiguo Niu
2024-11-06 2:16 ` Chao Yu via Linux-f2fs-devel [this message]
2024-11-06 2:16 ` Chao Yu
2024-11-06 2:26 ` [f2fs-dev] " Zhiguo Niu
2024-11-06 2:26 ` Zhiguo Niu
2024-11-06 2:40 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-06 2:40 ` Chao Yu
2024-11-06 2:54 ` [f2fs-dev] " Zhiguo Niu
2024-11-06 2:54 ` Zhiguo Niu
2024-11-06 6:45 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-06 6:45 ` Chao Yu
2024-11-06 6:08 ` [f2fs-dev] " Zhiguo Niu
2024-11-06 6:08 ` Zhiguo Niu
2024-11-06 7:40 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-06 7:40 ` Chao Yu
2024-11-06 8:41 ` [f2fs-dev] " Zhiguo Niu
2024-11-06 8:41 ` Zhiguo Niu
2024-11-07 6:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-07 6:18 ` Chao Yu
2024-11-07 6:54 ` [f2fs-dev] " Zhiguo Niu
2024-11-07 6:54 ` Zhiguo Niu
2024-11-07 8:22 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-07 8:22 ` Chao Yu
2024-11-07 10:53 ` [f2fs-dev] " Zhiguo Niu
2024-11-07 10:53 ` Zhiguo Niu
2024-11-08 1:22 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2024-11-08 1:22 ` Chao Yu
2024-11-08 1:53 ` [f2fs-dev] " Zhiguo Niu
2024-11-08 1:53 ` Zhiguo Niu
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=9199e9fc-7b5b-4069-b79b-65ba5ae1b0f6@kernel.org \
--to=linux-f2fs-devel@lists.sourceforge.net \
--cc=Hao_hao.Wang@unisoc.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=ke.wang@unisoc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=niuzhiguo84@gmail.com \
--cc=zhiguo.niu@unisoc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.