Skip to content

Commit 7fb6eca

Browse files
mcgrofBrian Maly
authored andcommitted
shmem: update documentation
Update the docs to reflect a bit better why some folks prefer tmpfs over ramfs and clarify a bit more about the difference between brd ramdisks. While at it, add THP docs for tmpfs, both the mount options and the sysfs file. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Luis Chamberlain <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Tested-by: Xin Hao <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Cc: Adam Manzanares <[email protected]> Cc: Davidlohr Bueso <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Kees Cook <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Pankaj Raghav <[email protected]> Cc: Yosry Ahmed <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit d0f5a85) Orabug: 38034039 Reviewed-by: Anthony Yznaga <[email protected]> Reviewed-by: Junxiao Bi <[email protected]> Signed-off-by: Stephen Brennan <[email protected]> Signed-off-by: Brian Maly <[email protected]>
1 parent 27e1695 commit 7fb6eca

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

Documentation/filesystems/tmpfs.rst

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,25 @@ everything stored therein is lost.
1313

1414
tmpfs puts everything into the kernel internal caches and grows and
1515
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.
2435

2536
Since tmpfs lives completely in the page cache and on swap, all tmpfs
2637
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
8596
use up all the memory on the machine; but enhances the scalability of
8697
that instance in a system with many CPUs making intensive use of it.
8798

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+
== ============================================================
88129

89130
tmpfs has a mount option to set the NUMA memory allocation policy for
90131
all files in that instance (if CONFIG_NUMA is enabled) - which can be

0 commit comments

Comments
 (0)