Skip to content

Commit 2c567af

Browse files
weiny2djwong
authored andcommitted
fs: Introduce DCACHE_DONTCACHE
DCACHE_DONTCACHE indicates a dentry should not be cached on final dput(). Also add a helper function to mark DCACHE_DONTCACHE on all dentries pointing to a specific inode when that inode is being set I_DONTCACHE. This facilitates dropping dentry references to inodes sooner which require eviction to swap S_DAX mode. Cc: Al Viro <[email protected]> Signed-off-by: Ira Weiny <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent dae2f8e commit 2c567af

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

fs/dcache.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ static inline bool retain_dentry(struct dentry *dentry)
647647
if (dentry->d_op->d_delete(dentry))
648648
return false;
649649
}
650+
651+
if (unlikely(dentry->d_flags & DCACHE_DONTCACHE))
652+
return false;
653+
650654
/* retain; LRU fodder */
651655
dentry->d_lockref.count--;
652656
if (unlikely(!(dentry->d_flags & DCACHE_LRU_LIST)))
@@ -656,6 +660,21 @@ static inline bool retain_dentry(struct dentry *dentry)
656660
return true;
657661
}
658662

663+
void d_mark_dontcache(struct inode *inode)
664+
{
665+
struct dentry *de;
666+
667+
spin_lock(&inode->i_lock);
668+
hlist_for_each_entry(de, &inode->i_dentry, d_u.d_alias) {
669+
spin_lock(&de->d_lock);
670+
de->d_flags |= DCACHE_DONTCACHE;
671+
spin_unlock(&de->d_lock);
672+
}
673+
inode->i_state |= I_DONTCACHE;
674+
spin_unlock(&inode->i_lock);
675+
}
676+
EXPORT_SYMBOL(d_mark_dontcache);
677+
659678
/*
660679
* Finish off a dentry we've decided to kill.
661680
* dentry->d_lock must be held, returns with it unlocked.

fs/xfs/xfs_icache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ xfs_iget_cache_miss(
561561
*/
562562
iflags = XFS_INEW;
563563
if (flags & XFS_IGET_DONTCACHE)
564-
VFS_I(ip)->i_state |= I_DONTCACHE;
564+
d_mark_dontcache(VFS_I(ip));
565565
ip->i_udquot = NULL;
566566
ip->i_gdquot = NULL;
567567
ip->i_pdquot = NULL;

include/linux/dcache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ struct dentry_operations {
177177

178178
#define DCACHE_REFERENCED 0x00000040 /* Recently used, don't discard. */
179179

180+
#define DCACHE_DONTCACHE 0x00000080 /* Purge from memory on final dput() */
181+
180182
#define DCACHE_CANT_MOUNT 0x00000100
181183
#define DCACHE_GENOCIDE 0x00000200
182184
#define DCACHE_SHRINK_LIST 0x00000400

include/linux/fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,6 +3055,7 @@ static inline int generic_drop_inode(struct inode *inode)
30553055
return !inode->i_nlink || inode_unhashed(inode) ||
30563056
(inode->i_state & I_DONTCACHE);
30573057
}
3058+
extern void d_mark_dontcache(struct inode *inode);
30583059

30593060
extern struct inode *ilookup5_nowait(struct super_block *sb,
30603061
unsigned long hashval, int (*test)(struct inode *, void *),

0 commit comments

Comments
 (0)