Skip to content

Commit

Permalink
xfs: don't report reserved bnobt space as available
Browse files Browse the repository at this point in the history
On a modern filesystem, we don't allow userspace to allocate blocks for
data storage from the per-AG space reservations, the user-controlled
reservation pool that prevents ENOSPC in the middle of internal
operations, or the internal per-AG set-aside that prevents unwanted
filesystem shutdowns due to ENOSPC during a bmap btree split.

Since we now consider freespace btree blocks as unavailable for
allocation for data storage, we shouldn't report those blocks via statfs
either.  This makes the numbers that we return via the statfs f_bavail
and f_bfree fields a more conservative estimate of actual free space.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
  • Loading branch information
Darrick J. Wong committed Mar 28, 2022
1 parent 82be38b commit 85bcfa2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fs/xfs/xfs_fsops.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ xfs_fs_counts(
cnt->allocino = percpu_counter_read_positive(&mp->m_icount);
cnt->freeino = percpu_counter_read_positive(&mp->m_ifree);
cnt->freedata = percpu_counter_read_positive(&mp->m_fdblocks) -
mp->m_alloc_set_aside;
xfs_fdblocks_unavailable(mp);

spin_lock(&mp->m_sb_lock);
cnt->freertx = mp->m_sb.sb_frextents;
Expand Down
3 changes: 2 additions & 1 deletion fs/xfs/xfs_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,8 @@ xfs_fs_statfs(
spin_unlock(&mp->m_sb_lock);

/* make sure statp->f_bfree does not underflow */
statp->f_bfree = max_t(int64_t, fdblocks - mp->m_alloc_set_aside, 0);
statp->f_bfree = max_t(int64_t, 0,
fdblocks - xfs_fdblocks_unavailable(mp));
statp->f_bavail = statp->f_bfree;

fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
Expand Down

0 comments on commit 85bcfa2

Please sign in to comment.