What is tmpfs and Ramfs in Linux
The major benefit to memory based file systems is that they are very fast – 10s of times faster than modern SSDs. Read and write performance is massively increased for all workload types. These types of fast storage areas are ideally suited for applications which need repetitively small data areas for caching or using as temporary space. In Oracle 11GR2 configuring the “tmpfs” is mandatory if we want to use the AMM(Automatic Memory Management).
tmpfs vs. ramfs
The two main RAM based file system types in Linux are tmpfs and ramfs. ramfs is the older file system type and is largely replaced in most scenarios by tmpfs.
ramfs
ramfs create file system in RAM as normal filesystem on DISK. Linux cache the files in RAM for faster access , but if the RAM got full the files will be moved to swap memory. ramfs uses this same memory and exactly the same mechanism which causes Linux to cache files with the exception that it is not removed when the memory used exceeds threshold set by the system.
The main disadvantage of ramfs is , we can not set a hard limit for the memory usage for ramfs , it will completely use the RAM if required and make the system hung. This is a problem if the application writing to the file system cannot be limited in total size. Another issue is you cannot see the size of the file system in df and it can only be estimated by looking at the cached entry in free.
tmpfs
tmpfs is advanced than ramfs. tmpfs uses a combination of computer RAM and disk based SWAP space to create a filesystem, such as EXT4, that the operating system can use. Because tmpfs is located in RAM, it’s very fast to read and write data to and from it, several times faster than an SSD. As your computer runs out of RAM, some of the data in tmpfs will be flushed to the systems SWAP storage on disk. This will dramatically decrease the speed that the tmpfs can be used, but stop your computer from receiving out of memory errors.
We can also check the size of tmpfs using the os level df command.
Advantages of tmpfs over ramfs
1) We can see the size of tmpfs using the df command
[oracle@node1 ~]$ df -h
tmpfs 8.0G 327M 7.7G 4% /dev/shm
2) We can set hard limit for size of the tmpfs
# mkdir -p /dev/tmp1
# mount -t tmpfs -o size=5g tmpfs /dev/tmp1
[root@node1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
…..
tmpfs 5.0G 0 5.0G 0% /dev/tmp1
to make the values persistent after the reboot , made an entry in /etc/fstab file.
tmpfs /dev/shm tmpfs defaults,size=5G 0 0
3) tmpfs can use the swap.