From ab26409db753bb087842ab6f1af943f3386c764f Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 22 Dec 2011 12:20:43 -0800 Subject: Linux 3.1 compat, super_block->s_shrink The Linux 3.1 kernel has introduced the concept of per-filesystem shrinkers which are directly assoicated with a super block. Prior to this change there was one shared global shrinker. The zfs code relied on being able to call the global shrinker when the arc_meta_limit was exceeded. This would cause the VFS to drop references on a fraction of the dentries in the dcache. The ARC could then safely reclaim the memory used by these entries and honor the arc_meta_limit. Unfortunately, when per-filesystem shrinkers were added the old interfaces were made unavailable. This change adds support to use the new per-filesystem shrinker interface so we can continue to honor the arc_meta_limit. The major benefit of the new interface is that we can now target only the zfs filesystem for dentry and inode pruning. Thus we can minimize any impact on the caching of other filesystems. In the context of making this change several other important issues related to managing the ARC were addressed, they include: * The dnlc_reduce_cache() function which was called by the ARC to drop dentries for the Posix layer was replaced with a generic zfs_prune_t callback. The ZPL layer now registers a callback to drop these dentries removing a layering violation which dates back to the Solaris code. This callback can also be used by other ARC consumers such as Lustre. arc_add_prune_callback() arc_remove_prune_callback() * The arc_reduce_dnlc_percent module option has been changed to arc_meta_prune for clarity. The dnlc functions are specific to Solaris's VFS and have already been largely eliminated already. The replacement tunable now represents the number of bytes the prune callback will request when invoked. * Less aggressively invoke the prune callback. We used to call this whenever we exceeded the arc_meta_limit however that's not strictly correct since it results in over zeleous reclaim of dentries and inodes. It is now only called once the arc_meta_limit is exceeded and every effort has been made to evict other data from the ARC cache. * More promptly manage exceeding the arc_meta_limit. When reading meta data in to the cache if a buffer was unable to be recycled notify the arc_reclaim thread to invoke the required prune. * Added arcstat_prune kstat which is incremented when the ARC is forced to request that a consumer prune its cache. Remember this will only occur when the ARC has no other choice. If it can evict buffers safely without invoking the prune callback it will. * This change is also expected to resolve the unexpect collapses of the ARC cache. This would occur because when exceeded just the arc_meta_limit reclaim presure would be excerted on the arc_c value via arc_shrink(). This effectively shrunk the entire cache when really we just needed to reclaim meta data. Signed-off-by: Brian Behlendorf Closes #466 Closes #292 --- module/zfs/zpl_super.c | 126 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 106 insertions(+), 20 deletions(-) (limited to 'module/zfs/zpl_super.c') diff --git a/module/zfs/zpl_super.c b/module/zfs/zpl_super.c index 650e9c0d3..3abb26a9e 100644 --- a/module/zfs/zpl_super.c +++ b/module/zfs/zpl_super.c @@ -199,34 +199,120 @@ zpl_kill_sb(struct super_block *sb) kill_anon_super(sb); } +#ifdef HAVE_SHRINK +/* + * Linux 3.1 - 3.x API + * + * The Linux 3.1 API introduced per-sb cache shrinkers to replace the + * global ones. This allows us a mechanism to cleanly target a specific + * zfs file system when the dnode and inode caches grow too large. + * + * In addition, the 3.0 kernel added the iterate_supers_type() helper + * function which is used to safely walk all of the zfs file systems. + */ +static void +zpl_prune_sb(struct super_block *sb, void *arg) +{ + int objects = 0; + int error; + + error = -zfs_sb_prune(sb, *(unsigned long *)arg, &objects); + ASSERT3S(error, <=, 0); + + return; +} + +void +zpl_prune_sbs(int64_t bytes_to_scan, void *private) +{ + unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t)); + + iterate_supers_type(&zpl_fs_type, zpl_prune_sb, &nr_to_scan); + kmem_reap(); +} +#else +/* + * Linux 2.6.x - 3.0 API + * + * These are best effort interfaces are provided by the SPL to induce + * the Linux VM subsystem to reclaim a fraction of the both dnode and + * inode caches. Ideally, we want to just target the zfs file systems + * however our only option is to reclaim from them all. + */ +void +zpl_prune_sbs(int64_t bytes_to_scan, void *private) +{ + unsigned long nr_to_scan = (bytes_to_scan / sizeof(znode_t)); + + shrink_dcache_memory(nr_to_scan, GFP_KERNEL); + shrink_icache_memory(nr_to_scan, GFP_KERNEL); + kmem_reap(); +} +#endif /* HAVE_SHRINK */ + +#ifdef HAVE_NR_CACHED_OBJECTS +static int +zpl_nr_cached_objects(struct super_block *sb) +{ + zfs_sb_t *zsb = sb->s_fs_info; + int nr; + + mutex_enter(&zsb->z_znodes_lock); + nr = zsb->z_nr_znodes; + mutex_exit(&zsb->z_znodes_lock); + + return (nr); +} +#endif /* HAVE_NR_CACHED_OBJECTS */ + +#ifdef HAVE_FREE_CACHED_OBJECTS +/* + * Attempt to evict some meta data from the cache. The ARC operates in + * terms of bytes while the Linux VFS uses objects. Now because this is + * just a best effort eviction and the exact values aren't critical so we + * extrapolate from an object count to a byte size using the znode_t size. + */ +static void +zpl_free_cached_objects(struct super_block *sb, int nr_to_scan) +{ + arc_adjust_meta(nr_to_scan * sizeof(znode_t), B_FALSE); +} +#endif /* HAVE_FREE_CACHED_OBJECTS */ + const struct super_operations zpl_super_operations = { - .alloc_inode = zpl_inode_alloc, - .destroy_inode = zpl_inode_destroy, - .dirty_inode = NULL, - .write_inode = NULL, - .drop_inode = NULL, + .alloc_inode = zpl_inode_alloc, + .destroy_inode = zpl_inode_destroy, + .dirty_inode = NULL, + .write_inode = NULL, + .drop_inode = NULL, #ifdef HAVE_EVICT_INODE - .evict_inode = zpl_evict_inode, + .evict_inode = zpl_evict_inode, #else - .clear_inode = zpl_clear_inode, - .delete_inode = zpl_inode_delete, + .clear_inode = zpl_clear_inode, + .delete_inode = zpl_inode_delete, #endif /* HAVE_EVICT_INODE */ - .put_super = zpl_put_super, - .write_super = NULL, - .sync_fs = zpl_sync_fs, - .statfs = zpl_statfs, - .remount_fs = zpl_remount_fs, - .show_options = zpl_show_options, - .show_stats = NULL, + .put_super = zpl_put_super, + .write_super = NULL, + .sync_fs = zpl_sync_fs, + .statfs = zpl_statfs, + .remount_fs = zpl_remount_fs, + .show_options = zpl_show_options, + .show_stats = NULL, +#ifdef HAVE_NR_CACHED_OBJECTS + .nr_cached_objects = zpl_nr_cached_objects, +#endif /* HAVE_NR_CACHED_OBJECTS */ +#ifdef HAVE_FREE_CACHED_OBJECTS + .free_cached_objects = zpl_free_cached_objects, +#endif /* HAVE_FREE_CACHED_OBJECTS */ }; struct file_system_type zpl_fs_type = { - .owner = THIS_MODULE, - .name = ZFS_DRIVER, + .owner = THIS_MODULE, + .name = ZFS_DRIVER, #ifdef HAVE_MOUNT_NODEV - .mount = zpl_mount, + .mount = zpl_mount, #else - .get_sb = zpl_get_sb, + .get_sb = zpl_get_sb, #endif /* HAVE_MOUNT_NODEV */ - .kill_sb = zpl_kill_sb, + .kill_sb = zpl_kill_sb, }; -- cgit v1.2.3