Boost Linux Server Performance: Master /dev/shm and tmpfs to Eliminate Disk I/O
This guide explains how to use Linux's memory‑based tmpfs and the /dev/shm mount point to avoid slow disk I/O, showing how to resize, bind, and apply tmpfs for caching, PHP sessions, and service sockets to dramatically improve server performance.
tmpfs is a memory‑based filesystem in Linux/Unix that can use RAM or swap to store files, offering dynamic sizing and lightning‑fast read/write because it resides entirely in memory.
Because data in tmpfs is volatile, it disappears after a reboot, so scripts are often needed to recreate mounts.
/dev/shm is a mount point that uses tmpfs (on CentOS/RedHat it links to /run/shm, on Ubuntu to /run/shm as well). By default its size is half of physical memory; you can view it with df -h.
To increase /dev/shm size, edit /etc/fstab entry for tmpfs and remount:
tmpfs /dev/shm tmpfs defaults,size=512m 0 0
mount -o remount /dev/shmAfter remount, df -h shows the new size.
Common use cases for tmpfs (/dev/shm) include placing cache directories, PHP session files, or service socket files in /tmp after binding it to /dev/shm, which can dramatically speed up web services.
Examples:
Set Squid cache directory to /tmp with cache_dir ufs /tmp 256 16 256.
Set PHP session path to /tmp via session.save_path = "/tmp".
Place nginx or MySQL socket files in /tmp.
Remember that data stored in tmpfs does not persist across reboots, so appropriate startup scripts should recreate any needed mounts or bindings.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
