@@ -3707,12 +3707,30 @@ xfs_alloc_vextent_iterate_ags(
xfs_agnumber_t restart_agno = minimum_agno;
xfs_agnumber_t agno;
int error = 0;
+ xfs_agnumber_t start_af = args->curr_af;
+ xfs_agnumber_t end_af = args->next_af - 1;
+
if (alloc_flags & XFS_ALLOC_FLAG_TRYLOCK)
restart_agno = 0;
restart:
+ /* if start_agno is not in current AF range, make it be. */
+ if ((start_agno < start_af) || (start_agno > end_af))
+ start_agno = start_af;
+
+ /* Only iterate the cross region between current allocation field and
+ * [restart_agno, start_agno].
+ */
+ restart_agno = max(start_af, restart_agno);
+ start_agno = min(end_af, start_agno);
+
+ WARN_ON_ONCE((args->next_af <= 0) || (args->next_af > mp->m_sb.sb_agcount));
+ WARN_ON_ONCE((args->curr_af < 0) || (args->curr_af >= mp->m_sb.sb_agcount));
+ WARN_ON_ONCE(restart_agno > start_agno);
+ WARN_ON_ONCE(restart_agno < start_af);
+ WARN_ON_ONCE(start_agno > end_af);
for_each_perag_wrap_range(mp, start_agno, restart_agno,
- mp->m_sb.sb_agcount, agno, args->pag) {
+ args->next_af, agno, args->pag) {
args->agno = agno;
error = xfs_alloc_vextent_prepare_ag(args, alloc_flags);
if (error)
@@ -3326,6 +3326,8 @@ xfs_bmap_btalloc_select_lengths(
struct xfs_perag *pag;
xfs_agnumber_t agno, startag;
int error = 0;
+ xfs_agnumber_t start_af = args->curr_af;
+ xfs_agnumber_t end_af = args->next_af - 1;
if (ap->tp->t_flags & XFS_TRANS_LOWMODE) {
args->total = ap->minlen;
@@ -3338,8 +3340,14 @@ xfs_bmap_btalloc_select_lengths(
if (startag == NULLAGNUMBER)
startag = 0;
+ /* if startag is not in current AF range, make it be. */
+ if ((startag < start_af) || (startag > end_af))
+ startag = start_af;
+
*blen = 0;
- for_each_perag_wrap(mp, startag, agno, pag) {
+ WARN_ON_ONCE((args->next_af <= 0) || (args->next_af > mp->m_sb.sb_agcount));
+ WARN_ON_ONCE((args->curr_af < 0) || (args->curr_af >= mp->m_sb.sb_agcount));
+ for_each_perag_af_wrap(mp, startag, agno, pag, start_af, args->next_af) {
error = xfs_bmap_longest_free_extent(pag, args->tp, blen);
if (error && error != -EAGAIN)
break;
@@ -3807,7 +3815,8 @@ xfs_bmap_btalloc(
xfs_inode_is_filestream(ap->ip))
error = xfs_bmap_btalloc_filestreams(ap, &args, stripe_align);
else
- error = xfs_bmap_btalloc_best_length(ap, &args, stripe_align);
+ error = xfs_bmap_btalloc_best_length_iterate_afs(ap, &args,
+ stripe_align);
if (error)
return error;