提交 9fe82b8c 编写于 作者: D Darrick J. Wong

xfs: track delayed allocation reservations across the filesystem

Add a percpu counter to track the number of blocks directly reserved for
delayed allocations on the data device.  This counter (in contrast to
i_delayed_blks) does not track allocated CoW staging extents or anything
going on with the realtime device.  It will be used in the upcoming
summary counter scrub function to check the free block counts without
having to freeze the filesystem or walk all the inodes to find the
delayed allocations.
Signed-off-by: NDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: NDave Chinner <dchinner@redhat.com>
上级 f60be90f
...@@ -2009,6 +2009,9 @@ xfs_bmap_add_extent_delay_real( ...@@ -2009,6 +2009,9 @@ xfs_bmap_add_extent_delay_real(
goto done; goto done;
} }
if (da_new != da_old)
xfs_mod_delalloc(mp, (int64_t)da_new - da_old);
if (bma->cur) { if (bma->cur) {
da_new += bma->cur->bc_private.b.allocated; da_new += bma->cur->bc_private.b.allocated;
bma->cur->bc_private.b.allocated = 0; bma->cur->bc_private.b.allocated = 0;
...@@ -2640,6 +2643,7 @@ xfs_bmap_add_extent_hole_delay( ...@@ -2640,6 +2643,7 @@ xfs_bmap_add_extent_hole_delay(
/* /*
* Nothing to do for disk quota accounting here. * Nothing to do for disk quota accounting here.
*/ */
xfs_mod_delalloc(ip->i_mount, (int64_t)newlen - oldlen);
} }
} }
...@@ -3352,8 +3356,10 @@ xfs_bmap_btalloc_accounting( ...@@ -3352,8 +3356,10 @@ xfs_bmap_btalloc_accounting(
* already have quota reservation and there's nothing to do * already have quota reservation and there's nothing to do
* yet. * yet.
*/ */
if (ap->wasdel) if (ap->wasdel) {
xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len);
return; return;
}
/* /*
* Otherwise, we've allocated blocks in a hole. The transaction * Otherwise, we've allocated blocks in a hole. The transaction
...@@ -3372,8 +3378,10 @@ xfs_bmap_btalloc_accounting( ...@@ -3372,8 +3378,10 @@ xfs_bmap_btalloc_accounting(
/* data/attr fork only */ /* data/attr fork only */
ap->ip->i_d.di_nblocks += args->len; ap->ip->i_d.di_nblocks += args->len;
xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE);
if (ap->wasdel) if (ap->wasdel) {
ap->ip->i_delayed_blks -= args->len; ap->ip->i_delayed_blks -= args->len;
xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len);
}
xfs_trans_mod_dquot_byino(ap->tp, ap->ip, xfs_trans_mod_dquot_byino(ap->tp, ap->ip,
ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT, ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT,
args->len); args->len);
...@@ -3969,6 +3977,7 @@ xfs_bmapi_reserve_delalloc( ...@@ -3969,6 +3977,7 @@ xfs_bmapi_reserve_delalloc(
ip->i_delayed_blks += alen; ip->i_delayed_blks += alen;
xfs_mod_delalloc(ip->i_mount, alen + indlen);
got->br_startoff = aoff; got->br_startoff = aoff;
got->br_startblock = nullstartblock(indlen); got->br_startblock = nullstartblock(indlen);
...@@ -4840,8 +4849,10 @@ xfs_bmap_del_extent_delay( ...@@ -4840,8 +4849,10 @@ xfs_bmap_del_extent_delay(
da_diff = da_old - da_new; da_diff = da_old - da_new;
if (!isrt) if (!isrt)
da_diff += del->br_blockcount; da_diff += del->br_blockcount;
if (da_diff) if (da_diff) {
xfs_mod_fdblocks(mp, da_diff, false); xfs_mod_fdblocks(mp, da_diff, false);
xfs_mod_delalloc(mp, -da_diff);
}
return error; return error;
} }
......
...@@ -1451,3 +1451,24 @@ xfs_force_summary_recalc( ...@@ -1451,3 +1451,24 @@ xfs_force_summary_recalc(
xfs_fs_mark_sick(mp, XFS_SICK_FS_COUNTERS); xfs_fs_mark_sick(mp, XFS_SICK_FS_COUNTERS);
} }
/*
* Update the in-core delayed block counter.
*
* We prefer to update the counter without having to take a spinlock for every
* counter update (i.e. batching). Each change to delayed allocation
* reservations can change can easily exceed the default percpu counter
* batching, so we use a larger batch factor here.
*
* Note that we don't currently have any callers requiring fast summation
* (e.g. percpu_counter_read) so we can use a big batch value here.
*/
#define XFS_DELALLOC_BATCH (4096)
void
xfs_mod_delalloc(
struct xfs_mount *mp,
int64_t delta)
{
percpu_counter_add_batch(&mp->m_delalloc_blks, delta,
XFS_DELALLOC_BATCH);
}
...@@ -81,6 +81,12 @@ typedef struct xfs_mount { ...@@ -81,6 +81,12 @@ typedef struct xfs_mount {
struct percpu_counter m_icount; /* allocated inodes counter */ struct percpu_counter m_icount; /* allocated inodes counter */
struct percpu_counter m_ifree; /* free inodes counter */ struct percpu_counter m_ifree; /* free inodes counter */
struct percpu_counter m_fdblocks; /* free block counter */ struct percpu_counter m_fdblocks; /* free block counter */
/*
* Count of data device blocks reserved for delayed allocations,
* including indlen blocks. Does not include allocated CoW staging
* extents or anything related to the rt device.
*/
struct percpu_counter m_delalloc_blks;
struct xfs_buf *m_sb_bp; /* buffer for superblock */ struct xfs_buf *m_sb_bp; /* buffer for superblock */
char *m_fsname; /* filesystem name */ char *m_fsname; /* filesystem name */
...@@ -475,5 +481,6 @@ int xfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb, ...@@ -475,5 +481,6 @@ int xfs_zero_extent(struct xfs_inode *ip, xfs_fsblock_t start_fsb,
struct xfs_error_cfg * xfs_error_get_cfg(struct xfs_mount *mp, struct xfs_error_cfg * xfs_error_get_cfg(struct xfs_mount *mp,
int error_class, int error); int error_class, int error);
void xfs_force_summary_recalc(struct xfs_mount *mp); void xfs_force_summary_recalc(struct xfs_mount *mp);
void xfs_mod_delalloc(struct xfs_mount *mp, int64_t delta);
#endif /* __XFS_MOUNT_H__ */ #endif /* __XFS_MOUNT_H__ */
...@@ -1538,8 +1538,14 @@ xfs_init_percpu_counters( ...@@ -1538,8 +1538,14 @@ xfs_init_percpu_counters(
if (error) if (error)
goto free_ifree; goto free_ifree;
error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
if (error)
goto free_fdblocks;
return 0; return 0;
free_fdblocks:
percpu_counter_destroy(&mp->m_fdblocks);
free_ifree: free_ifree:
percpu_counter_destroy(&mp->m_ifree); percpu_counter_destroy(&mp->m_ifree);
free_icount: free_icount:
...@@ -1563,6 +1569,9 @@ xfs_destroy_percpu_counters( ...@@ -1563,6 +1569,9 @@ xfs_destroy_percpu_counters(
percpu_counter_destroy(&mp->m_icount); percpu_counter_destroy(&mp->m_icount);
percpu_counter_destroy(&mp->m_ifree); percpu_counter_destroy(&mp->m_ifree);
percpu_counter_destroy(&mp->m_fdblocks); percpu_counter_destroy(&mp->m_fdblocks);
ASSERT(XFS_FORCED_SHUTDOWN(mp) ||
percpu_counter_sum(&mp->m_delalloc_blks) == 0);
percpu_counter_destroy(&mp->m_delalloc_blks);
} }
static struct xfs_mount * static struct xfs_mount *
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册