How to make /tmp directory use RAM over FileSystem
For faster access to /tmp directory, like you are storing a video stream in it, it would then be best to have it mounted to RAM rather than SSD file system.
df -hT
will show you all things mounted and what type. If the type is tmpfs
then that means its on RAM.
mount
will also show you all things mounted and again you are looking if tmp
is mounted on type tmpfs
To add tmp
you need to update the file system table, which you can view by doing cat /etc/fstab
.
Point to consider is how much RAM you have on your machine and then to accordingly decide if mounting /tmp
directory makes sense given how how much space you think it will take and whether it will result in swapping RAM to disk. You can check your RAM by doing free -mh
.
Update fstab
with the following will add tmp
to RAM and limit its size to .5GB.
tmpfs /tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0
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 stored session media. This also helps when using a browser to surf the web as cookies can be stored on this volatile media speeding up the application; on every reboot they are scrubbed or wiped from RAM. If users need to keep temporary files for analytics then they should avoid using the tmpfs filesystem for /tmp and other directories. All data stored in the tmpfs mount point will be lost when the system is rebooted or powered down.
Another command which can tell you where and how your directory is mounted is findmnt --target /<directory-to-check>
Easiest way to mount is:
sudo mount -t tmpfs tmpfs /tmp
But this is temporary and after restarting /tmp
is back again on ext4
. To Restart sudo shutdown -r -t 0
.
To edit use vim
. If you don’t have it, install by doing sudo apt-get install vim
.
Do free -h
to check how much free memory you have and then make decision on what size you want to allocate.
Finally updating /etc/fstab
is what does the trick on a raspberrypi.
- First
sudo vim /etc/fstab
- Then add a new line with
tmpfs /tmp tmpfs rw,nosuid,noatime,nodev,size=256M,mode=1777 0 0
- Then restart
sudo shutdown -r -t 0
. - Now check it
df -hT
andmount | grep /tmp