Skip to content

Commit fd26a88

Browse files
djwongdchinner
authored andcommitted
xfs: factor rmap btree size into the indlen calculations
When we're estimating the amount of space it's going to take to satisfy a delalloc reservation, we need to include the space that we might need to grow the rmapbt. This helps us to avoid running out of space later when _iomap_write_allocate needs more space than we reserved. Eryu Guan observed this happening on generic/224 when sunit/swidth were set. Reported-by: Eryu Guan <eguan@redhat.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
1 parent 1247ec4 commit fd26a88

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "xfs_rmap.h"
5050
#include "xfs_ag_resv.h"
5151
#include "xfs_refcount.h"
52+
#include "xfs_rmap_btree.h"
5253

5354

5455
kmem_zone_t *xfs_bmap_free_item_zone;
@@ -190,21 +191,33 @@ xfs_bmap_worst_indlen(
190191
int maxrecs; /* maximum record count at this level */
191192
xfs_mount_t *mp; /* mount structure */
192193
xfs_filblks_t rval; /* return value */
194+
xfs_filblks_t orig_len;
193195

194196
mp = ip->i_mount;
197+
198+
/* Calculate the worst-case size of the bmbt. */
199+
orig_len = len;
195200
maxrecs = mp->m_bmap_dmxr[0];
196201
for (level = 0, rval = 0;
197202
level < XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK);
198203
level++) {
199204
len += maxrecs - 1;
200205
do_div(len, maxrecs);
201206
rval += len;
202-
if (len == 1)
203-
return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
207+
if (len == 1) {
208+
rval += XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
204209
level - 1;
210+
break;
211+
}
205212
if (level == 0)
206213
maxrecs = mp->m_bmap_dmxr[1];
207214
}
215+
216+
/* Calculate the worst-case size of the rmapbt. */
217+
if (xfs_sb_version_hasrmapbt(&mp->m_sb))
218+
rval += 1 + xfs_rmapbt_calc_size(mp, orig_len) +
219+
mp->m_rmap_maxlevels;
220+
208221
return rval;
209222
}
210223

0 commit comments

Comments
 (0)