Skip to content

Commit 712bae9

Browse files
author
Christoph Hellwig
committed
xfs: generalize the freespace and reserved blocks handling
xfs_{add,dec}_freecounter already handles the block and RT extent percpu counters, but it currently hardcodes the passed in counter. Add a freecounter abstraction that uses an enum to designate the counter and add wrappers that hide the actual percpu_counters. This will allow expanding the reserved block handling to the RT extent counter in the next step, and also prepares for adding yet another such counter that can share the code. Both these additions will be needed for the zoned allocator. Also switch the flooring of the frextents counter to 0 in statfs for the rthinherit case to a manual min_t call to match the handling of the fdblocks counter for normal file systems. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
1 parent cc3d2f5 commit 712bae9

File tree

16 files changed

+151
-73
lines changed

16 files changed

+151
-73
lines changed

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ xfs_dialloc(
19271927
* that we can immediately allocate, but then we allow allocation on the
19281928
* second pass if we fail to find an AG with free inodes in it.
19291929
*/
1930-
if (percpu_counter_read_positive(&mp->m_fdblocks) <
1930+
if (xfs_estimate_freecounter(mp, XC_FREE_BLOCKS) <
19311931
mp->m_low_space[XFS_LOWSP_1_PCNT]) {
19321932
ok_alloc = false;
19331933
low_space = true;

fs/xfs/libxfs/xfs_metafile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ xfs_metafile_resv_can_cover(
9595
* There aren't enough blocks left in the inode's reservation, but it
9696
* isn't critical unless there also isn't enough free space.
9797
*/
98-
return __percpu_counter_compare(&ip->i_mount->m_fdblocks,
98+
return xfs_compare_freecounter(ip->i_mount, XC_FREE_BLOCKS,
9999
rhs - ip->i_delayed_blks, 2048) >= 0;
100100
}
101101

fs/xfs/libxfs/xfs_sb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,7 @@ xfs_log_sb(
12651265
mp->m_sb.sb_ifree = min_t(uint64_t,
12661266
percpu_counter_sum_positive(&mp->m_ifree),
12671267
mp->m_sb.sb_icount);
1268-
mp->m_sb.sb_fdblocks =
1269-
percpu_counter_sum_positive(&mp->m_fdblocks);
1268+
mp->m_sb.sb_fdblocks = xfs_sum_freecounter(mp, XC_FREE_BLOCKS);
12701269
}
12711270

12721271
/*
@@ -1275,9 +1274,10 @@ xfs_log_sb(
12751274
* we handle nearly-lockless reservations, so we must use the _positive
12761275
* variant here to avoid writing out nonsense frextents.
12771276
*/
1278-
if (xfs_has_rtgroups(mp))
1277+
if (xfs_has_rtgroups(mp)) {
12791278
mp->m_sb.sb_frextents =
1280-
percpu_counter_sum_positive(&mp->m_frextents);
1279+
xfs_sum_freecounter(mp, XC_FREE_RTEXTENTS);
1280+
}
12811281

12821282
xfs_sb_to_disk(bp->b_addr, &mp->m_sb);
12831283
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_SB_BUF);

fs/xfs/libxfs/xfs_types.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,23 @@ enum xfs_group_type {
233233
{ XG_TYPE_AG, "ag" }, \
234234
{ XG_TYPE_RTG, "rtg" }
235235

236+
enum xfs_free_counter {
237+
/*
238+
* Number of free blocks on the data device.
239+
*/
240+
XC_FREE_BLOCKS,
241+
242+
/*
243+
* Number of free RT extents on the RT device.
244+
*/
245+
XC_FREE_RTEXTENTS,
246+
XC_FREE_NR,
247+
};
248+
249+
#define XFS_FREECOUNTER_STR \
250+
{ XC_FREE_BLOCKS, "blocks" }, \
251+
{ XC_FREE_RTEXTENTS, "rtextents" }
252+
236253
/*
237254
* Type verifier functions
238255
*/

fs/xfs/scrub/fscounters.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ xchk_fscounters(
513513
/* Snapshot the percpu counters. */
514514
icount = percpu_counter_sum(&mp->m_icount);
515515
ifree = percpu_counter_sum(&mp->m_ifree);
516-
fdblocks = percpu_counter_sum(&mp->m_fdblocks);
517-
frextents = percpu_counter_sum(&mp->m_frextents);
516+
fdblocks = xfs_sum_freecounter_raw(mp, XC_FREE_BLOCKS);
517+
frextents = xfs_sum_freecounter_raw(mp, XC_FREE_RTEXTENTS);
518518

519519
/* No negative values, please! */
520520
if (icount < 0 || ifree < 0)
@@ -589,15 +589,16 @@ xchk_fscounters(
589589
try_again = true;
590590
}
591591

592-
if (!xchk_fscount_within_range(sc, fdblocks, &mp->m_fdblocks,
593-
fsc->fdblocks)) {
592+
if (!xchk_fscount_within_range(sc, fdblocks,
593+
&mp->m_free[XC_FREE_BLOCKS].count, fsc->fdblocks)) {
594594
if (fsc->frozen)
595595
xchk_set_corrupt(sc);
596596
else
597597
try_again = true;
598598
}
599599

600-
if (!xchk_fscount_within_range(sc, frextents, &mp->m_frextents,
600+
if (!xchk_fscount_within_range(sc, frextents,
601+
&mp->m_free[XC_FREE_RTEXTENTS].count,
601602
fsc->frextents - fsc->frextents_delayed)) {
602603
if (fsc->frozen)
603604
xchk_set_corrupt(sc);

fs/xfs/scrub/fscounters_repair.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ xrep_fscounters(
6464

6565
percpu_counter_set(&mp->m_icount, fsc->icount);
6666
percpu_counter_set(&mp->m_ifree, fsc->ifree);
67-
percpu_counter_set(&mp->m_fdblocks, fsc->fdblocks);
67+
xfs_set_freecounter(mp, XC_FREE_BLOCKS, fsc->fdblocks);
6868

6969
/*
7070
* Online repair is only supported on v5 file systems, which require
@@ -74,7 +74,7 @@ xrep_fscounters(
7474
* track of the delalloc reservations separately, as they are are
7575
* subtracted from m_frextents, but not included in sb_frextents.
7676
*/
77-
percpu_counter_set(&mp->m_frextents,
77+
xfs_set_freecounter(mp, XC_FREE_RTEXTENTS,
7878
fsc->frextents - fsc->frextents_delayed);
7979
if (!xfs_has_rtgroups(mp))
8080
mp->m_sb.sb_frextents = fsc->frextents;

fs/xfs/scrub/newbt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ xrep_newbt_estimate_slack(
6262
free = sc->sa.pag->pagf_freeblks;
6363
sz = xfs_ag_block_count(sc->mp, pag_agno(sc->sa.pag));
6464
} else {
65-
free = percpu_counter_sum(&sc->mp->m_fdblocks);
65+
free = xfs_sum_freecounter_raw(sc->mp, XC_FREE_BLOCKS);
6666
sz = sc->mp->m_sb.sb_dblocks;
6767
}
6868

fs/xfs/xfs_fsops.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ xfs_reserve_blocks(
409409

410410
/*
411411
* If the request is larger than the current reservation, reserve the
412-
* blocks before we update the reserve counters. Sample m_fdblocks and
412+
* blocks before we update the reserve counters. Sample m_free and
413413
* perform a partial reservation if the request exceeds free space.
414414
*
415415
* The code below estimates how many blocks it can request from
@@ -419,8 +419,8 @@ xfs_reserve_blocks(
419419
* space to fill it because mod_fdblocks will refill an undersized
420420
* reserve when it can.
421421
*/
422-
free = percpu_counter_sum(&mp->m_fdblocks) -
423-
xfs_fdblocks_unavailable(mp);
422+
free = xfs_sum_freecounter_raw(mp, XC_FREE_BLOCKS) -
423+
xfs_freecounter_unavailable(mp, XC_FREE_BLOCKS);
424424
delta = request - mp->m_resblks;
425425
mp->m_resblks = request;
426426
if (delta > 0 && free > 0) {

fs/xfs/xfs_icache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ xfs_inodegc_want_queue_rt_file(
20762076
if (!XFS_IS_REALTIME_INODE(ip))
20772077
return false;
20782078

2079-
if (__percpu_counter_compare(&mp->m_frextents,
2079+
if (xfs_compare_freecounter(mp, XC_FREE_RTEXTENTS,
20802080
mp->m_low_rtexts[XFS_LOWSP_5_PCNT],
20812081
XFS_FDBLOCKS_BATCH) < 0)
20822082
return true;
@@ -2104,7 +2104,7 @@ xfs_inodegc_want_queue_work(
21042104
if (items > mp->m_ino_geo.inodes_per_cluster)
21052105
return true;
21062106

2107-
if (__percpu_counter_compare(&mp->m_fdblocks,
2107+
if (xfs_compare_freecounter(mp, XC_FREE_BLOCKS,
21082108
mp->m_low_space[XFS_LOWSP_5_PCNT],
21092109
XFS_FDBLOCKS_BATCH) < 0)
21102110
return true;

fs/xfs/xfs_ioctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,9 @@ xfs_ioctl_fs_counts(
11551155
struct xfs_fsop_counts out = {
11561156
.allocino = percpu_counter_read_positive(&mp->m_icount),
11571157
.freeino = percpu_counter_read_positive(&mp->m_ifree),
1158-
.freedata = percpu_counter_read_positive(&mp->m_fdblocks) -
1159-
xfs_fdblocks_unavailable(mp),
1160-
.freertx = percpu_counter_read_positive(&mp->m_frextents),
1158+
.freedata = xfs_estimate_freecounter(mp, XC_FREE_BLOCKS) -
1159+
xfs_freecounter_unavailable(mp, XC_FREE_BLOCKS),
1160+
.freertx = xfs_estimate_freecounter(mp, XC_FREE_RTEXTENTS),
11611161
};
11621162

11631163
if (copy_to_user(uarg, &out, sizeof(out)))

0 commit comments

Comments
 (0)