Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

superblock: add filesystem shrinker operations

Now we have a per-superblock shrinker implementation, we can add a
filesystem specific callout to it to allow filesystem internal
caches to be shrunk by the superblock shrinker.

Rather than perpetuate the multipurpose shrinker callback API (i.e.
nr_to_scan == 0 meaning "tell me how many objects freeable in the
cache), two operations will be added. The first will return the
number of objects that are freeable, the second is the actual
shrinker call.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Dave Chinner and committed by
Al Viro
0e1fdafd 4f8c19fd

+50 -11
+16
Documentation/filesystems/vfs.txt
··· 229 229 230 230 ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); 231 231 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 232 + int (*nr_cached_objects)(struct super_block *); 233 + void (*free_cached_objects)(struct super_block *, int); 232 234 }; 233 235 234 236 All methods are called without any locks being held, unless otherwise ··· 302 300 quota_read: called by the VFS to read from filesystem quota file. 303 301 304 302 quota_write: called by the VFS to write to filesystem quota file. 303 + 304 + nr_cached_objects: called by the sb cache shrinking function for the 305 + filesystem to return the number of freeable cached objects it contains. 306 + Optional. 307 + 308 + free_cache_objects: called by the sb cache shrinking function for the 309 + filesystem to scan the number of objects indicated to try to free them. 310 + Optional, but any filesystem implementing this method needs to also 311 + implement ->nr_cached_objects for it to be called correctly. 312 + 313 + We can't do anything with any errors that the filesystem might 314 + encountered, hence the void return type. This will never be called if 315 + the VM is trying to reclaim under GFP_NOFS conditions, hence this 316 + method does not need to handle that situation itself. 305 317 306 318 Whoever sets up the inode is responsible for filling in the "i_op" field. This 307 319 is a pointer to a "struct inode_operations" which describes the methods that
+32 -11
fs/super.c
··· 48 48 static int prune_super(struct shrinker *shrink, struct shrink_control *sc) 49 49 { 50 50 struct super_block *sb; 51 - int count; 51 + int fs_objects = 0; 52 + int total_objects; 52 53 53 54 sb = container_of(shrink, struct super_block, s_shrink); 54 55 ··· 63 62 if (!grab_super_passive(sb)) 64 63 return -1; 65 64 65 + if (sb->s_op && sb->s_op->nr_cached_objects) 66 + fs_objects = sb->s_op->nr_cached_objects(sb); 67 + 68 + total_objects = sb->s_nr_dentry_unused + 69 + sb->s_nr_inodes_unused + fs_objects + 1; 70 + 66 71 if (sc->nr_to_scan) { 67 - /* proportion the scan between the two caches */ 68 - int total; 72 + int dentries; 73 + int inodes; 69 74 70 - total = sb->s_nr_dentry_unused + sb->s_nr_inodes_unused + 1; 71 - count = (sc->nr_to_scan * sb->s_nr_dentry_unused) / total; 75 + /* proportion the scan between the caches */ 76 + dentries = (sc->nr_to_scan * sb->s_nr_dentry_unused) / 77 + total_objects; 78 + inodes = (sc->nr_to_scan * sb->s_nr_inodes_unused) / 79 + total_objects; 80 + if (fs_objects) 81 + fs_objects = (sc->nr_to_scan * fs_objects) / 82 + total_objects; 83 + /* 84 + * prune the dcache first as the icache is pinned by it, then 85 + * prune the icache, followed by the filesystem specific caches 86 + */ 87 + prune_dcache_sb(sb, dentries); 88 + prune_icache_sb(sb, inodes); 72 89 73 - /* prune dcache first as icache is pinned by it */ 74 - prune_dcache_sb(sb, count); 75 - prune_icache_sb(sb, sc->nr_to_scan - count); 90 + if (fs_objects && sb->s_op->free_cached_objects) { 91 + sb->s_op->free_cached_objects(sb, fs_objects); 92 + fs_objects = sb->s_op->nr_cached_objects(sb); 93 + } 94 + total_objects = sb->s_nr_dentry_unused + 95 + sb->s_nr_inodes_unused + fs_objects; 76 96 } 77 97 78 - count = ((sb->s_nr_dentry_unused + sb->s_nr_inodes_unused) / 100) 79 - * sysctl_vfs_cache_pressure; 98 + total_objects = (total_objects / 100) * sysctl_vfs_cache_pressure; 80 99 drop_super(sb); 81 - return count; 100 + return total_objects; 82 101 } 83 102 84 103 /**
+2
include/linux/fs.h
··· 1655 1655 ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 1656 1656 #endif 1657 1657 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t); 1658 + int (*nr_cached_objects)(struct super_block *); 1659 + void (*free_cached_objects)(struct super_block *, int); 1658 1660 }; 1659 1661 1660 1662 /*