@@ -293,63 +293,66 @@ xfs_perag_clear_inode_tag(
293
293
}
294
294
295
295
/*
296
- * Search from @first to find the next perag with the given tag set .
296
+ * Find the next AG after @pag, or the first AG if @pag is NULL .
297
297
*/
298
298
static struct xfs_perag *
299
- xfs_perag_get_tag (
299
+ xfs_perag_get_next_tag (
300
300
struct xfs_mount * mp ,
301
- xfs_agnumber_t first ,
301
+ struct xfs_perag * pag ,
302
302
unsigned int tag )
303
303
{
304
- struct xfs_perag * pag ;
304
+ unsigned long index = 0 ;
305
305
int found ;
306
306
307
+ if (pag ) {
308
+ index = pag -> pag_agno + 1 ;
309
+ xfs_perag_rele (pag );
310
+ }
311
+
307
312
rcu_read_lock ();
308
313
found = radix_tree_gang_lookup_tag (& mp -> m_perag_tree ,
309
- (void * * )& pag , first , 1 , tag );
314
+ (void * * )& pag , index , 1 , tag );
310
315
if (found <= 0 ) {
311
316
rcu_read_unlock ();
312
317
return NULL ;
313
318
}
314
- trace_xfs_perag_get_tag (pag , _RET_IP_ );
319
+ trace_xfs_perag_get_next_tag (pag , _RET_IP_ );
315
320
atomic_inc (& pag -> pag_ref );
316
321
rcu_read_unlock ();
317
322
return pag ;
318
323
}
319
324
320
325
/*
321
- * Search from @first to find the next perag with the given tag set .
326
+ * Find the next AG after @pag, or the first AG if @pag is NULL .
322
327
*/
323
328
static struct xfs_perag *
324
- xfs_perag_grab_tag (
329
+ xfs_perag_grab_next_tag (
325
330
struct xfs_mount * mp ,
326
- xfs_agnumber_t first ,
331
+ struct xfs_perag * pag ,
327
332
int tag )
328
333
{
329
- struct xfs_perag * pag ;
334
+ unsigned long index = 0 ;
330
335
int found ;
331
336
337
+ if (pag ) {
338
+ index = pag -> pag_agno + 1 ;
339
+ xfs_perag_rele (pag );
340
+ }
341
+
332
342
rcu_read_lock ();
333
343
found = radix_tree_gang_lookup_tag (& mp -> m_perag_tree ,
334
- (void * * )& pag , first , 1 , tag );
344
+ (void * * )& pag , index , 1 , tag );
335
345
if (found <= 0 ) {
336
346
rcu_read_unlock ();
337
347
return NULL ;
338
348
}
339
- trace_xfs_perag_grab_tag (pag , _RET_IP_ );
349
+ trace_xfs_perag_grab_next_tag (pag , _RET_IP_ );
340
350
if (!atomic_inc_not_zero (& pag -> pag_active_ref ))
341
351
pag = NULL ;
342
352
rcu_read_unlock ();
343
353
return pag ;
344
354
}
345
355
346
- #define for_each_perag_tag (mp , agno , pag , tag ) \
347
- for ((agno) = 0, (pag) = xfs_perag_grab_tag((mp), 0, (tag)); \
348
- (pag) != NULL; \
349
- (agno) = (pag)->pag_agno + 1, \
350
- xfs_perag_rele(pag), \
351
- (pag) = xfs_perag_grab_tag((mp), (agno), (tag)))
352
-
353
356
/*
354
357
* When we recycle a reclaimable inode, we need to re-initialise the VFS inode
355
358
* part of the structure. This is made more complex by the fact we store
@@ -1077,15 +1080,11 @@ long
1077
1080
xfs_reclaim_inodes_count (
1078
1081
struct xfs_mount * mp )
1079
1082
{
1080
- struct xfs_perag * pag ;
1081
- xfs_agnumber_t ag = 0 ;
1083
+ struct xfs_perag * pag = NULL ;
1082
1084
long reclaimable = 0 ;
1083
1085
1084
- while ((pag = xfs_perag_get_tag (mp , ag , XFS_ICI_RECLAIM_TAG ))) {
1085
- ag = pag -> pag_agno + 1 ;
1086
+ while ((pag = xfs_perag_get_next_tag (mp , pag , XFS_ICI_RECLAIM_TAG )))
1086
1087
reclaimable += pag -> pag_ici_reclaimable ;
1087
- xfs_perag_put (pag );
1088
- }
1089
1088
return reclaimable ;
1090
1089
}
1091
1090
@@ -1427,14 +1426,13 @@ void
1427
1426
xfs_blockgc_start (
1428
1427
struct xfs_mount * mp )
1429
1428
{
1430
- struct xfs_perag * pag ;
1431
- xfs_agnumber_t agno ;
1429
+ struct xfs_perag * pag = NULL ;
1432
1430
1433
1431
if (xfs_set_blockgc_enabled (mp ))
1434
1432
return ;
1435
1433
1436
1434
trace_xfs_blockgc_start (mp , __return_address );
1437
- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1435
+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
1438
1436
xfs_blockgc_queue (pag );
1439
1437
}
1440
1438
@@ -1550,21 +1548,19 @@ int
1550
1548
xfs_blockgc_flush_all (
1551
1549
struct xfs_mount * mp )
1552
1550
{
1553
- struct xfs_perag * pag ;
1554
- xfs_agnumber_t agno ;
1551
+ struct xfs_perag * pag = NULL ;
1555
1552
1556
1553
trace_xfs_blockgc_flush_all (mp , __return_address );
1557
1554
1558
1555
/*
1559
- * For each blockgc worker, move its queue time up to now. If it
1560
- * wasn't queued, it will not be requeued. Then flush whatever's
1561
- * left.
1556
+ * For each blockgc worker, move its queue time up to now. If it wasn't
1557
+ * queued, it will not be requeued. Then flush whatever is left.
1562
1558
*/
1563
- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1559
+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
1564
1560
mod_delayed_work (pag -> pag_mount -> m_blockgc_wq ,
1565
1561
& pag -> pag_blockgc_work , 0 );
1566
1562
1567
- for_each_perag_tag ( mp , agno , pag , XFS_ICI_BLOCKGC_TAG )
1563
+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , XFS_ICI_BLOCKGC_TAG )) )
1568
1564
flush_delayed_work (& pag -> pag_blockgc_work );
1569
1565
1570
1566
return xfs_inodegc_flush (mp );
@@ -1810,12 +1806,11 @@ xfs_icwalk(
1810
1806
enum xfs_icwalk_goal goal ,
1811
1807
struct xfs_icwalk * icw )
1812
1808
{
1813
- struct xfs_perag * pag ;
1809
+ struct xfs_perag * pag = NULL ;
1814
1810
int error = 0 ;
1815
1811
int last_error = 0 ;
1816
- xfs_agnumber_t agno ;
1817
1812
1818
- for_each_perag_tag ( mp , agno , pag , goal ) {
1813
+ while (( pag = xfs_perag_grab_next_tag ( mp , pag , goal )) ) {
1819
1814
error = xfs_icwalk_ag (pag , goal , icw );
1820
1815
if (error ) {
1821
1816
last_error = error ;
0 commit comments