Skip to content

Moving /tmp to tmpfs on cPanel — speed and risks

Putting /tmp on tmpfs (RAM-backed) speeds up PHP sessions, MySQL temp tables, and many small-file operations. cPanel does this by default through securetmp. Here is what it does and when to adjust.

cPanel ships with /usr/local/cpanel/scripts/securetmp which mounts /tmp as a separate filesystem with noexec and nosuid for security. On most modern cPanel hosts, this is a file-backed loop device — fast enough for normal use, but disk-bound. Some teams move /tmp to tmpfs (RAM-backed) for additional speed, especially when sessions and MySQL temp tables churn heavily. The change is small; the implications are worth understanding before you flip it.

What’s happening

/tmp on a cPanel host is heavily used by: PHP file-based sessions, MySQL temporary tables (tmpdir), upload processing, package builds, and any random script that writes scratch files. On a busy WordPress host, hundreds of MB of tmp writes per minute is normal.

With /tmp on disk (default secure setup), every write is a disk operation. On NVMe this is fast; on SATA SSD it is moderate; on HDD it can be a bottleneck. tmpfs eliminates the disk hit entirely — writes are pure memory operations.

The tradeoffs:

  • Speed: tmpfs is 5-50x faster than disk-backed tmp, depending on disk type.
  • Persistence: tmpfs is cleared on reboot. For tmp, this is usually fine — tmp is supposed to be ephemeral.
  • RAM consumption: tmpfs uses RAM up to its size limit. A 4 GB tmpfs effectively reduces usable RAM by up to 4 GB. On a tight host, this matters.
  • OOM behavior: a process that fills /tmp will consume RAM rather than disk space, potentially triggering OOM.

How to verify

Current /tmp setup:

mount | grep -E '\s/tmp\s'
df -h /tmp
ls -la /usr/tmpDSK 2>/dev/null

If the mount line shows loop, it is the cPanel default file-backed setup. If it shows tmpfs, it is already RAM-backed.

Size and pressure:

df -h /tmp
du -sh /tmp 2>/dev/null
ls /tmp | wc -l

For PHP session counts:

ls /var/cpanel/php/sessions/ea-php82/ | wc -l 2>/dev/null
ls /tmp/sess_* 2>/dev/null | wc -l

The fix

The decision and implementation:

  1. Stay with cPanel’s secure /tmp default if disk IO is not a bottleneck. Check iostat -xz 1 10 — if %util on the disk holding /tmp is low, tmpfs is not needed.

  2. Move to tmpfs if disk IO is a bottleneck. Size to 2-4 GB depending on host RAM (do not exceed 25% of total RAM).

    In /etc/fstab:

    tmpfs /tmp tmpfs defaults,noexec,nosuid,size=4G,mode=1777 0 0

    To switch live (carefully):

    /usr/local/cpanel/scripts/securetmp --umount
    mount -t tmpfs -o defaults,noexec,nosuid,size=4G,mode=1777 tmpfs /tmp

    Some services (cpanel, mysql) may need a restart to pick up the new mount.

  3. Configure MySQL tmpdir explicitly so MySQL knows it is on tmpfs:

    [mysqld]
    tmpdir = /tmp

    And, ideally, move large temp tables to a different location (/var/lib/mysql-tmp/ on disk) with slave_load_tmpdir. Otherwise a single big GROUP BY query can blow the tmpfs.

  4. Monitor /tmp pressure after switch. df -h /tmp over the next week. If it nears full during normal load, increase the size or fix the abusive process.

  5. Move PHP sessions out of /tmp entirely. Redis or Memcached for sessions removes the largest /tmp churn source. Pair with tmpfs and you get both wins.

For most cPanel hosts on NVMe storage, the disk-backed default is fast enough and tmpfs is not worth the operational risk. For older hosts on SATA SSD or HDD, tmpfs is a real improvement. Stack Harbor sizes /tmp per host as part of cPanel/WHM management.