tmpfs ability to shrink and expand
From: Ritesh Raj Sarraf
Date: Sun Jul 24 2016 - 14:38:44 EST
-----BEGIN PGP SIGNED MESSAGE-----
I am writing to you because you are listed as Maintainers for the tmpfs file
system in the Linux kernel.
Recently, I have had a bug in a general purpose application, where it ran out of
space in $TMPDIR. As is common, these days, most people vote for /tmp on tmpfs,
for obviously good reasons (performance, efficiency etc).
On bringing this bug, and the topic of "TMPDIR on tmpfs" on Debian-Devel,
there's one comment which wasn't clear to me. Hence this email to you.
Even in the description below about tmpfs, it says, "..... to accommodate the
files it contains and is able to swap unneeded pages out to swap space."
When we say "swap unneeded pages out to swap space", as I understand, what is
being referred as "Swappable" here is any process in the kernel's namespace. And
not referring to processes associated with /tmp ? Because those mostly will be
The way I observed, it looks like whatever "/tmp on tmpfs" is capped at, from
the VFS point of view, is the standard limit for processes accessing files in
/tmp. And that file system view and limitations won't change (in effect to other
processes being swapped or not).
Consider this example:
rrs@chutzpah:~$ df -h /tmp/
FilesystemÂÂÂÂÂÂSizeÂÂUsed Avail Use% Mounted on
rrs@chutzpah:~$ dd if=/dev/zero of=/tmp/foo.img bs=1M count=4000
dd: error writing '/tmp/foo.img': No space left on device
3691+0 records in
3690+0 records out
3869605888 bytes (3.9 GB, 3.6 GiB) copied, 1.12808 s, 3.4 GB/s
rrs@chutzpah:~$ free -m
Here's the description of tmpfs from the latest
Tmpfs is a file system which keeps all files in virtual memory.
Everything in tmpfs is temporary in the sense that no files will be
created on your hard drive. If you unmount a tmpfs instance,
everything stored therein is lost.
tmpfs puts everything into the kernel internal caches and grows and
shrinks to accommodate the files it contains and is able to swap
unneeded pages out to swap space. It has maximum size limits which can
be adjusted on the fly via 'mount -o remount ...'
If you compare it to ramfs (which was the template to create tmpfs)
you gain swapping and limit checking. Another similar thing is the RAM
disk (/dev/ram*), which simulates a fixed size hard disk in physical
RAM, where you have to create an ordinary filesystem on top. Ramdisks
cannot swap and you do not have the possibility to resize them.Â
Since tmpfs lives completely in the page cache and on swap, all tmpfs
pages will be shown as "Shmem" in /proc/meminfo and "Shared" in
free(1). Notice that these counters also include shared memory
(shmem, see ipcs(1)). The most reliable way to get the count is
using df(1) and du(1).
Ritesh Raj Sarraf | http://people.debian.org/~rrs
Debian - The Universal Operating System
-----BEGIN PGP SIGNATURE-----
-----END PGP SIGNATURE-----