I want to run a task with limits on the kernel objects that they will indirectly trigger. Note that this is not about the memory, threads, etc. used by the application, but about memory used by the kernel. Specifically, I want to limit the amount of inode cache that the task can use.
My motivating example is updatedb
. It can use a considerable amount of inode cache, for things that mostly won't be needed afterwards. Specifically, I want to limit the value that is indicated by the ext4_inode_cache
line in /proc/slabinfo
. (Note that this is not included in the “buffers” or “cache” lines shown by free
: that's only file content cache, the slab content is kernel memory and recorded in the “used” column.)
echo 2 >/proc/sys/vm/drop_caches
afterwards frees the cache, but that doesn't do me any good: the useless stuff has displaced things that I wanted to keep in memory, such as running applications and their frequently-used files.
The system is Linux with a recent (≥ 3.8) kernel. I can use root access to set things up.
How can I run a command in a limited environment (a container?) such that the contribution of that environment to the (ext4) inode cache is limited to a value that I set?
find
. But find has no mechanism which would allow this to be controlled.