Ramfs is a Linux-based file system that is stored under RAM. In the process you can think of Ramfs as the creation of a file system on a normal HDD, and now HDD is replaced with RAM, because RAM is stored so it has high storage efficiency. Since the implementation of RAMFS is equivalent to storing RAM as the last layer, swap is not used in Ramfs. When did you hear about the swap of files on HDD? The usual swap is for memory, while the RAMFS underlying storage is RAM, not HDD, but it looks like HDD to Linux. But the big flaw with RAMFS is that it eats up all of the system's memory, even if you specify the size when you mount, and it can only be accessed by the root user. The test method is simple:
sudo mount-t ramfs-o size=10m Ramfs./ramfs/
sudo dd if=/dev/zero of=./ramfs/test.file bs=1m count=20
Test you will find that the above operation is successful, or you can simply do a hard point on your own virtual machine, directly write a larger than the memory of the file, you will find the instant system on the card master. In addition, the DD command does not have sufficient permissions if it is not executed with root user:
Dd:opening './ramfs/test.file ': Permission denied
TMPFS is also a file system under Linux, it will all the files are stored in virtual memory, Umount TMPFS after all the data will be lost, TMPFS is Ramfs derivatives. TMPFS uses the mechanism of virtual memory, it will swap, but it has a benefit compared to RAMFS: the size parameter specified at mount is working so that the system is safe, not like Ramfs. I'm not paying attention because writing data is too big to eat all the system memory causes the system to hang. In the first example of my article is mount a 10M size Tmpfs, and then execute the SQL command (it needs to create a temporary table greater than 10M), because TMPFS limit the size, so also error. So what are the scenarios for TMPFS? There are several main points in the official documentation:
Kernel need it inside, and we can't see it.
GLIBC more than 2.2 versions, there must be a TMPFS mount in/dev/shm used as POSIX shared memory
There are many other uses that we don't know yet.
Including my current company there is a need, some data if the access pressure on the disk can not carry, so temporarily made a TMPFS cache to slow down the pressure, of course, this is not the ultimate solution. So in summary, Ramfs and TMPFS have the following similarities and differences:
Ramfs will automatically grow in space because of data writes, which may result in the last system all memory consumption
TMPFS can be limited in size at Mount, and will not grow automatically
Ramfs won't use swap.
TMPFS will use swap
Both are used to improve efficiency, but TMPFS is better than RAMFS (the results are right and the principle remains to be explored)
The difference between TMPFS and Ramfs under Linux