Skip to content

Commit 288e1f6

Browse files
Darrick J. WongChandan Babu R
authored andcommitted
xfs: restrict when we try to align cow fork delalloc to cowextsz hints
xfs/205 produces the following failure when always_cow is enabled: --- a/tests/xfs/205.out 2024-02-28 16:20:24.437887970 -0800 +++ b/tests/xfs/205.out.bad 2024-06-03 21:13:40.584000000 -0700 @@ -1,4 +1,5 @@ QA output created by 205 *** one file + !!! disk full (expected) *** one file, a few bytes at a time *** done This is the result of overly aggressive attempts to align cow fork delalloc reservations to the CoW extent size hint. Looking at the trace data, we're trying to append a single fsblock to the "fred" file. Trying to create a speculative post-eof reservation fails because there's not enough space. We then set @prealloc_blocks to zero and try again, but the cowextsz alignment code triggers, which expands our request for a 1-fsblock reservation into a 39-block reservation. There's not enough space for that, so the whole write fails with ENOSPC even though there's sufficient space in the filesystem to allocate the single block that we need to land the write. There are two things wrong here -- first, we shouldn't be attempting speculative preallocations beyond what was requested when we're low on space. Second, if we've already computed a posteof preallocation, we shouldn't bother trying to align that to the cowextsize hint. Fix both of these problems by adding a flag that only enables the expansion of the delalloc reservation to the cowextsize if we're doing a non-extending write, and only if we're not doing an ENOSPC retry. This requires us to move the ENOSPC retry logic to xfs_bmapi_reserve_delalloc. I probably should have caught this six years ago when 6ca3072 was being reviewed, but oh well. Update the comments to reflect what the code does now. Fixes: 6ca3072 ("xfs: bmap code cleanup") Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 610b291 commit 288e1f6

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,20 +4058,32 @@ xfs_bmapi_reserve_delalloc(
40584058
xfs_extlen_t indlen;
40594059
uint64_t fdblocks;
40604060
int error;
4061-
xfs_fileoff_t aoff = off;
4061+
xfs_fileoff_t aoff;
4062+
bool use_cowextszhint =
4063+
whichfork == XFS_COW_FORK && !prealloc;
40624064

4065+
retry:
40634066
/*
40644067
* Cap the alloc length. Keep track of prealloc so we know whether to
40654068
* tag the inode before we return.
40664069
*/
4070+
aoff = off;
40674071
alen = XFS_FILBLKS_MIN(len + prealloc, XFS_MAX_BMBT_EXTLEN);
40684072
if (!eof)
40694073
alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff);
40704074
if (prealloc && alen >= len)
40714075
prealloc = alen - len;
40724076

4073-
/* Figure out the extent size, adjust alen */
4074-
if (whichfork == XFS_COW_FORK) {
4077+
/*
4078+
* If we're targetting the COW fork but aren't creating a speculative
4079+
* posteof preallocation, try to expand the reservation to align with
4080+
* the COW extent size hint if there's sufficient free space.
4081+
*
4082+
* Unlike the data fork, the CoW cancellation functions will free all
4083+
* the reservations at inactivation, so we don't require that every
4084+
* delalloc reservation have a dirty pagecache.
4085+
*/
4086+
if (use_cowextszhint) {
40754087
struct xfs_bmbt_irec prev;
40764088
xfs_extlen_t extsz = xfs_get_cowextsz_hint(ip);
40774089

@@ -4090,7 +4102,7 @@ xfs_bmapi_reserve_delalloc(
40904102
*/
40914103
error = xfs_quota_reserve_blkres(ip, alen);
40924104
if (error)
4093-
return error;
4105+
goto out;
40944106

40954107
/*
40964108
* Split changing sb for alen and indlen since they could be coming
@@ -4140,6 +4152,17 @@ xfs_bmapi_reserve_delalloc(
41404152
out_unreserve_quota:
41414153
if (XFS_IS_QUOTA_ON(mp))
41424154
xfs_quota_unreserve_blkres(ip, alen);
4155+
out:
4156+
if (error == -ENOSPC || error == -EDQUOT) {
4157+
trace_xfs_delalloc_enospc(ip, off, len);
4158+
4159+
if (prealloc || use_cowextszhint) {
4160+
/* retry without any preallocation */
4161+
use_cowextszhint = false;
4162+
prealloc = 0;
4163+
goto retry;
4164+
}
4165+
}
41434166
return error;
41444167
}
41454168

fs/xfs/xfs_iomap.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,33 +1148,23 @@ xfs_buffered_write_iomap_begin(
11481148
}
11491149
}
11501150

1151-
retry:
1152-
error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb,
1153-
end_fsb - offset_fsb, prealloc_blocks,
1154-
allocfork == XFS_DATA_FORK ? &imap : &cmap,
1155-
allocfork == XFS_DATA_FORK ? &icur : &ccur,
1156-
allocfork == XFS_DATA_FORK ? eof : cow_eof);
1157-
switch (error) {
1158-
case 0:
1159-
break;
1160-
case -ENOSPC:
1161-
case -EDQUOT:
1162-
/* retry without any preallocation */
1163-
trace_xfs_delalloc_enospc(ip, offset, count);
1164-
if (prealloc_blocks) {
1165-
prealloc_blocks = 0;
1166-
goto retry;
1167-
}
1168-
fallthrough;
1169-
default:
1170-
goto out_unlock;
1171-
}
1172-
11731151
if (allocfork == XFS_COW_FORK) {
1152+
error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb,
1153+
end_fsb - offset_fsb, prealloc_blocks, &cmap,
1154+
&ccur, cow_eof);
1155+
if (error)
1156+
goto out_unlock;
1157+
11741158
trace_xfs_iomap_alloc(ip, offset, count, allocfork, &cmap);
11751159
goto found_cow;
11761160
}
11771161

1162+
error = xfs_bmapi_reserve_delalloc(ip, allocfork, offset_fsb,
1163+
end_fsb - offset_fsb, prealloc_blocks, &imap, &icur,
1164+
eof);
1165+
if (error)
1166+
goto out_unlock;
1167+
11781168
/*
11791169
* Flag newly allocated delalloc blocks with IOMAP_F_NEW so we punch
11801170
* them out if the write happens to fail.

0 commit comments

Comments
 (0)