public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH v2] xfs: fix the entry condition of exact EOF block allocation optimization
@ 2024-11-30 11:11 Jinliang Zheng
  2024-12-03 20:40 ` Dave Chinner
  0 siblings, 1 reply; 4+ messages in thread
From: Jinliang Zheng @ 2024-11-30 11:11 UTC (permalink / raw)
  To: cem, djwong
  Cc: hch, dchinner, chandanbabu, linux-xfs, linux-kernel,
	Jinliang Zheng

When we call create(), lseek() and write() sequentially, offset != 0
cannot be used as a judgment condition for whether the file already
has extents.

Furthermore, when xfs_bmap_adjacent() has not given a better blkno,
it is not necessary to use exact EOF block allocation.

Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
Changelog:
- V2: Fix the entry condition
- V1: https://lore.kernel.org/linux-xfs/ZyFJm7xg7Msd6eVr@dread.disaster.area/T/#t
---
 fs/xfs/libxfs/xfs_bmap.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 36dd08d13293..c1e5372b6b2e 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -3531,12 +3531,14 @@ xfs_bmap_btalloc_at_eof(
 	int			error;
 
 	/*
-	 * 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.
+	 * If there are already extents in the file, and xfs_bmap_adjacent() has
+	 * given a better blkno, 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.
 	 */
-	if (ap->offset) {
+	if (ap->prev.br_startoff != NULLFILEOFF &&
+	     !isnullstartblock(ap->prev.br_startblock) &&
+	     xfs_bmap_adjacent_valid(ap, ap->blkno, ap->prev.br_startblock)) {
 		xfs_extlen_t	nextminlen = 0;
 
 		/*
-- 
2.41.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-05 23:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 11:11 [RESEND PATCH v2] xfs: fix the entry condition of exact EOF block allocation optimization Jinliang Zheng
2024-12-03 20:40 ` Dave Chinner
2024-12-05 12:18   ` Jinliang Zheng
2024-12-05 23:48     ` Dave Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox