/tmp on RAM

The purpose of /tmp directory on GNU/Linux has been to provide programs a directory for temporary files. A system reboot automatically deletes the file in /tmp directory. In this article, we would discuss /tmp on RAM.

Many GNU/Linux based distributions mounts /tmp as RAM based tmpfs (temporary file system). It not only removes disk I/O but also increases performance. Furthermore, its certain aspects will be discussed next.

What /tmp on RAM disk provides

A. Performance

Since /tmp mount on ram disk as tmpfs. Therefore, Read and Write will be significantly faster. It is worth mentioning here that, RAM’s Read and Write speeds are faster when compared to that of Hard Drive or Solid State Drive. Hence, applications can access data on /tmp quicker than usual.

B. Disk Optimization

Temporary files when placed on tmpfs, frees disk I/O which allow disk activity to go down and in turn it allocates resources to other disk I/O operations. Especially fewer Read and Write operations to Flash based Storage reduces the requirement to TRIM NAND based Disk.

Also, it results in fewer Disk wake-ups.

C. Data Security

As temporary data is not written to disk, the chances of data leak from Hard Disk/SSD are next to none.

What are limitations of /tmp on RAM disk

A. Pseudo Data Security

Data can however still leak, while system is live and program’s data resides in tmpfs or other side channels depending upon security measures taken by the program.

But data will not leak once the device is powered down, with exception for cold boot method for data recovery.

B. RAM Limit

tmpfs size is limited to amount of RAM available in the system. Therefore, size of /tmp is limited. If program hogs on /tmp directory for huge amounts of data then system will resort back to swap space or slow down the whole system, leaving you with no RAM for other processes.

Configure /tmp on tmpfs

On RHEL 7 / CentOS 7 / Fedora:

To Check

systemctl is-enabled tmp.mount

Enable –

systemctl enable tmp.mount

Disable –

systemctl disable tmp.mount

On Debian Stretch :

Check –

systemctl is-enabled tmp.mount

Enable –

cp /usr/share/systemd/tmp.mount /etc/systemd/system/

systemctl enable tmp.mount

Disable –

systemctl disable tmp.mount

Manually On GNU/Linux :

Add to /etc/fstab

tmpfs /tmp tmpfs rw,nosuid,noatime,nodev,size=4G,mode=1777 0 0

*size=4G depending on ram allocation.

Manually resize on fly :

mount -o remount,size=4G,noatime /tmp