Skip to content

Commit 676a659

Browse files
author
Darrick J. Wong
committed
xfs: retry allocations when locality-based search fails
If a realtime allocation fails because we can't find a sufficiently large free extent satisfying locality rules, relax the locality rules and try again. This reduces the occurrence of short writes to realtime files when the write size is large and the free space is fragmented. This was originally discovered by running generic/186 with the realtime reflink patchset and a 128k cow extent size hint, but the short write symptoms can manifest with a 128k extent size hint and no reflink, so apply the fix now. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Allison Henderson <[email protected]>
1 parent 9d5e849 commit 676a659

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ xfs_bmap_rtalloc(
8484
xfs_extlen_t minlen = mp->m_sb.sb_rextsize;
8585
xfs_extlen_t raminlen;
8686
bool rtlocked = false;
87+
bool ignore_locality = false;
8788
int error;
8889

8990
align = xfs_get_extsz_hint(ap->ip);
@@ -158,7 +159,10 @@ xfs_bmap_rtalloc(
158159
/*
159160
* Realtime allocation, done through xfs_rtallocate_extent.
160161
*/
161-
do_div(ap->blkno, mp->m_sb.sb_rextsize);
162+
if (ignore_locality)
163+
ap->blkno = 0;
164+
else
165+
do_div(ap->blkno, mp->m_sb.sb_rextsize);
162166
rtb = ap->blkno;
163167
ap->length = ralen;
164168
raminlen = max_t(xfs_extlen_t, 1, minlen / mp->m_sb.sb_rextsize);
@@ -197,6 +201,15 @@ xfs_bmap_rtalloc(
197201
goto retry;
198202
}
199203

204+
if (!ignore_locality && ap->blkno != 0) {
205+
/*
206+
* If we can't allocate near a specific rt extent, try again
207+
* without locality criteria.
208+
*/
209+
ignore_locality = true;
210+
goto retry;
211+
}
212+
200213
ap->blkno = NULLFSBLOCK;
201214
ap->length = 0;
202215
return 0;

0 commit comments

Comments
 (0)