Operations 5 min read

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.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Boost Linux Server Performance: Master /dev/shm and tmpfs to Eliminate Disk I/O

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/shm

After 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performancecachingLinuxServertmpfsdev/shm
MaGe Linux Operations
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.