Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

tmpfs

From Wikipedia, the free encyclopedia
Temporary file system on Unix-like systems

tmpfs (short fortemporary file system) is atemporary file storage paradigm implemented in manyUnix-like operating systems. It is intended to appear as a mountedfile system, but data is stored involatile memory rather than on a persistent storage device.

The idea behind tmpfs is similar to that of aRAM disk, in that both provide a file system stored in volatile memory; however, the implementations differ. While tmpfs is implemented at thelogical file system layer, a RAM disk is implemented at thephysical 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

[edit]

Everything stored in tmpfs is temporary in the sense that no files will be directly created onnon-volatile storage such as ahard drive (althoughswap space is used as backing store according to thepage replacement policy of the operating system). Onreboot, everything in tmpfs will be lost.

The memory used by tmpfs grows and shrinks to accommodate the files it contains.

Many Unixdistributions enable and use tmpfs by default for the/tmp branch of the file system or forshared memory. This can be observed withdf 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/getty@tty1.service tmpfs               1024      0      1024   0% /run/credentials/getty@tty3.service tmpfs             337284     32    337252   1% /run/user/0 tmpfs               1024      0      1024   0% /run/credentials/getty@tty4.service tmpfs             337284 280464     56820  84% /run/user/1000

Some Linux distributions (e.g.Debian until Debian 13[1]) do not have a tmpfs mounted on/tmp by default; in this case, files under/tmp will be stored in the same file system as/.

On almost all Linux distributions[citation needed], a tmpfs is mounted on/run/ or/var/run/ to store temporary run-time files such asPID files andUnix domain sockets.

Implementations

[edit]

There are several independent variants of the tmpfs concept. One of the earliest was developed bySun Microsystems for SunOS, and other operating systems, such as the BSDs and Linux, provided their own.

SunOS

[edit]

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.[2][3]

TheSolaris/tmp directory was made a tmpfs file system by default starting with Solaris 2.1,[4] released in December 1992.[5] Output for the Solarisdf command will showswap as the background storage for any tmpfs volume:

#df-kFilesystem  kbytes  used   avail capacity  Mounted onswap        601592     0  601592     0%    /tmp/test

Linux

[edit]

tmpfs is supported by theLinux kernel beginning in version 2.4 (January 4, 2001).[6] Linux tmpfs (previously known asshm fs)[7] is based on the ramfs code used during bootup and also uses thepage cache, but, unlike ramfs, it supports swapping out less-used pages to swap space, as well as filesystem size and inode limits to preventout-of-memory situations (defaulting to half of physical RAM and half the number of RAM pages, respectively).[8]

BSD

[edit]

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

tmpfs, a memory filesystem implemented using conventional in-memory data structures to improve on the performance of MFS, was merged into the officialNetBSD source tree on September 10, 2005;[10] 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.[11]

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 was enabled in builds from December 17, 2013.[12] The first release of OpenBSD with tmpfs included was 5.5.[13] OpenBSD 6.0 disabled tmpfs due to lack of maintenance.

Advantages

[edit]

Due to the higher speeds of RAM compared to disk storage, tmpfs allowscache to be much faster when stored in one, leading to a more efficient overall system, though operating systems with apage cache 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 users to delete temporary files manually. In addition, storing files in RAM prevents disks from filling up too quickly and extends the life offlash-based storage by reducing write operations.

Disadvantages

[edit]

On systems withoutswap 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

[edit]
  1. ^Brockmeier, Joe (2024-06-03)."Debian's /tmpest in a teapot".LWN.net. Retrieved2025-08-29.
  2. ^Peter Snyder."tmpfs: A Virtual Memory File System"(PDF). Archived fromthe original(PDF) on 2025-03-11. Retrieved2007-05-07.
  3. ^Hal L. Stern."SunOS 4.1 Performance Tuning". Archived fromthe original(GZipped PostScript) on 2012-02-07. Retrieved2007-05-07.
  4. ^"SPARC: Installing Solaris Software"(PDF). SunSoft. December 1992. p. 9. RetrievedApril 23, 2019.
  5. ^"Solaris Operating System (Unix)".operating-system.org.
  6. ^Daniel Robbins (2001-09-01)."Common threads: Advanced filesystem implementor's guide, Part 3". IBM DeveloperWorks. Archived fromthe original on 2012-02-03. Retrieved2013-02-15.
  7. ^Daniel Robbins (2001-09-01)."Common threads: Advanced filesystem implementor's guide, Part 3". IBM DeveloperWorks. Archived fromthe original on 2012-02-03. Retrieved2013-02-15.
  8. ^Christoph Rohland; Hugh Dickins; KOSAKI Motohiro."tmpfs.txt".kernel.org. Retrieved2010-03-16.
  9. ^"NetBSD mount_mfs(8) man page". 2007-12-08. Archived fromthe original on 2016-04-16. Retrieved2013-02-15.
  10. ^Julio M. Merino Vidal (2006-02-24)."NetBSD-SoC: Efficient memory file-system". Retrieved2013-02-15.
  11. ^Xin LI (2013-04-23)."FreeBSD tmpfs(5) manpage". Retrieved2008-12-02.
  12. ^"CVS: cvs.openbsd.org: src - enable tmpfs so it gets tested some more".
  13. ^"OpenBSD 5.5". 2014-05-01. Retrieved2014-05-01.

External links

[edit]
Disk and
non-rotating
Optical disc
Flash memory andSSD
host-sidewear leveling
Distributed parallel
NAS
Specialized
Pseudo
Encrypted
Types
Features
Access control
Interfaces
Lists
Layouts
Retrieved from "https://en.wikipedia.org/w/index.php?title=Tmpfs&oldid=1334252796"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp