tmpfs (short for Temporary File System) is a
temporary file
A temporary file is a file created to store information temporarily, either for a program's intermediate use or for transfer to a permanent file when complete. It may be created by computer programs for a variety of purposes, such as when a progra ...
storage paradigm implemented in many
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
operating systems. It is intended to appear as a mounted
file system, but data is stored in
volatile memory
Volatile memory, in contrast to non-volatile memory, is computer memory that requires power to maintain the stored information; it retains its contents while powered on but when the power is interrupted, the stored data is quickly lost.
Volatile ...
instead of a persistent storage device.
The idea behind tmpfs is similar in concept to a
RAM disk
A RAM drive (also called a RAM disk) is a block of random-access memory ( primary storage or volatile memory) that a computer's software is treating as if the memory were a disk drive (secondary storage). RAM drives provide high-performance te ...
, in that both provide a file system stored in volatile memory; however, the implementations are different. While tmpfs is implemented at the ''logical file system'' layer, a RAM disk is implemented at the ''
physical file system'' layer. In other words, a RAM disk is a virtual block device with a normal file system running on top of it, while tmpfs is a virtual file system without any underlying block device.
Semantics
Everything stored in tmpfs is temporary in the sense that no files will be directly created on
non-volatile storage
Non-volatile memory (NVM) or non-volatile storage is a type of computer memory that can retain stored information even after power is removed. In contrast, volatile memory needs constant power in order to retain data.
Non-volatile memory typ ...
such as a
hard drive
A hard disk drive (HDD), hard disk, hard drive, or fixed disk is an electro-mechanical data storage device that stores and retrieves digital data using magnetic storage with one or more rigid rapidly rotating hard disk drive platter, pla ...
(although
swap space is used as backing store according to the
page replacement policy of the operating system). On
reboot
In computing, rebooting is the process by which a running computer system is restarted, either intentionally or unintentionally. Reboots can be either a cold reboot (alternatively known as a hard reboot) in which the power to the system is physi ...
, everything in tmpfs will be lost.
The memory used by tmpfs grows and shrinks to accommodate the files it contains.
Many Unix
distribution Distribution may refer to:
Mathematics
*Distribution (mathematics), generalized functions used to formulate solutions of partial differential equations
*Probability distribution, the probability of a particular value or value range of a varia ...
s enable and use tmpfs by default for the branch of the file system or for
shared memory. This can be observed with as in this example:
Filesystem 1K-blocks Used Available Use% Mounted on
tmpfs 1686428 0 1686428 0% /dev/shm
tmpfs 674572 1808 672764 1% /run
tmpfs 1024 0 1024 0% /run/credentials/systemd-journald.service
tmpfs 1686428 1628 1684800 1% /tmp
tmpfs 1024 0 1024 0% /run/credentials/
[email protected]
tmpfs 1024 0 1024 0% /run/credentials/
[email protected]
tmpfs 337284 32 337252 1% /run/user/0
tmpfs 1024 0 1024 0% /run/credentials/
[email protected]
tmpfs 337284 280464 56820 84% /run/user/1000
Some Linux distributions (e.g.
Debian
Debian () is a free and open-source software, free and open source Linux distribution, developed by the Debian Project, which was established by Ian Murdock in August 1993. Debian is one of the oldest operating systems based on the Linux kerne ...
) do not have a tmpfs mounted on by default; in this case, files under will be stored in the same file system as .
And on almost all Linux distributions, a tmpfs is mounted on or to store temporary run-time files such as
PID files and
Unix domain sockets.
Implementations
There are several independent variants of the tmpfs concept. One of the earliest was developed by
Sun Microsystems
Sun Microsystems, Inc., often known as Sun for short, was an American technology company that existed from 1982 to 2010 which developed and sold computers, computer components, software, and information technology services. Sun contributed sig ...
for SunOS, and other operating systems like the BSDs and Linux provided their own.
SunOS
SunOS
SunOS is a Unix-branded operating system developed by Sun Microsystems for their workstation and server computer systems from 1982 until the mid-1990s. The ''SunOS'' name is usually only used to refer to versions 1.0 to 4.1.4, which were based ...
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.
The
Solaris directory was made a tmpfs file system by default starting with Solaris 2.1, released in December 1992. Output for the Solaris 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
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
beginning in version 2.4 (January 4, 2001). Linux tmpfs (previously known as shm fs)
is based on the ramfs code used during bootup and also uses the
page cache
In computing, a page cache, sometimes also called disk cache, is a transparent cache for the pages originating from a secondary storage device such as a hard disk drive (HDD) or a solid-state drive (SSD). The operating system keeps a page ca ...
, 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
Out of memory (OOM) is an often undesired state of computer operation where no additional memory can be allocated for use by programs or the operating system. Such a system will be unable to load any additional programs, and since many programs ...
situations (defaulting to half of physical RAM and half the number of RAM pages, respectively).
BSD
4.2BSD introduced MFS, 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
NetBSD is a free and open-source Unix-like operating system based on the Berkeley Software Distribution (BSD). It was the first open-source BSD descendant officially released after 386BSD was fork (software development), forked. It continues to ...
source tree on September 10, 2005; it is available in 4.0 and later versions.
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
has ported NetBSD's implementation, where it is available in 7.0 and later versions.
DragonFly BSD
DragonFly BSD is a free and open-source Unix-like operating system forked from FreeBSD 4.8. Matthew Dillon, an Amiga developer in the late 1980s and early 1990s and FreeBSD developer between 1994 and 2003, began working on DragonFly BSD in ...
has also ported NetBSD's implementation, where it is available in 2.5.1 and later versions.
OpenBSD
OpenBSD is a security-focused operating system, security-focused, free software, Unix-like operating system based on the Berkeley Software Distribution (BSD). Theo de Raadt created OpenBSD in 1995 by fork (software development), forking NetBSD ...
ported NetBSD's tmpfs implementation as well, initially started by Pedro Martelletto and improved by many others. It was enabled in builds from December 17, 2013. The first release of OpenBSD with tmpfs included was 5.5. OpenBSD 6.0 disabled tmpfs due to lack of maintenance.
Microsoft Windows
In
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
, creating files using the flag will cause file systems to avoid writing data back to non-volatile storage if sufficient cache memory is available.
Advantages
Due to the higher speeds of RAM compared to disk storage, tmpfs allows
cache to be much faster when stored in one, leading to a more efficient overall system, though operating systems with a
page cache
In computing, a page cache, sometimes also called disk cache, is a transparent cache for the pages originating from a secondary storage device such as a hard disk drive (HDD) or a solid-state drive (SSD). The operating system keeps a page ca ...
will see less benefit as recently-used file pages will remain in-memory if free memory is sufficient. Since RAM is cleared upon reboot, tmpfs prevents systems from becoming too cluttered without requiring that the user manually delete temporary files. In addition, storing files in RAM prevents disks from filling up too quickly and extends the life of
flash-based storage by reducing the number of writes.
Disadvantages
On systems without
swap space, or where swap space is running low, tmpfs may consume large amounts of memory.
If cache files are stored in tmpfs, programs will lose their cached data across reboots.
References
External links
*
*
{{File systems
Special-purpose file systems
Special-purpose file systems supported by the Linux kernel
Computer-related introductions in 1987
Linux kernel features