Skip to content

Commit 74c36a8

Browse files
author
Dave Chinner
committed
xfs: use xfs_alloc_vextent_this_ag() where appropriate
Change obvious callers of single AG allocation to use xfs_alloc_vextent_this_ag(). Drive the per-ag grabbing out to the callers, too, so that callers with active references don't need to do new lookups just for an allocation in a context that already has a perag reference. The only remaining caller that does single AG allocation through xfs_alloc_vextent() is xfs_bmap_btalloc() with XFS_ALLOCTYPE_NEAR_BNO. That is going to need more untangling before it can be converted cleanly. Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
1 parent 4811c93 commit 74c36a8

File tree

9 files changed

+74
-53
lines changed

9 files changed

+74
-53
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ xfs_ag_shrink_space(
887887
struct xfs_alloc_arg args = {
888888
.tp = *tpp,
889889
.mp = mp,
890+
.pag = pag,
890891
.type = XFS_ALLOCTYPE_THIS_BNO,
891892
.minlen = delta,
892893
.maxlen = delta,
@@ -938,7 +939,7 @@ xfs_ag_shrink_space(
938939
return error;
939940

940941
/* internal log shouldn't also show up in the free space btrees */
941-
error = xfs_alloc_vextent(&args);
942+
error = xfs_alloc_vextent_this_ag(&args);
942943
if (!error && args.agbno == NULLAGBLOCK)
943944
error = -ENOSPC;
944945

fs/xfs/libxfs/xfs_alloc.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,6 @@ xfs_alloc_fix_freelist(
27232723
targs.agbp = agbp;
27242724
targs.agno = args->agno;
27252725
targs.alignment = targs.minlen = targs.prod = 1;
2726-
targs.type = XFS_ALLOCTYPE_THIS_AG;
27272726
targs.pag = pag;
27282727
error = xfs_alloc_read_agfl(pag, tp, &agflbp);
27292728
if (error)
@@ -3271,14 +3270,17 @@ xfs_alloc_vextent_set_fsbno(
32713270
/*
32723271
* Allocate within a single AG only.
32733272
*/
3274-
static int
3273+
int
32753274
xfs_alloc_vextent_this_ag(
3276-
struct xfs_alloc_arg *args,
3277-
xfs_agnumber_t minimum_agno)
3275+
struct xfs_alloc_arg *args)
32783276
{
32793277
struct xfs_mount *mp = args->mp;
3278+
xfs_agnumber_t minimum_agno = 0;
32803279
int error;
32813280

3281+
if (args->tp->t_highest_agno != NULLAGNUMBER)
3282+
minimum_agno = args->tp->t_highest_agno;
3283+
32823284
error = xfs_alloc_vextent_check_args(args);
32833285
if (error) {
32843286
if (error == -ENOSPC)
@@ -3293,11 +3295,8 @@ xfs_alloc_vextent_this_ag(
32933295
return 0;
32943296
}
32953297

3296-
args->pag = xfs_perag_get(mp, args->agno);
32973298
error = xfs_alloc_ag_vextent(args);
3298-
32993299
xfs_alloc_vextent_set_fsbno(args, minimum_agno);
3300-
xfs_perag_put(args->pag);
33013300
return error;
33023301
}
33033302

@@ -3480,6 +3479,7 @@ xfs_alloc_vextent(
34803479
struct xfs_alloc_arg *args)
34813480
{
34823481
xfs_agnumber_t minimum_agno = 0;
3482+
int error;
34833483

34843484
if (args->tp->t_highest_agno != NULLAGNUMBER)
34853485
minimum_agno = args->tp->t_highest_agno;
@@ -3488,17 +3488,21 @@ xfs_alloc_vextent(
34883488
case XFS_ALLOCTYPE_THIS_AG:
34893489
case XFS_ALLOCTYPE_NEAR_BNO:
34903490
case XFS_ALLOCTYPE_THIS_BNO:
3491-
return xfs_alloc_vextent_this_ag(args, minimum_agno);
3491+
args->pag = xfs_perag_get(args->mp,
3492+
XFS_FSB_TO_AGNO(args->mp, args->fsbno));
3493+
error = xfs_alloc_vextent_this_ag(args);
3494+
xfs_perag_put(args->pag);
3495+
break;
34923496
case XFS_ALLOCTYPE_START_BNO:
34933497
return xfs_alloc_vextent_start_ag(args, minimum_agno);
34943498
case XFS_ALLOCTYPE_FIRST_AG:
34953499
return xfs_alloc_vextent_first_ag(args, minimum_agno);
34963500
default:
3501+
error = -EFSCORRUPTED;
34973502
ASSERT(0);
3498-
/* NOTREACHED */
3503+
break;
34993504
}
3500-
/* Should never get here */
3501-
return -EFSCORRUPTED;
3505+
return error;
35023506
}
35033507

35043508
/* Ensure that the freelist is at full capacity. */

fs/xfs/libxfs/xfs_alloc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ int /* error */
124124
xfs_alloc_vextent(
125125
xfs_alloc_arg_t *args); /* allocation argument structure */
126126

127+
/*
128+
* Allocate an extent in the specific AG defined by args->fsbno. If there is no
129+
* space in that AG, then the allocation will fail.
130+
*/
131+
int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args);
132+
127133
/*
128134
* Free an extent.
129135
*/

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,8 @@ xfs_bmap_local_to_extents(
789789
memset(&args, 0, sizeof(args));
790790
args.tp = tp;
791791
args.mp = ip->i_mount;
792+
args.total = total;
793+
args.minlen = args.maxlen = args.prod = 1;
792794
xfs_rmap_ino_owner(&args.oinfo, ip->i_ino, whichfork, 0);
793795
/*
794796
* Allocate a block. We know we need only one, since the
@@ -3506,8 +3508,7 @@ xfs_bmap_btalloc(
35063508
xfs_extlen_t orig_length;
35073509
xfs_extlen_t blen;
35083510
xfs_extlen_t nextminlen = 0;
3509-
int isaligned;
3510-
int tryagain;
3511+
int isaligned = 0;
35113512
int error;
35123513
int stripe_align;
35133514

@@ -3528,7 +3529,6 @@ xfs_bmap_btalloc(
35283529

35293530
xfs_bmap_adjacent(ap);
35303531

3531-
tryagain = isaligned = 0;
35323532
args.fsbno = ap->blkno;
35333533
args.oinfo = XFS_RMAP_OINFO_SKIP_UPDATE;
35343534

@@ -3576,9 +3576,9 @@ xfs_bmap_btalloc(
35763576
* allocation with alignment turned on.
35773577
*/
35783578
atype = args.type;
3579-
tryagain = 1;
35803579
args.type = XFS_ALLOCTYPE_THIS_BNO;
35813580
args.alignment = 1;
3581+
35823582
/*
35833583
* Compute the minlen+alignment for the
35843584
* next case. Set slop so that the value
@@ -3595,34 +3595,37 @@ xfs_bmap_btalloc(
35953595
args.minlen - 1;
35963596
else
35973597
args.minalignslop = 0;
3598+
3599+
args.pag = xfs_perag_get(mp,
3600+
XFS_FSB_TO_AGNO(mp, args.fsbno));
3601+
error = xfs_alloc_vextent_this_ag(&args);
3602+
xfs_perag_put(args.pag);
3603+
if (error)
3604+
return error;
3605+
3606+
if (args.fsbno != NULLFSBLOCK)
3607+
goto out_success;
3608+
/*
3609+
* Exact allocation failed. Now try with alignment
3610+
* turned on.
3611+
*/
3612+
args.pag = NULL;
3613+
args.type = atype;
3614+
args.fsbno = ap->blkno;
3615+
args.alignment = stripe_align;
3616+
args.minlen = nextminlen;
3617+
args.minalignslop = 0;
3618+
isaligned = 1;
35983619
}
35993620
} else {
36003621
args.alignment = 1;
36013622
args.minalignslop = 0;
36023623
}
3603-
args.minleft = ap->minleft;
3604-
args.wasdel = ap->wasdel;
3605-
args.resv = XFS_AG_RESV_NONE;
3606-
args.datatype = ap->datatype;
36073624

36083625
error = xfs_alloc_vextent(&args);
36093626
if (error)
36103627
return error;
36113628

3612-
if (tryagain && args.fsbno == NULLFSBLOCK) {
3613-
/*
3614-
* Exact allocation failed. Now try with alignment
3615-
* turned on.
3616-
*/
3617-
args.type = atype;
3618-
args.fsbno = ap->blkno;
3619-
args.alignment = stripe_align;
3620-
args.minlen = nextminlen;
3621-
args.minalignslop = 0;
3622-
isaligned = 1;
3623-
if ((error = xfs_alloc_vextent(&args)))
3624-
return error;
3625-
}
36263629
if (isaligned && args.fsbno == NULLFSBLOCK) {
36273630
/*
36283631
* allocation failed, so turn off alignment and
@@ -3650,8 +3653,13 @@ xfs_bmap_btalloc(
36503653
return error;
36513654
ap->tp->t_flags |= XFS_TRANS_LOWMODE;
36523655
}
3656+
args.minleft = ap->minleft;
3657+
args.wasdel = ap->wasdel;
3658+
args.resv = XFS_AG_RESV_NONE;
3659+
args.datatype = ap->datatype;
36533660

36543661
if (args.fsbno != NULLFSBLOCK) {
3662+
out_success:
36553663
xfs_bmap_process_allocated_extent(ap, &args, orig_offset,
36563664
orig_length);
36573665
} else {

fs/xfs/libxfs/xfs_bmap_btree.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "xfs_quota.h"
2222
#include "xfs_trace.h"
2323
#include "xfs_rmap.h"
24+
#include "xfs_ag.h"
2425

2526
static struct kmem_cache *xfs_bmbt_cur_cache;
2627

@@ -200,14 +201,18 @@ xfs_bmbt_alloc_block(
200201
union xfs_btree_ptr *new,
201202
int *stat)
202203
{
203-
xfs_alloc_arg_t args; /* block allocation args */
204-
int error; /* error return value */
204+
struct xfs_alloc_arg args;
205+
int error;
205206

206207
memset(&args, 0, sizeof(args));
207208
args.tp = cur->bc_tp;
208209
args.mp = cur->bc_mp;
209210
xfs_rmap_ino_bmbt_owner(&args.oinfo, cur->bc_ino.ip->i_ino,
210211
cur->bc_ino.whichfork);
212+
args.minlen = args.maxlen = args.prod = 1;
213+
args.wasdel = cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL;
214+
if (!args.wasdel && args.tp->t_blk_res == 0)
215+
return -ENOSPC;
211216

212217
args.fsbno = be64_to_cpu(start->l);
213218
args.type = XFS_ALLOCTYPE_START_BNO;
@@ -222,15 +227,9 @@ xfs_bmbt_alloc_block(
222227
args.minleft = xfs_bmapi_minleft(cur->bc_tp, cur->bc_ino.ip,
223228
cur->bc_ino.whichfork);
224229

225-
args.minlen = args.maxlen = args.prod = 1;
226-
args.wasdel = cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL;
227-
if (!args.wasdel && args.tp->t_blk_res == 0) {
228-
error = -ENOSPC;
229-
goto error0;
230-
}
231230
error = xfs_alloc_vextent(&args);
232231
if (error)
233-
goto error0;
232+
return error;
234233

235234
if (args.fsbno == NULLFSBLOCK && args.minleft) {
236235
/*
@@ -243,7 +242,7 @@ xfs_bmbt_alloc_block(
243242
args.type = XFS_ALLOCTYPE_START_BNO;
244243
error = xfs_alloc_vextent(&args);
245244
if (error)
246-
goto error0;
245+
return error;
247246
cur->bc_tp->t_flags |= XFS_TRANS_LOWMODE;
248247
}
249248
if (WARN_ON_ONCE(args.fsbno == NULLFSBLOCK)) {
@@ -262,9 +261,6 @@ xfs_bmbt_alloc_block(
262261

263262
*stat = 1;
264263
return 0;
265-
266-
error0:
267-
return error;
268264
}
269265

270266
STATIC int

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ xfs_ialloc_ag_alloc(
630630
args.mp = tp->t_mountp;
631631
args.fsbno = NULLFSBLOCK;
632632
args.oinfo = XFS_RMAP_OINFO_INODES;
633+
args.pag = pag;
633634

634635
#ifdef DEBUG
635636
/* randomly do sparse inode allocations */
@@ -683,7 +684,8 @@ xfs_ialloc_ag_alloc(
683684

684685
/* Allow space for the inode btree to split. */
685686
args.minleft = igeo->inobt_maxlevels;
686-
if ((error = xfs_alloc_vextent(&args)))
687+
error = xfs_alloc_vextent_this_ag(&args);
688+
if (error)
687689
return error;
688690

689691
/*
@@ -731,7 +733,8 @@ xfs_ialloc_ag_alloc(
731733
* Allow space for the inode btree to split.
732734
*/
733735
args.minleft = igeo->inobt_maxlevels;
734-
if ((error = xfs_alloc_vextent(&args)))
736+
error = xfs_alloc_vextent_this_ag(&args);
737+
if (error)
735738
return error;
736739
}
737740

@@ -780,7 +783,7 @@ xfs_ialloc_ag_alloc(
780783
args.mp->m_sb.sb_inoalignmt) -
781784
igeo->ialloc_blks;
782785

783-
error = xfs_alloc_vextent(&args);
786+
error = xfs_alloc_vextent_this_ag(&args);
784787
if (error)
785788
return error;
786789

fs/xfs/libxfs/xfs_ialloc_btree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ __xfs_inobt_alloc_block(
103103
memset(&args, 0, sizeof(args));
104104
args.tp = cur->bc_tp;
105105
args.mp = cur->bc_mp;
106+
args.pag = cur->bc_ag.pag;
106107
args.oinfo = XFS_RMAP_OINFO_INOBT;
107108
args.fsbno = XFS_AGB_TO_FSB(args.mp, cur->bc_ag.pag->pag_agno, sbno);
108109
args.minlen = 1;
@@ -111,7 +112,7 @@ __xfs_inobt_alloc_block(
111112
args.type = XFS_ALLOCTYPE_NEAR_BNO;
112113
args.resv = resv;
113114

114-
error = xfs_alloc_vextent(&args);
115+
error = xfs_alloc_vextent_this_ag(&args);
115116
if (error)
116117
return error;
117118

fs/xfs/libxfs/xfs_refcount_btree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,15 @@ xfs_refcountbt_alloc_block(
6767
memset(&args, 0, sizeof(args));
6868
args.tp = cur->bc_tp;
6969
args.mp = cur->bc_mp;
70+
args.pag = cur->bc_ag.pag;
7071
args.type = XFS_ALLOCTYPE_NEAR_BNO;
7172
args.fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_ag.pag->pag_agno,
7273
xfs_refc_block(args.mp));
7374
args.oinfo = XFS_RMAP_OINFO_REFC;
7475
args.minlen = args.maxlen = args.prod = 1;
7576
args.resv = XFS_AG_RESV_METADATA;
7677

77-
error = xfs_alloc_vextent(&args);
78+
error = xfs_alloc_vextent_this_ag(&args);
7879
if (error)
7980
goto out_error;
8081
trace_xfs_refcountbt_alloc_block(cur->bc_mp, cur->bc_ag.pag->pag_agno,

fs/xfs/scrub/repair.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ xrep_alloc_ag_block(
326326

327327
args.tp = sc->tp;
328328
args.mp = sc->mp;
329+
args.pag = sc->sa.pag;
329330
args.oinfo = *oinfo;
330331
args.fsbno = XFS_AGB_TO_FSB(args.mp, sc->sa.pag->pag_agno, 0);
331332
args.minlen = 1;
@@ -334,7 +335,7 @@ xrep_alloc_ag_block(
334335
args.type = XFS_ALLOCTYPE_THIS_AG;
335336
args.resv = resv;
336337

337-
error = xfs_alloc_vextent(&args);
338+
error = xfs_alloc_vextent_this_ag(&args);
338339
if (error)
339340
return error;
340341
if (args.fsbno == NULLFSBLOCK)

0 commit comments

Comments
 (0)