ArticleslgStudy

computer science

Tmpfs

Tmpfs is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Tmpfs rather than just read about it. In short: tmpfs (short for temporary file system) is a temporary file storage paradigm implemented in many Unix-like operating systems. It is intended to appear as a mounted file system, but data is stored in volatile memory rather than on a persistent storage device.

Key takeaways

  • Tmpfs belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Tmpfs to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Tmpfs from memory before moving on to harder problems.

Reference excerpt

tmpfs (short for temporary file system) is a temporary file storage paradigm implemented in many Unix-like operating systems. It is intended to appear as a mounted file system, but data is stored in volatile memory rather than on a persistent storage device. The idea behind tmpfs is similar to that of a RAM disk, in that both provide a file system stored in volatile memory; however, the implementations differ. 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 such as a hard drive (although swap space is used as backing store according to the page replacement policy of the operating system). On reboot, everything in tmpfs will be lost. The memory used by tmpfs grows and shrinks to accommodate the files it contains. 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 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) 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, a tmpfs is mounted on /run/ or /var/run/ 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 for SunOS, and other operating systems, such as the BSDs and Linux, provided their own.

SunOS 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. The Solaris /tmp directory was made a tmpfs file system by default starting with Solaris 2.1, released in December 1992. Output for the Solaris df command will show swap as the background storage for any tmpfs volume:

Linux tmpfs is supported by the Linux kernel 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, 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).

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 to improve on the performance of MFS, was merged into the official NetBSD source tree on September 10, 2005; 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. 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. The first release of OpenBSD with tmpfs included was 5.5. OpenBSD 6.0 disabled tmpfs due to lack of maintenance.

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 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 of flash-based storage by reducing write operations.

Disadvantages On systems without swap space, or where swap space is running low, tmpfs may consume large amounts of memory. In a Linux container with a memory limit, files stored in tmpfs count towards that limit, so a process writing to tmpfs can be stopped by the out-of-memory killer while the file system still reports free space. The memory stays in use until the files are deleted, even after the process that wrote them has exited. If cache files are stored in tmpfs, programs will lose their cached data across reboots.

References

External links "Solaris tmpfs(7FS) man page". Retrieved 2013-02-25. "Kernel.org tmpfs documentation". Retrieved 2015-10-05.

Worked examples

Example 1 — a first encounter with Tmpfs

Start with the simplest possible case. Write down what Tmpfs claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Tmpfs before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Tmpfs ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Tmpfs

In research
Tmpfs appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Tmpfs in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Tmpfs is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer-related introductions in 1987, Linux kernel features, Special-purpose file systems, so understanding it makes those chapters shorter.
In everyday life
Look for Tmpfs outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Tmpfs” →

How to study Tmpfs in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Tmpfs means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Tmpfs out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Tmpfs in simple terms?

tmpfs (short for temporary file system) is a temporary file storage paradigm implemented in many Unix-like operating systems. It is intended to appear as a mounted file system, but data is stored in volatile memory rather than on a persistent storage device.

Why does Tmpfs matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Tmpfs?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Tmpfs.

Tags

  • Computer-related introductions in 1987
  • Linux kernel features
  • Special-purpose file systems
  • Special-purpose file systems supported by the Linux kernel

Keep exploring