Skip to content

Commit 7c03b12

Browse files
Darrick J. Wonggregkh
authored andcommitted
xfs: use dontcache for grabbing inodes during scrub
commit b27ce0d upstream. [backport: resolve conflict due to missing iscan.c] Back when I wrote commit a03297a, I had thought that we'd be doing users a favor by only marking inodes dontcache at the end of a scrub operation, and only if there's only one reference to that inode. This was more or less true back when I_DONTCACHE was an XFS iflag and the only thing it did was change the outcome of xfs_fs_drop_inode to 1. Note: If there are dentries pointing to the inode when scrub finishes, the inode will have positive i_count and stay around in cache until dentry reclaim. But now we have d_mark_dontcache, which cause the inode *and* the dentries attached to it all to be marked I_DONTCACHE, which means that we drop the dentries ASAP, which drops the inode ASAP. This is bad if scrub found problems with the inode, because now they can be scheduled for inactivation, which can cause inodegc to trip on it and shut down the filesystem. Even if the inode isn't bad, this is still suboptimal because phases 3-7 each initiate inode scans. Dropping the inode immediately during phase 3 is silly because phase 5 will reload it and drop it immediately, etc. It's fine to mark the inodes dontcache, but if there have been accesses to the file that set up dentries, we should keep them. I validated this by setting up ftrace to capture xfs_iget_recycle* tracepoints and ran xfs/285 for 30 seconds. With current djwong-wtf I saw ~30,000 recycle events. I then dropped the d_mark_dontcache calls and set XFS_IGET_DONTCACHE, and the recycle events dropped to ~5,000 per 30 seconds. Therefore, grab the inode with XFS_IGET_DONTCACHE, which only has the effect of setting I_DONTCACHE for cache misses. Remove the d_mark_dontcache call that can happen in xchk_irele. Fixes: a03297a ("xfs: manage inode DONTCACHE status at irele time") Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Catherine Hoang <catherine.hoang@oracle.com> Acked-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 20adb1e commit 7c03b12

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

fs/xfs/scrub/common.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ xchk_iget(
735735
{
736736
ASSERT(sc->tp != NULL);
737737

738-
return xfs_iget(sc->mp, sc->tp, inum, XFS_IGET_UNTRUSTED, 0, ipp);
738+
return xfs_iget(sc->mp, sc->tp, inum, XCHK_IGET_FLAGS, 0, ipp);
739739
}
740740

741741
/*
@@ -786,8 +786,8 @@ xchk_iget_agi(
786786
if (error)
787787
return error;
788788

789-
error = xfs_iget(mp, tp, inum,
790-
XFS_IGET_NORETRY | XFS_IGET_UNTRUSTED, 0, ipp);
789+
error = xfs_iget(mp, tp, inum, XFS_IGET_NORETRY | XCHK_IGET_FLAGS, 0,
790+
ipp);
791791
if (error == -EAGAIN) {
792792
/*
793793
* The inode may be in core but temporarily unavailable and may
@@ -994,12 +994,6 @@ xchk_irele(
994994
spin_lock(&VFS_I(ip)->i_lock);
995995
VFS_I(ip)->i_state &= ~I_DONTCACHE;
996996
spin_unlock(&VFS_I(ip)->i_lock);
997-
} else if (atomic_read(&VFS_I(ip)->i_count) == 1) {
998-
/*
999-
* If this is the last reference to the inode and the caller
1000-
* permits it, set DONTCACHE to avoid thrashing.
1001-
*/
1002-
d_mark_dontcache(VFS_I(ip));
1003997
}
1004998

1005999
xfs_irele(ip);

fs/xfs/scrub/scrub.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ struct xfs_scrub;
1717
#define XCHK_GFP_FLAGS ((__force gfp_t)(GFP_KERNEL | __GFP_NOWARN | \
1818
__GFP_RETRY_MAYFAIL))
1919

20+
/*
21+
* For opening files by handle for fsck operations, we don't trust the inumber
22+
* or the allocation state; therefore, perform an untrusted lookup. We don't
23+
* want these inodes to pollute the cache, so mark them for immediate removal.
24+
*/
25+
#define XCHK_IGET_FLAGS (XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE)
26+
2027
/* Type info and names for the scrub types. */
2128
enum xchk_type {
2229
ST_NONE = 1, /* disabled */

0 commit comments

Comments
 (0)