All Linux HowTo's

Set the inode limit in /etc/fstab for tmpfs on a CentOS or Redhat server

This article explains how to set the inode limit on a tmpfs on a CentOS or RHEL server. The default inode limit may be too small if you intend to store many small files on it.

The following will set the tmpfs resource to 2GB with a default inode limit (nr_inodes=174837). The inode limit is calculated based on the size you specify.

tmpfs 			/var/mytmpfs 	tmpfs 	defaults,size=2048m,nr_inodes=174837 	0 0

By changing the “nr_inodes=174837” to be “nr_inodes=1748370” we’ve changed it by a factor of 10. And there fore can fit 10 times more files on it assuming there’s space.

Note the extra “0” at the end of the “nr_inodes” value in the following example:

tmpfs 			/var/mytmpfs 	tmpfs 	defaults,size=2048m,nr_inodes=1748370 	0 0

Make sure that “/var/myrmpfs” exists before mounting the above tmpfs resource.

You can now umount and mount the above resource to see it take effect.

TIP: always do the mount first to make sure it works. You don’t want to test this for the first time by rebooting the server because if you’ve made a mistake, you will have a hard time booting into the OS.