Commit a4411519 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] vm: vfs shrinkage tuning

Some people want the dentry and inode caches shrink harder, others want them
shrunk more reluctantly.

The patch adds /proc/sys/vm/vfs_cache_pressure, which tunes the vfs cache
versus pagecache scanning pressure.

- at vfs_cache_pressure=0 we don't shrink dcache and icache at all.

- at vfs_cache_pressure=100 there is no change in behaviour.

- at vfs_cache_pressure > 100 we reclaim dentries and inodes harder.


The number of megabytes of slab left after a slocate.cron on my 256MB test
box:

vfs_cache_pressure=100000   33480
vfs_cache_pressure=10000    61996
vfs_cache_pressure=1000     104056
vfs_cache_pressure=200      166340
vfs_cache_pressure=100      190200
vfs_cache_pressure=50       206168

Of course, this just left more directory and inode pagecache behind instead of
vfs cache.  Interestingly, on this machine the entire slocate run fits into
pagecache, but not into VFS caches.
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 42b8d994
......@@ -1115,6 +1115,18 @@ program to load modules on demand.
The files in this directory can be used to tune the operation of the virtual
memory (VM) subsystem of the Linux kernel.
vfs_cache_pressure
------------------
Controls the tendency of the kernel to reclaim the memory which is used for
caching of directory and inode objects.
At the default value of vfs_cache_pressure=100 the kernel will attempt to
reclaim dentries and inodes at a "fair" rate with respect to pagecache and
swapcache reclaim. Decreasing vfs_cache_pressure causes the kernel to prefer
to retain dentry and inode caches. Increasing vfs_cache_pressure beyond 100
causes the kernel to prefer to reclaim dentries and inodes.
dirty_background_ratio
----------------------
......
......@@ -28,7 +28,7 @@ Currently, these files are in /proc/sys/vm:
==============================================================
dirty_ratio, dirty_background_ratio, dirty_expire_centisecs,
dirty_writeback_centisecs:
dirty_writeback_centisecs, vfs_cache_pressure:
See Documentation/filesystems/proc.txt
......
......@@ -32,9 +32,10 @@
#include <linux/swap.h>
#include <linux/bootmem.h>
#define DCACHE_PARANOIA 1
/* #define DCACHE_DEBUG 1 */
int sysctl_vfs_cache_pressure = 100;
spinlock_t dcache_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
seqlock_t rename_lock __cacheline_aligned_in_smp = SEQLOCK_UNLOCKED;
......@@ -664,7 +665,7 @@ static int shrink_dcache_memory(int nr, unsigned int gfp_mask)
return -1;
prune_dcache(nr);
}
return dentry_stat.nr_unused;
return (dentry_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
}
/**
......
......@@ -488,7 +488,7 @@ static int shrink_icache_memory(int nr, unsigned int gfp_mask)
if (gfp_mask & __GFP_FS)
prune_icache(nr);
}
return inodes_stat.nr_unused;
return (inodes_stat.nr_unused / 100) * sysctl_vfs_cache_pressure;
}
static void __wait_on_freeing_inode(struct inode *inode);
......
......@@ -313,6 +313,8 @@ static inline int d_mountpoint(struct dentry *dentry)
extern struct vfsmount *lookup_mnt(struct vfsmount *, struct dentry *);
extern struct dentry *lookup_create(struct nameidata *nd, int is_dir);
extern int sysctl_vfs_cache_pressure;
#endif /* __KERNEL__ */
#endif /* __LINUX_DCACHE_H */
......@@ -164,6 +164,7 @@ enum
VM_LAPTOP_MODE=23, /* vm laptop mode */
VM_BLOCK_DUMP=24, /* block dump mode */
VM_HUGETLB_GROUP=25, /* permitted hugetlb group */
VM_VFS_CACHE_PRESSURE=26, /* dcache/icache reclaim pressure */
};
......
......@@ -39,6 +39,8 @@
#include <linux/initrd.h>
#include <linux/times.h>
#include <linux/limits.h>
#include <linux/dcache.h>
#include <asm/uaccess.h>
#ifdef CONFIG_ROOT_NFS
......@@ -777,6 +779,16 @@ static ctl_table vm_table[] = {
.strategy = &sysctl_intvec,
.extra1 = &zero,
},
{
.ctl_name = VM_VFS_CACHE_PRESSURE,
.procname = "vfs_cache_pressure",
.data = &sysctl_vfs_cache_pressure,
.maxlen = sizeof(sysctl_vfs_cache_pressure),
.mode = 0644,
.proc_handler = &proc_dointvec,
.strategy = &sysctl_intvec,
.extra1 = &zero,
},
{ .ctl_name = 0 }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment