Linux RAM Filesystem: 4 Steps to Speed Up Builds

Quick Linux Tip #106:

Question: My build is slow because of disk I/O. How do I use RAM as a filesystem?

Try: sudo mount -t tmpfs -o size=4G,mode=1777 tmpfs /mnt/ramdisk

Info: tmpfs creates an ultra-fast temporary RAM filesystem (~7x faster than SSD), ideal for build caches, temp files, and test databases. Data vanishes on reboot.

Examples:

  • $ sudo mkdir /mnt/ramdisk && sudo mount -t tmpfs -o size=2G tmpfs /mnt/ramdisk  # Create & mount 2G RAM disk
  • $ echo 'tmpfs /mnt/ramdisk tmpfs defaults,size=4G 0 0' | sudo tee -a /etc/fstab  # Persist mount config across reboots
  • $ sudo umount /mnt/ramdisk  # Unmount filesystem and free allocated RAM

Note: mode=1777 sets world-writable access with the sticky bit (like /tmp). RAM is only consumed as files are written and freed when deleted or unmounted.




LinuxTeck.com
linuxteck:~$ sudo mount -t tmpfs -o size=4G,mode=1777 tmpfs /mnt/ramdisk

linuxteck:~$ df -h /mnt/ramdisk
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           4.0G     0  4.0G   0% /mnt/ramdisk

linuxteck:~$ dd if=/dev/zero of=/mnt/ramdisk/test bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 0.345 s, 3.1 GB/s

linuxteck:~$ dd if=/dev/zero of=/tmp/test bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 2.34 s, 459 MB/s
linuxteck:~$

PREVIOUS ARTICLE Quick Linux Tip #105: Bash History Monitoring: 5 Ways to Audit Linux Commands NEXT ARTICLE Quick Linux Tip #107: Linux Secure Password Generation: 4 Easy Methods
About John Britto

John Britto Founder & Chief-Editor @LinuxTeck. A Computer Geek and Linux Intellectual having more than 20+ years of experience in Linux and Open Source technologies.

View all posts by John Britto →

Leave a Reply

Your email address will not be published.