* [PATCH] xfs: fix the judgment of whether the file already has extents
@ 2024-10-26 18:01 alexjlzheng
2024-10-28 9:41 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: alexjlzheng @ 2024-10-26 18:01 UTC (permalink / raw)
To: cem, djwong
Cc: chandanbabu, dchinner, zhangjiachen.jaycee, linux-xfs,
linux-kernel, Jinliang Zheng
From: Jinliang Zheng <alexjlzheng@tencent.com>
When we call create(), lseek() and write() sequentially, offset != 0
cannot be used as a judgment condition for whether the file already
has extents.
This patch uses prev.br_startoff instead of offset != 0.
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
fs/xfs/libxfs/xfs_bmap.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 36dd08d13293..94e7aeed9e95 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3536,7 +3536,7 @@ xfs_bmap_btalloc_at_eof(
* or it's the first allocation in a file, just try for a stripe aligned
* allocation.
*/
- if (ap->offset) {
+ if (ap->prev.br_startoff != NULLFILEOFF) {
xfs_extlen_t nextminlen = 0;
/*
--
2.41.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix the judgment of whether the file already has extents
2024-10-26 18:01 [PATCH] xfs: fix the judgment of whether the file already has extents alexjlzheng
@ 2024-10-28 9:41 ` Christoph Hellwig
2024-10-28 10:33 ` Jinliang Zheng
2024-10-29 20:46 ` Dave Chinner
2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2024-10-28 9:41 UTC (permalink / raw)
To: alexjlzheng
Cc: cem, djwong, chandanbabu, dchinner, zhangjiachen.jaycee,
linux-xfs, linux-kernel, Jinliang Zheng
On Sun, Oct 27, 2024 at 02:01:16AM +0800, alexjlzheng@gmail.com wrote:
> From: Jinliang Zheng <alexjlzheng@tencent.com>
>
> When we call create(), lseek() and write() sequentially, offset != 0
> cannot be used as a judgment condition for whether the file already
> has extents.
>
> This patch uses prev.br_startoff instead of offset != 0.
This changed the predicate from "are we at offset 0" to "are there
any allocations before that". That's a pretty big semantic change.
Maybe a good one, maybe not. Can you explain what workload it helps
you with?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix the judgment of whether the file already has extents
2024-10-26 18:01 [PATCH] xfs: fix the judgment of whether the file already has extents alexjlzheng
2024-10-28 9:41 ` Christoph Hellwig
@ 2024-10-28 10:33 ` Jinliang Zheng
2024-10-28 10:42 ` Jinliang Zheng
2024-10-29 20:46 ` Dave Chinner
2 siblings, 1 reply; 5+ messages in thread
From: Jinliang Zheng @ 2024-10-28 10:33 UTC (permalink / raw)
To: alexjlzheng
Cc: alexjlzheng, cem, chandanbabu, dchinner, djwong, linux-kernel,
linux-xfs, zhangjiachen.jaycee
On Mon, 28 Oct 2024 02:41:01 -0700, hch@infradead.org wrote:
> On Sun, Oct 27, 2024 at 02:01:16AM +0800, alexjlzheng@gmail.com wrote:
> > From: Jinliang Zheng <alexjlzheng@tencent.com>
> >
> > When we call create(), lseek() and write() sequentially, offset != 0
> > cannot be used as a judgment condition for whether the file already
> > has extents.
> >
> > This patch uses prev.br_startoff instead of offset != 0.
>
> This changed the predicate from "are we at offset 0" to "are there
> any allocations before that". That's a pretty big semantic change.
> Maybe a good one, maybe not. Can you explain what workload it helps
> you with?
Thanks for your reply.
I noticed this because I was confused when reading the code here. The code
comment here says:
/*
* If there are already extents in the file, try an exact EOF block
* allocation to extend the file as a contiguous extent. If that fails,
* or it's the first allocation in a file, just try for a stripe aligned
* allocation.
*/
But as you said, the semantics of the current code is "are we at offset 0",
not "are there any allocations before that".
Therefore, I think it is better to use "prev.br_startoff != NULLFILEOFF"
instead of the current "offset != 0", at least its semantics are more
consistent with the intention in the code comment and reduce confusion.
But if the semantics here have indeed changed to the point where it is
inconsistent with the code comment, my suggestion is to update the code
comment here.
Thank you. :)
Jinliang Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix the judgment of whether the file already has extents
2024-10-28 10:33 ` Jinliang Zheng
@ 2024-10-28 10:42 ` Jinliang Zheng
0 siblings, 0 replies; 5+ messages in thread
From: Jinliang Zheng @ 2024-10-28 10:42 UTC (permalink / raw)
To: alexjlzheng
Cc: alexjlzheng, cem, chandanbabu, dchinner, djwong, linux-kernel,
linux-xfs, zhangjiachen.jaycee
On Mon, 28 Oct 2024 18:33:32 +0800, alexjlzheng@tencent.com wrote:
> On Mon, 28 Oct 2024 02:41:01 -0700, hch@infradead.org wrote:
> > On Sun, Oct 27, 2024 at 02:01:16AM +0800, alexjlzheng@gmail.com wrote:
> > > From: Jinliang Zheng <alexjlzheng@tencent.com>
> > >
> > > When we call create(), lseek() and write() sequentially, offset != 0
> > > cannot be used as a judgment condition for whether the file already
> > > has extents.
> > >
> > > This patch uses prev.br_startoff instead of offset != 0.
> >
> > This changed the predicate from "are we at offset 0" to "are there
> > any allocations before that". That's a pretty big semantic change.
> > Maybe a good one, maybe not. Can you explain what workload it helps
> > you with?
>
>
> Thanks for your reply.
>
> I noticed this because I was confused when reading the code here. The code
> comment here says:
>
> /*
> * If there are already extents in the file, try an exact EOF block
> * allocation to extend the file as a contiguous extent. If that fails,
> * or it's the first allocation in a file, just try for a stripe aligned
> * allocation.
> */
>
> But as you said, the semantics of the current code is "are we at offset 0",
> not "are there any allocations before that".
By the way, we only get here if got is or after EOF, so "are there any allocations
before that" means "are there already extents in the file".
Thank you, again. :)
Jinliang Zheng
>
> Therefore, I think it is better to use "prev.br_startoff != NULLFILEOFF"
> instead of the current "offset != 0", at least its semantics are more
> consistent with the intention in the code comment and reduce confusion.
>
> But if the semantics here have indeed changed to the point where it is
> inconsistent with the code comment, my suggestion is to update the code
> comment here.
>
> Thank you. :)
> Jinliang Zheng
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] xfs: fix the judgment of whether the file already has extents
2024-10-26 18:01 [PATCH] xfs: fix the judgment of whether the file already has extents alexjlzheng
2024-10-28 9:41 ` Christoph Hellwig
2024-10-28 10:33 ` Jinliang Zheng
@ 2024-10-29 20:46 ` Dave Chinner
2 siblings, 0 replies; 5+ messages in thread
From: Dave Chinner @ 2024-10-29 20:46 UTC (permalink / raw)
To: alexjlzheng
Cc: cem, djwong, chandanbabu, dchinner, zhangjiachen.jaycee,
linux-xfs, linux-kernel, Jinliang Zheng
On Sun, Oct 27, 2024 at 02:01:16AM +0800, alexjlzheng@gmail.com wrote:
> From: Jinliang Zheng <alexjlzheng@tencent.com>
>
> When we call create(), lseek() and write() sequentially, offset != 0
> cannot be used as a judgment condition for whether the file already
> has extents.
>
> This patch uses prev.br_startoff instead of offset != 0.
>
> Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
> ---
> fs/xfs/libxfs/xfs_bmap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
> index 36dd08d13293..94e7aeed9e95 100644
> --- a/fs/xfs/libxfs/xfs_bmap.c
> +++ b/fs/xfs/libxfs/xfs_bmap.c
> @@ -3536,7 +3536,7 @@ xfs_bmap_btalloc_at_eof(
> * or it's the first allocation in a file, just try for a stripe aligned
> * allocation.
> */
> - if (ap->offset) {
> + if (ap->prev.br_startoff != NULLFILEOFF) {
> xfs_extlen_t nextminlen = 0;
Makes sense, but the logic is not correct. See xfs_bmap_adjacent()
on how it sets up the ap->blkno target for exact eof bno allocation.
-Dave.
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-29 20:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-26 18:01 [PATCH] xfs: fix the judgment of whether the file already has extents alexjlzheng
2024-10-28 9:41 ` Christoph Hellwig
2024-10-28 10:33 ` Jinliang Zheng
2024-10-28 10:42 ` Jinliang Zheng
2024-10-29 20:46 ` Dave Chinner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox