Linux – Limit the inode cache used by a command

cacheinodelimitlinuxmemory

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?

Best Answer

If you look at the kernel's inode source code, you can see that the ihash_entries is set at the kernel level only.

There is no user or process level considerations at all. Adding those could drastically decrease performance which would be counter productive.

It would also imply keeping track of all processes that used the cached entries, therefore using more memory to do it.

The bottom line is that it is simply not possible with the current kernel, nor would it be a good idea to implement it.

Related Question