1 Tmpfs is a file system which keeps all files in virtual memory.
4 Everything in tmpfs is temporary in the sense that no files will be
5 created on your hard drive. If you unmount a tmpfs instance,
6 everything stored therein is lost.
8 tmpfs puts everything into the kernel internal caches and grows and
9 shrinks to accommodate the files it contains and is able to swap
10 unneeded pages out to swap space. It has maximum size limits which can
11 be adjusted on the fly via 'mount -o remount ...'
13 If you compare it to ramfs (which was the template to create tmpfs)
14 you gain swapping and limit checking. Another similar thing is the RAM
15 disk (/dev/ram*), which simulates a fixed size hard disk in physical
16 RAM, where you have to create an ordinary filesystem on top. Ramdisks
17 cannot swap and you do not have the possibility to resize them.
19 Since tmpfs lives completely in the page cache and on swap, all tmpfs
20 pages currently in memory will show up as cached. It will not show up
21 as shared or something like that. Further on you can check the actual
22 RAM+swap use of a tmpfs instance with df(1) and du(1).
25 tmpfs has the following uses:
27 1) There is always a kernel internal mount which you will not see at
28 all. This is used for shared anonymous mappings and SYSV shared
31 This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
32 set, the user visible part of tmpfs is not build. But the internal
33 mechanisms are always present.
35 2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
36 POSIX shared memory (shm_open, shm_unlink). Adding the following
37 line to /etc/fstab should take care of this:
39 tmpfs /dev/shm tmpfs defaults 0 0
41 Remember to create the directory that you intend to mount tmpfs on
42 if necessary (/dev/shm is automagically created if you use devfs).
44 This mount is _not_ needed for SYSV shared memory. The internal
45 mount is used for that. (In the 2.3 kernel versions it was
46 necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
49 3) Some people (including me) find it very convenient to mount it
50 e.g. on /tmp and /var/tmp and have a big swap partition. But be
51 aware: loop mounts of tmpfs files do not work due to the internal
52 design. So mkinitrd shipped by most distributions will fail with a
55 4) And probably a lot more I do not know about :-)
58 tmpfs has a couple of mount options:
60 size: The limit of allocated bytes for this tmpfs instance. The
61 default is half of your physical RAM without swap. If you
62 oversize your tmpfs instances the machine will deadlock
63 since the OOM handler will not be able to free that memory.
64 nr_blocks: The same as size, but in blocks of PAGECACHE_SIZE.
65 nr_inodes: The maximum number of inodes for this instance. The default
66 is half of the number of your physical RAM pages.
68 These parameters accept a suffix k, m or g for kilo, mega and giga and
69 can be changed on remount.
71 To specify the initial root directory you can use the following mount
74 mode: The permissions as an octal number
78 These options do not have any effect on remount. You can change these
79 parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.
82 So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs'
83 will give you tmpfs instance on /mytmpfs which can allocate 10GB
84 RAM/SWAP in 10240 inodes and it is only accessible by root.
89 1) give the size option a percent semantic: If you give a mount option
90 size=50% the tmpfs instance should be able to grow to 50 percent of
91 RAM + swap. So the instance should adapt automatically if you add
93 2) loop mounts: This is difficult since loop.c relies on the readpage
94 operation. This operation gets a page from the caller to be filled
95 with the content of the file at that position. But tmpfs always has
96 the page and thus cannot copy the content to the given page. So it
97 cannot provide this operation. The VM had to be changed seriously
99 3) Show the number of tmpfs RAM pages. (As shared?)
102 Christoph Rohland <cr@sap.com>, 1.12.01