Field of application
- For services with a regular write temporary pattern of small files that are cleaned up after usage,
it is good practice to use a tmpfs in /tmp.
Be default the size of the tmpfs is limited to 50% of the total main RAM size=50%. but tmpfs utilizes the whole virtual memory (RAM+swap).
- Without tmpfs files would be written to disk, which is extremly slow compared to RAM. If the space in the tmpfs is short data is swapped (governed by the Least Recently Used Scheduler (LRU)). It is written to to disk as if tmpfs was not mounted, but in another partition (swap). But in the case that enough RAM is available, disk-IO is reduced and a lot of performance has been gained.
- Especially in Storage Area Networks (SAN) it is a considerable strategy to avoid disk-io and stress to shared resources. Still, care has to be taken, that the swap space is not exhausted.
- ramfs, but no swapping and no limit checking
- ramdisk, but no swapping and not resizable
tmpfs prior to systemd
Prior to jessie and systemd with it's generators, tmpfs was managed (on Debian) via static fstab entries or a SystemV init-script, which as managed by
1 # Configuration for tmpfs filesystems mounted in early boot, before 2 # filesystems from /etc/fstab are mounted. For information about 3 # these variables see the tmpfs(5) manual page. 4 5 # /run is always mounted as a tmpfs on systems which support tmpfs 6 # mounts. 7 8 # mount /run/lock as a tmpfs (separately from /run). Defaults to yes; 9 # set to no to disable (/run/lock will then be part of the /run tmpfs, 10 # if available). 11 #RAMLOCK=yes 12 13 # mount /run/shm as a tmpfs (separately from /run). Defaults to yes; 14 # set to no to disable (/run/shm will then be part of the /run tmpfs, 15 # if available). 16 #RAMSHM=yes 17 18 # mount /tmp as a tmpfs. Defaults to no; set to yes to enable (/tmp 19 # will be part of the root filesystem if disabled). /tmp may also be 20 # configured to be a separate mount in /etc/fstab. 21 RAMTMP=yes 22 23 # Size limits. Please see tmpfs(5) for details on how to configure 24 # tmpfs size limits. 25 #TMPFS_SIZE=20%VM 26 #RUN_SIZE=10% 27 #LOCK_SIZE=5242880 # 5MiB 28 #SHM_SIZE= 29 #TMP_SIZE= 30 31 # Mount tmpfs on /tmp if there is less than the limit size (in kiB) on 32 # the root filesystem (overriding RAMTMP). 33 #TMP_OVERFLOW_LIMIT=1024 34
tmpfs with systemd
Starting with jessie and systemd, generators derive .mount units from the static entries in /etc/fstab. The config file /etc/default/tmpfs is no longer honored. Options have to be present in /etc/fstab.
1 # /etc/fstab: static file system information. 2 # 3 # Use 'blkid' to print the universally unique identifier for a 4 # device; this may be used with UUID= as a more robust way to name devices 5 # that works even if disks are added and removed. See fstab(5). 6 # 7 #<file_system> <mount_point> <type> <options> <dump> <pass> 8 UUID=42908876-b15a-4e63-b350-214ac9300d8f / xfs noatime 0 0 9 UUID=8197d880-3059-4e39-89ea-3796146ac244 none swap sw 0 0 10 tmpfs /tmp tmpfs nosuid,nodev,noexec,mode=1777,huge=within_size 0 0 11 tmpfs /dev/shm tmpfs nosuid,nodev,noexec,mode=1777,huge=within_size 0 0 12 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
On every boot systemd-generators create and renew dynamic .mount-units.
Mount-units may be handled like other units in SystemD (enabled, disabled, shown, masked, …)
Live remount to change mount options
1 mount -o remount,size=60% /tmp