1.\"- 2.\" Copyright (c) 2007 Xin LI 3.\" Copyright (c) 2017 The FreeBSD Foundation, Inc. 4.\" 5.\" Part of this documentation was written by 6.\" Konstantin Belousov <kib@FreeBSD.org> under sponsorship 7.\" from the FreeBSD Foundation. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS DOCUMENTATION IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28.\" 29.\"- 30.\" Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. 31.\" All rights reserved. 32.\" 33.\" Redistribution and use in source and binary forms, with or without 34.\" modification, are permitted provided that the following conditions 35.\" are met: 36.\" 1. Redistributions of source code must retain the above copyright 37.\" notice, this list of conditions and the following disclaimer. 38.\" 2. Redistributions in binary form must reproduce the above copyright 39.\" notice, this list of conditions and the following disclaimer in the 40.\" documentation and/or other materials provided with the distribution. 41.\" 42.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 43.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 44.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 45.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 46.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 47.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 48.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 49.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 52.\" POSSIBILITY OF SUCH DAMAGE. 53.\" 54.Dd September 18, 2023 55.Dt TMPFS 4 56.Os 57.Sh NAME 58.Nm tmpfs 59.Nd "in-memory file system" 60.Sh SYNOPSIS 61To compile this driver into the kernel, 62place the following line in your 63kernel configuration file: 64.Bd -ragged -offset indent 65.Cd "options TMPFS" 66.Ed 67.Pp 68Alternatively, to load the driver as a 69module at boot time, place the following line in 70.Xr loader.conf 5 : 71.Bd -literal -offset indent 72tmpfs_load="YES" 73.Ed 74.Sh DESCRIPTION 75The 76.Nm 77driver implements an in-memory, or 78.Nm 79file system. 80The filesystem stores both file metadata and data in main memory. 81This allows very fast and low latency accesses to the data. 82The data is volatile. 83An umount or system reboot invalidates it. 84These properties make the filesystem's mounts suitable for fast 85scratch storage, like 86.Pa /tmp . 87.Pp 88If the system becomes low on memory and swap is configured 89.Po see 90.Xr swapon 8 Pc , 91the system can transfer file data to swap space, freeing memory 92for other needs. 93Metadata, including the directory content, is never swapped out by the 94current implementation. 95Keep this in mind when planning the mount limits, especially when expecting 96to place many small files on a tmpfs mount. 97.Pp 98When 99.Xr mmap 2 100is used on a file from a tmpfs mount, the swap VM object managing the 101file pages is used to implement mapping and avoid double-copying of 102the file data. 103This quirk causes process inspection tools, like 104.Xr procstat 1 , 105to report anonymous memory mappings instead of file mappings. 106.Sh OPTIONS 107The following options are available when 108mounting 109.Nm 110file systems: 111.Bl -tag -width "maxfilesize" 112.It Cm easize 113Set the maximum memory size used by extended attributes in bytes. 114The default is 16 megabytes. 115.It Cm export 116Accept the 117.Cm export 118option for compatibility with 119.Xr nfsv4 4 . 120This option does nothing. 121.It Cm gid 122Set the group ID of the root inode of the file system. 123The default is the mount point's GID. 124.It Cm inodes 125Set the maximum number of nodes available to the file system. 126If not specified, the file system chooses a reasonable maximum based on 127the file system size, which can be limited with the 128.Cm size 129option. 130.It Cm maxfilesize 131Set the maximum file size in bytes. 132The default is the maximum possible value. 133.It Cm mode 134Set the mode (in octal notation) of the root inode of the file system. 135The default is the mount point's mode. 136.It Cm nomtime 137Disable the tracking of mtime updates caused by writes to the 138shared mapped areas backed by 139.Nm 140files. 141This option removes periodic scans, 142which downgrade read-write-mapped pages to read-only to note the writes. 143.It Cm nonc 144Do not use namecache to resolve names to files for the created mount. 145This saves memory, but currently might impair scalability for highly 146used mounts on large machines. 147.It Cm nosymfollow 148Do not follow 149.Xr symlink 7 Ap s 150on the mounted file system. 151.It Cm pgread 152Enable pgcache read for the mount. 153.It Cm size 154Set the total file system size in bytes, unless suffixed 155with one of k, m, g, t, or p, which denote byte, kilobyte, 156megabyte, gigabyte, terabyte and petabyte respectively. 157If zero (the default) or a value larger than SIZE_MAX - PAGE_SIZE 158is given, the available amount of memory (including 159main memory and swap space) will be used. 160.It Cm uid 161Set the user ID of the root inode of the file system. 162The default is the mount point's UID. 163.It Cm union 164Refer to 165.Xr mount 8 . 166.El 167.Sh SYSCTL VARIABLES 168The following 169.Xr sysctl 8 170variables are available: 171.Bl -tag -width indent 172.It Va vfs.tmpfs.memory_percent 173The percentage of memory plus swap space available at kernel file system 174initialization that can be used by a file system with a size of 0. 175When this amount of space in use is reached, new files cannot be created 176and files cannot be extended. 177The default is 95%. 178Changing this value also changes 179.Va vfs.tmpfs.memory_reserved . 180.It Va vfs.tmpfs.memory_reserved 181The currently-reserved amount of memory plus swap space 182based on the memory percentage. 183The minimum is compiled into the system, and defaults to 4 MB. 184.El 185.Sh EXAMPLES 186Mount a 187.Nm 188memory file system: 189.Pp 190.Dl "mount -t tmpfs tmpfs /tmp" 191.Pp 192Configure a 193.Nm 194mount via 195.Xr fstab 5 : 196.Bd -literal -offset indent 197tmpfs /tmp tmpfs rw 0 0 198.Ed 199.Sh SEE ALSO 200.Xr procstat 1 , 201.Xr mmap 2 , 202.Xr nmount 2 , 203.Xr unmount 2 , 204.Xr fstab 5 , 205.Xr mdmfs 8 , 206.Xr mount 8 , 207.Xr swapinfo 8 , 208.Xr swapon 8 209.Sh HISTORY 210The 211.Nm 212driver first appeared in 213.Fx 7.0 . 214.Sh AUTHORS 215.An -nosplit 216The 217.Nm 218kernel implementation was written by 219.An Julio M. Merino Vidal Aq Mt jmmv@NetBSD.org 220as a Google Summer of Code project. 221.Pp 222.An Rohit Jalan 223and others ported it from 224.Nx 225to 226.Fx . 227.Pp 228This manual page was written by 229.An Xin LI Aq Mt delphij@FreeBSD.org . 230