History

fs: Kill DCACHE_DONTCACHE dentry even if DCACHE_REFERENCED is set

If DCACHE_REFERENCED is set, fast_dput() will return true, and then retain_dentry() have no chance to check DCACHE_DONTCACHE. As a result, the dentry won't be killed and the corresponding inode can't be evicted. In the following example, the DAX policy can't take effects unless we do a drop_caches manually. # DCACHE_LRU_LIST will be set echo abcdefg > test.txt # DCACHE_REFERENCED will be set and DCACHE_DONTCACHE can't do anything xfs_io -c 'chattr +x' test.txt # Drop caches to make DAX changing take effects echo 2 > /proc/sys/vm/drop_caches What this patch does is preventing fast_dput() from returning true if DCACHE_DONTCACHE is set. Then retain_dentry() will detect the DCACHE_DONTCACHE and will return false. As a result, the dentry will be killed and the inode will be evicted. In this way, if we change per-file DAX policy, it will take effects automatically after this file is closed by all processes. I also add some comments to make the code more clear.

Hao Li committed 5 years ago

Commit 77573fa1 parent 88149081 file · +8 −1Browse files

Unified · Split

fs/dcache.c+8−1
@@ -793,10 +793,17 @@ static inline bool fast_dput(struct dentry *dentry) · 792 unmodified lines
793 * a reference to the dentry and change that, but793 * a reference to the dentry and change that, but
794 * our work is done - we can leave the dentry794 * our work is done - we can leave the dentry
795 * around with a zero refcount.795 * around with a zero refcount.
796 *
797 * Nevertheless, there are two cases that we should kill
798 * the dentry anyway.
799 * 1. free disconnected dentries as soon as their refcount
800 * reached zero.
801 * 2. free dentries if they should not be cached.
796 */802 */
797 smp_rmb();803 smp_rmb();
798 d_flags = READ_ONCE(dentry->d_flags);804 d_flags = READ_ONCE(dentry->d_flags);
799 d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST | DCACHE_DISCONNECTED;805 d_flags &= DCACHE_REFERENCED | DCACHE_LRU_LIST |
806 DCACHE_DISCONNECTED | DCACHE_DONTCACHE;
800 807
801 /* Nothing to do? Dropping the reference was all we needed? */808 /* Nothing to do? Dropping the reference was all we needed? */
802 if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry))809 if (d_flags == (DCACHE_REFERENCED | DCACHE_LRU_LIST) && !d_unhashed(dentry))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t