xfs: do not allocate the entire delalloc extent in xfs_bmapi_write
authorChristoph Hellwig <hch@lst.de>
Mon, 29 Apr 2024 06:15:28 +0000 (08:15 +0200)
committerChandan Babu R <chandanbabu@kernel.org>
Tue, 30 Apr 2024 04:15:19 +0000 (09:45 +0530)
While trying to convert the entire delalloc extent is a good decision
for regular writeback as it leads to larger contigous on-disk extents,
but for other callers of xfs_bmapi_write is is rather questionable as
it forced them to loop creating new transactions just in case there
is no large enough contiguous extent to cover the whole delalloc
reservation.

Change xfs_bmapi_write to only allocate the passed in range instead,
whіle the writeback path through xfs_bmapi_convert_delalloc and
xfs_bmapi_allocate still always converts the full extents.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/libxfs/xfs_bmap.c

index ec204c430d536b4f90c0079c168a09e7d04dbff4..be515bac8ea1e0204373dd5f2cf4e91b87e7dd6d 100644 (file)
@@ -4524,8 +4524,9 @@ xfs_bmapi_write(
                        bma.length = XFS_FILBLKS_MIN(len, XFS_MAX_BMBT_EXTLEN);
 
                        if (wasdelay) {
-                               bma.offset = bma.got.br_startoff;
-                               bma.length = bma.got.br_blockcount;
+                               bma.length = XFS_FILBLKS_MIN(bma.length,
+                                       bma.got.br_blockcount -
+                                       (bno - bma.got.br_startoff));
                        } else {
                                if (!eof)
                                        bma.length = XFS_FILBLKS_MIN(bma.length,