Skip to content

Commit 885fc2b

Browse files
biger410Brian Maly
authored andcommitted
xfs: decide if inode needs inactivation
Add a predicate function to decide if an inode needs (deferred) inactivation. Any file that has been unlinked or has speculative preallocations either for post-EOF writes or for CoW qualifies. This function will also be used by the upcoming deferred inactivation patch. Signed-off-by: Darrick J. Wong <[email protected]> (cherry picked from commit f20a128f44b5eff13afa9f87d76e6310d3607d92) cherry-pick-repo=kernel/git/djwong/xfs-linux.git Orabug: 30944736 Signed-off-by: Junxiao Bi <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 65a3cac commit 885fc2b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

fs/xfs/xfs_inode.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,60 @@ xfs_inactive_ifree(
17891789
return 0;
17901790
}
17911791

1792+
/*
1793+
* Returns true if we need to update the on-disk metadata before we can free
1794+
* the memory used by this inode. Updates include freeing post-eof
1795+
* preallocations; and marking the inode free in the inobt if it is
1796+
* on the unlinked list.
1797+
*/
1798+
bool
1799+
xfs_inode_needs_inactivation(
1800+
struct xfs_inode *ip)
1801+
{
1802+
struct xfs_mount *mp = ip->i_mount;
1803+
1804+
/*
1805+
* If the inode is already free, then there can be nothing
1806+
* to clean up here.
1807+
*/
1808+
if (VFS_I(ip)->i_mode == 0)
1809+
return false;
1810+
1811+
/* If this is a read-only mount, don't do this (would generate I/O) */
1812+
if (mp->m_flags & XFS_MOUNT_RDONLY)
1813+
return false;
1814+
1815+
if (VFS_I(ip)->i_nlink != 0) {
1816+
int error;
1817+
bool has;
1818+
1819+
/*
1820+
* force is true because we are evicting an inode from the
1821+
* cache. Post-eof blocks must be freed, lest we end up with
1822+
* broken free space accounting.
1823+
*
1824+
* Note: don't bother with iolock here since lockdep complains
1825+
* about acquiring it in reclaim context. We have the only
1826+
* reference to the inode at this point anyways.
1827+
*
1828+
* If the predicate errors out, send the inode through
1829+
* inactivation anyway, because that's what we did before.
1830+
* The inactivation worker will ignore an inode that doesn't
1831+
* actually need it.
1832+
*/
1833+
if (!xfs_can_free_eofblocks(ip, true))
1834+
return false;
1835+
error = xfs_has_eofblocks(ip, &has);
1836+
return error != 0 || has;
1837+
}
1838+
1839+
/*
1840+
* Link count dropped to zero, which means we have to mark the inode
1841+
* free on disk and remove it from the AGI unlinked list.
1842+
*/
1843+
return true;
1844+
}
1845+
17921846
/*
17931847
* xfs_inactive
17941848
*

fs/xfs/xfs_inode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ int xfs_zero_eof(struct xfs_inode *ip, xfs_off_t offset,
405405
xfs_fsize_t isize, bool *did_zeroing);
406406
int xfs_iozero(struct xfs_inode *ip, loff_t pos, size_t count);
407407
int xfs_has_eofblocks(struct xfs_inode *ip, bool *has);
408+
bool xfs_inode_needs_inactivation(struct xfs_inode *ip);
408409

409410

410411
/* from xfs_iops.c */

0 commit comments

Comments
 (0)