@@ -13,14 +13,25 @@ everything stored therein is lost.
13
13
14
14
tmpfs puts everything into the kernel internal caches and grows and
15
15
shrinks to accommodate the files it contains and is able to swap
16
- unneeded pages out to swap space. It has maximum size limits which can
17
- be adjusted on the fly via 'mount -o remount ...'
18
-
19
- If you compare it to ramfs (which was the template to create tmpfs)
20
- you gain swapping and limit checking. Another similar thing is the RAM
21
- disk (/dev/ram*), which simulates a fixed size hard disk in physical
22
- RAM, where you have to create an ordinary filesystem on top. Ramdisks
23
- cannot swap and you do not have the possibility to resize them.
16
+ unneeded pages out to swap space, and supports THP.
17
+
18
+ tmpfs extends ramfs with a few userspace configurable options listed and
19
+ explained further below, some of which can be reconfigured dynamically on the
20
+ fly using a remount ('mount -o remount ...') of the filesystem. A tmpfs
21
+ filesystem can be resized but it cannot be resized to a size below its current
22
+ usage. tmpfs also supports POSIX ACLs, and extended attributes for the
23
+ trusted.* and security.* namespaces. ramfs does not use swap and you cannot
24
+ modify any parameter for a ramfs filesystem. The size limit of a ramfs
25
+ filesystem is how much memory you have available, and so care must be taken if
26
+ used so to not run out of memory.
27
+
28
+ An alternative to tmpfs and ramfs is to use brd to create RAM disks
29
+ (/dev/ram*), which allows you to simulate a block device disk in physical RAM.
30
+ To write data you would just then need to create an regular filesystem on top
31
+ this ramdisk. As with ramfs, brd ramdisks cannot swap. brd ramdisks are also
32
+ configured in size at initialization and you cannot dynamically resize them.
33
+ Contrary to brd ramdisks, tmpfs has its own filesystem, it does not rely on the
34
+ block layer at all.
24
35
25
36
Since tmpfs lives completely in the page cache and on swap, all tmpfs
26
37
pages will be shown as "Shmem" in /proc/meminfo and "Shared" in
@@ -85,6 +96,36 @@ mount with such options, since it allows any user with write access to
85
96
use up all the memory on the machine; but enhances the scalability of
86
97
that instance in a system with many CPUs making intensive use of it.
87
98
99
+ tmpfs also supports Transparent Huge Pages which requires a kernel
100
+ configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge supported for
101
+ your system (has_transparent_hugepage(), which is architecture specific).
102
+ The mount options for this are:
103
+
104
+ ====== ============================================================
105
+ huge=0 never: disables huge pages for the mount
106
+ huge=1 always: enables huge pages for the mount
107
+ huge=2 within_size: only allocate huge pages if the page will be
108
+ fully within i_size, also respect fadvise()/madvise() hints.
109
+ huge=3 advise: only allocate huge pages if requested with
110
+ fadvise()/madvise()
111
+ ====== ============================================================
112
+
113
+ There is a sysfs file which you can also use to control system wide THP
114
+ configuration for all tmpfs mounts, the file is:
115
+
116
+ /sys/kernel/mm/transparent_hugepage/shmem_enabled
117
+
118
+ This sysfs file is placed on top of THP sysfs directory and so is registered
119
+ by THP code. It is however only used to control all tmpfs mounts with one
120
+ single knob. Since it controls all tmpfs mounts it should only be used either
121
+ for emergency or testing purposes. The values you can set for shmem_enabled are:
122
+
123
+ == ============================================================
124
+ -1 deny: disables huge on shm_mnt and all mounts, for
125
+ emergency use
126
+ -2 force: enables huge on shm_mnt and all mounts, w/o needing
127
+ option, for testing
128
+ == ============================================================
88
129
89
130
tmpfs has a mount option to set the NUMA memory allocation policy for
90
131
all files in that instance (if CONFIG_NUMA is enabled) - which can be
0 commit comments