Skip to content

Commit a3e48f6

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: cleanup picking the start extent hint in xfs_bmap_rtalloc
Clean up the logical in xfs_bmap_rtalloc that tries to find a rtextent to start the search from by using a separate variable for the hint, not calling xfs_bmap_adjacent when we want to ignore the locality and avoid an extra roundtrip converting between block numbers and RT extent numbers. As a side-effect this doesn't pointlessly call xfs_rtpick_extent and increment the start rtextent hint if we are going to ignore the result anyway. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 676544c commit a3e48f6

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

fs/xfs/xfs_rtalloc.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,8 @@ xfs_bmap_rtalloc(
13981398
{
13991399
struct xfs_mount *mp = ap->ip->i_mount;
14001400
xfs_fileoff_t orig_offset = ap->offset;
1401-
xfs_rtxnum_t rtx;
1401+
xfs_rtxnum_t start; /* allocation hint rtextent no */
1402+
xfs_rtxnum_t rtx; /* actually allocated rtextent no */
14021403
xfs_rtxlen_t prod = 0; /* product factor for allocators */
14031404
xfs_extlen_t mod = 0; /* product factor for allocators */
14041405
xfs_rtxlen_t ralen = 0; /* realtime allocation length */
@@ -1459,30 +1460,24 @@ xfs_bmap_rtalloc(
14591460
rtlocked = true;
14601461
}
14611462

1462-
/*
1463-
* If it's an allocation to an empty file at offset 0,
1464-
* pick an extent that will space things out in the rt area.
1465-
*/
1466-
if (ap->eof && ap->offset == 0) {
1467-
error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
1463+
if (ignore_locality) {
1464+
start = 0;
1465+
} else if (xfs_bmap_adjacent(ap)) {
1466+
start = xfs_rtb_to_rtx(mp, ap->blkno);
1467+
} else if (ap->eof && ap->offset == 0) {
1468+
/*
1469+
* If it's an allocation to an empty file at offset 0, pick an
1470+
* extent that will space things out in the rt area.
1471+
*/
1472+
error = xfs_rtpick_extent(mp, ap->tp, ralen, &start);
14681473
if (error)
14691474
return error;
1470-
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
14711475
} else {
1472-
ap->blkno = 0;
1476+
start = 0;
14731477
}
14741478

1475-
xfs_bmap_adjacent(ap);
1476-
1477-
/*
1478-
* Realtime allocation, done through xfs_rtallocate_extent.
1479-
*/
1480-
if (ignore_locality)
1481-
rtx = 0;
1482-
else
1483-
rtx = xfs_rtb_to_rtx(mp, ap->blkno);
14841479
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
1485-
error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
1480+
error = xfs_rtallocate_extent(ap->tp, start, raminlen, ralen, &ralen,
14861481
ap->wasdel, prod, &rtx);
14871482
if (error == -ENOSPC) {
14881483
if (align > mp->m_sb.sb_rextsize) {
@@ -1499,7 +1494,7 @@ xfs_bmap_rtalloc(
14991494
goto retry;
15001495
}
15011496

1502-
if (!ignore_locality && ap->blkno != 0) {
1497+
if (!ignore_locality && start != 0) {
15031498
/*
15041499
* If we can't allocate near a specific rt extent, try
15051500
* again without locality criteria.

0 commit comments

Comments
 (0)