What is tmpfs?
tmpfs is a temporary filesystem which lives completely in the memory's page cache and on swap.
what is /dev/shm?
- It's an instance of tmpfs.
- There're other tmpfs instances like /run, /tmp base on different Linux distributions.
- The default size of /dev/shm is half of your memory size. But this size is only the maximum amount of memory it can use. It doesn't actually use that memory unless its storing something.
Why put files into tmpfs?
- Speed up accesses to these files
- Efficiently passing data between programs(for shared memory)
- Ensure these files will automatically cleared upon reboot. (e.g., .pid and lock file).
*Note: When using systemd, temporary files in tmpfs directories can be recreated at boot by using tmpfiles.d.
- Most systems use very little shared memory, run
ipcs -mto see how much yours is currently using
- Even less actually use POSIX shared memory (/dev/shm)
- You can mount /dev/shm with a larger size and put DB files inside for a better performance
vi /etc/fstab tmpfs /tmp tmpfs nodev,noexec,nosuid,size=20G 0 0 mount -o remount /dev/shm
- Compile source codes in tmpfs will be much faster since the entire untar and compile require no actual disk I/O