Jump to content

tmpfs

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Dsimic (talk | contribs) at 16:24, 4 July 2016 (± 2 categories using HotCat). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

tmpfs is a common name for a temporary file storage facility on many Unix-like operating systems. It is intended to appear as a mounted file system, but stored in volatile memory instead of a persistent storage device. A similar construction is a RAM disk, which appears as a virtual disk drive and hosts a disk file system.

Semantics

Everything stored in tmpfs is temporary in the sense that no files will be created on the hard drive; however, swap space is used as backing store in case of low memory situations. On reboot, everything in tmpfs will be lost.

The memory used by tmpfs grows and shrinks to accommodate the files it contains and can be swapped out to swap space.

Many Unix distributions enable and use tmpfs by default for the /tmp branch of the file system or for shared memory. This can be observed with df as in this example:

Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 256M  688K  256M   1%  /tmp

On some Linux distributions (e.g. Debian, Ubuntu), /tmp is a normal directory, but /dev/shm uses tmpfs.

Implementations

SunOS/Solaris

SunOS 4 includes what is most likely the earliest implementation of tmpfs; it first appeared in SunOS 4.0 in late 1987, together with new orthogonal address space management that allowed any object to be memory mapped.[1][2]

The Solaris /tmp directory was made a tmpfs file system by default starting with Solaris 2.1,[citation needed] released in December 1992.[3] Output for the Solaris df command will show swap as the background storage for any tmpfs volume:

 # df -k
 Filesystem  kbytes  used   avail capacity  Mounted on
 swap        601592     0  601592     0%    /tmp/test

Linux

tmpfs is supported by the Linux kernel from version 2.4 and up.[4] tmpfs (previously known as shmfs) is based on the ramfs code used during bootup and also uses the page cache, but unlike ramfs it supports swapping out less-used pages to swap space as well as filesystem size and inode limits to prevent out of memory situations (defaulting to half of physical RAM and half the number of RAM pages, respectively).[5]

BSD

4.2BSD introduced MFS,[6] a memory-based file system implemented by applying the existing FFS disk filesystem to a virtual memory region.

tmpfs, a memory filesystem implemented using conventional in-memory data structures in order to improve on the performance of MFS, was merged into the official NetBSD source tree on September 10, 2005;[7] it is available in 4.0 and later versions.

FreeBSD has ported NetBSD's implementation, where it is available in 7.0 and later versions.[8]

DragonFly BSD has also ported NetBSD's implementation, where it is available in 2.5.1 and later versions.

OpenBSD ported NetBSD's tmpfs implementation as well, initially started by Pedro Martelletto and improved by many others. It has got linked to build on December 17, 2013.[9] The first release of OpenBSD with tmpfs included was 5.5.[10]

References

  1. ^ Peter Snyder. "tmpfs: A Virtual Memory File System" (PDF). Retrieved 2007-05-07.
  2. ^ Hal L. Stern. "SunOS 4.1 Performance Tuning" (GZipped PostScript). Retrieved 2007-05-07.
  3. ^ "Solaris Operating System (Unix)". operating-system.org.
  4. ^ Daniel Robbins (2001-09-01). "Common threads: Advanced filesystem implementor's guide, Part 3". IBM DeveloperWorks. Retrieved 2013-02-15. Article describing the Linux implementation
  5. ^ Christoph Rohland; Hugh Dickins; KOSAKI Motohiro. "tmpfs.txt". kernel.org. Retrieved 2010-03-16.
  6. ^ "NetBSD mount_mfs(8) man page". 2007-12-08. Retrieved 2013-02-15.
  7. ^ Julio M. Merino Vidal (2006-02-24). "NetBSD-SoC: Efficient memory file-system". Retrieved 2013-02-15.
  8. ^ Xin LI (2013-04-23). "FreeBSD tmpfs(5) manpage". Retrieved 2008-12-02.
  9. ^ "CVS: cvs.openbsd.org: src - enable tmpfs so it gets tested some more".
  10. ^ "OpenBSD 5.5". 2014-05-01. Retrieved 2014-05-01.