From Gentoo Wiki
Jump to: navigation, search
This page contains changes which are not marked for translation.



tmpfs (Temporary File System) is a virtual filesystem to store files in memory.

The volatile memory can't keep the files after shutdown, reboot or crash. Only store recoverable files in tmpfs.

In GNU Linux the RAMFS(Random Access Memory File System) has been replaced by TMPFS as the old RAMFS did not handle well when the system run out of memory. The TMPFS allows the filesystem to grow dynamically as and when it needs more space until it hits the pre-set maximum value it has been allocated, after which time it will complain it is out of space and if the ram is used up before it's maximum set value is used it will then use swap space if it is available.

There are many ways and many things we can use the temporary file system in GNU Linux, one being the /tmp directory which does not need to physically store non-volatile data. It matter not that this data is wiped out after a reboot as you are booting up a new session which will be creating and writing new cache data and so on into the /tmp directory.

If you use SystemD to boot instead of OpenRC your /tmp directory is mounted by default as a TMPFS, see section bellow on SystemD to either disable this and mount it manually in /etc/fstab.


You need to activate the following kernel options:

File systems  --->
     Pseudo filesystems  --->
          [*] Tmpfs virtual memory file system support (former shm fs)
          [ ] Optional drivers
Optional drivers
Option Description
Tmpfs POSIX Access Control Lists Enable ACL permissions.
Tmpfs extended attributes Enable metadata support.


Generation and mounting of tmpfs in one step:

root #mount -t tmpfs tmpfs /MOUNTPOINT

You can specify the mount option size to control the maximum size of the filesystem (default: half of your memory). Note that tmpfs doesn't reserve this memory, but allocates only the needed memory.


When using SystemD the /tmp directory is mounted by default as a TMPFS and given a default size which is deemed big enough for your usage but not so big it will chew up too much RAM. You can view mounted temporary filesystems using this command

root # findmnt --target /tmp

This will show you if the /tmp mount-point is a tmpfs filesystem and will show you the set size of said filesystem.

If you want to disable this and take back control of the directory and have it controlled through your /etc/fstab then we can do this by disabling the automatic mount from SystemD and adding it to our /etc/fstab.

root #systemctl mask tmp.mount

This command will now not mount /tmp as a tmpfs and will automatically default back to your block device i.e. you HDD/SSD. We can now add a new line in our /etc/fstab which will create a tmpfs for /tmp manually.

FILE /etc/fstabtmpfs fstab example
tmpfs /tmp         tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0


OpenRC is the same as for SystemD only we ommit having to disable SystemD from mounting the /tmp directory manually. This means it is as simple as adding the mountpoint into your /etc/fstab.

FILE /etc/fstabtmpfs fstab example
tmpfs /tmp         tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0

Other directories to consider

Performance boosting our systems is for many first and foremost, faster performance higher security and better privacy so here are a few other directories to consider in mounting as a tmpfs to boost your Gentoo GNU Linux box. Most standard installations of Gentoo have already set the folders bellow as a tmpfs so use the findmnt command to check if they are already a tmpfs before you attempt to manually mount them in your fstab.

root # findmnt --target /"Directory to check"

Directory Purpose
/run Run-time variable data: Information about the running system since last boot, e.g., currently logged-in users and running daemons.
/var/run Run-time variable data. This directory contains system information data describing the system since it was booted.
/var/lock Lock files. Files keeping track of resources currently in use.


The outcome of using a temporary filesystem for non volatile files such as the /tmp directory is that the system has a very fast and very responsive access to caching files and or stored session media. This also helps when you use a browser to surf the web as the cookies can be made to be stored on this volatile media speeding up the browser and on every reboot they are scrubbed or wiped from RAM. If you intend on keeping your temporary files for analytics then use of the tmpfs for /tmp and other directories which are used similarly may not be for you. Remember all data stored in the tmpfs mount point will be lost when the system is rebooted or powered down.

Advancements in Technology

There has been some new offerings from the tech giants including a not as fast as RAM but faster than SSD technology to be used as cache drives. These devices are usually incorporated on a PCIe add-in card and have either a adaptor from PCIe to M.2 slot or the entire memory device is embedded into the PCIe card.

So if you need a non-volatile high speed versatile solution that is faster than SSD/SAS/SATA then these high speed solutions are something you should look into. Of course you would not be mounting these devices with tmpfs but instead using a conventional partitioning filesystem and then mounting the appropriate mount-point to the device such as /dev/sd* /tmp and so on.

Technology such as the Intel 3Dx Optaine memory cache can be used for task like this but this technology although more versatile than SSD it is still subject to wearing out. It does however provide a brilliant midway point that will only get better as the technology progresses in the future and provide us with a much faster much snappier computing experience when setup correctly.

See also