← Documents Documentation/filesystems/tmpfs.rst GitHub 원문 ↗

Linux 6.18.37 · Filesystems

Tmpfs

tmpfs 메모리 동작과 sizing·THP·quota·NUMA·casefold option의 전문 번역입니다.

Source pathDocumentation/filesystems/tmpfs.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

tmpfs.rst:1-276

tmpfs는 page cache와 선택적 swap에 file을 저장하는 동적 RAM 파일 시스템이다. size·block·inode 상한, noswap, THP, quota, NUMA policy, root metadata, inode 폭, UTF-8 casefold를 mount option으로 제어한다.

일부 option은 remount에서 바꿀 수 있지만 noswap의 최초 설정, quota 계열, 초기 root mode·uid·gid는 바꿀 수 없다. 무제한 size나 inode는 machine 전체 memory 소진 위험이 있어 운영 설정에서는 명시적 상한이 중요하다.

Tmpfs 자원 경로
tmpfs file 생성size·inode·quota 한도 검사NUMA·THP policy 적용page cache에 저장허용된 경우 memory pressure에서 swap out

file page가 memory pressure와 policy에 따라 배치된다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 =====
4 Tmpfs
5 =====
6
7 Tmpfs is a file system which keeps all of its files in virtual memory.
8
9
10 Everything in tmpfs is temporary in the sense that no files will be
11 created on your hard drive. If you unmount a tmpfs instance,
12 everything stored therein is lost.
13
14 tmpfs puts everything into the kernel internal caches and grows and
15 shrinks to accommodate the files it contains and is able to swap
16 unneeded pages out to swap space, if swap was enabled for the tmpfs
17 mount. tmpfs also supports THP.
18
19 tmpfs extends ramfs with a few userspace configurable options listed and
20 explained further below, some of which can be reconfigured dynamically on the
21 fly using a remount ('mount -o remount ...') of the filesystem. A tmpfs
22 filesystem can be resized but it cannot be resized to a size below its current
23 usage. tmpfs also supports POSIX ACLs, and extended attributes for the
24 trusted.*, security.* and user.* namespaces. ramfs does not use swap and you
25 cannot modify any parameter for a ramfs filesystem. The size limit of a ramfs
26 filesystem is how much memory you have available, and so care must be taken if
27 used so to not run out of memory.
28
29 An alternative to tmpfs and ramfs is to use brd to create RAM disks
30 (/dev/ram*), which allows you to simulate a block device disk in physical RAM.
31 To write data you would just then need to create an regular filesystem on top
32 this ramdisk. As with ramfs, brd ramdisks cannot swap. brd ramdisks are also
33 configured in size at initialization and you cannot dynamically resize them.
34 Contrary to brd ramdisks, tmpfs has its own filesystem, it does not rely on the
35 block layer at all.
36
37 Since tmpfs lives completely in the page cache and optionally on swap,
38 all tmpfs pages will be shown as "Shmem" in /proc/meminfo and "Shared" in
39 free(1). Notice that these counters also include shared memory
40 (shmem, see ipcs(1)). The most reliable way to get the count is
41 using df(1) and du(1).
42
43 tmpfs has the following uses:
44
45 1) There is always a kernel internal mount which you will not see at
46 all. This is used for shared anonymous mappings and SYSV shared
47 memory.
48
49 This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
50 set, the user visible part of tmpfs is not built. But the internal
51 mechanisms are always present.
52
53 2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
54 POSIX shared memory (shm_open, shm_unlink). Adding the following
55 line to /etc/fstab should take care of this::
56
57 tmpfs /dev/shm tmpfs defaults 0 0
58
59 Remember to create the directory that you intend to mount tmpfs on
60 if necessary.
61
62 This mount is _not_ needed for SYSV shared memory. The internal
63 mount is used for that. (In the 2.3 kernel versions it was
64 necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
65 shared memory.)
66
67 3) Some people (including me) find it very convenient to mount it
68 e.g. on /tmp and /var/tmp and have a big swap partition. And now
69 loop mounts of tmpfs files do work, so mkinitrd shipped by most
70 distributions should succeed with a tmpfs /tmp.
71
72 4) And probably a lot more I do not know about :-)
73
74
75 tmpfs has three mount options for sizing:
76
77 ========= ============================================================
78 size The limit of allocated bytes for this tmpfs instance. The
79 default is half of your physical RAM without swap. If you
80 oversize your tmpfs instances the machine will deadlock
81 since the OOM handler will not be able to free that memory.
82 nr_blocks The same as size, but in blocks of PAGE_SIZE.
83 nr_inodes The maximum number of inodes for this instance. The default
84 is half of the number of your physical RAM pages, or (on a
85 machine with highmem) the number of lowmem RAM pages,
86 whichever is the lower.
87 ========= ============================================================
88
89 These parameters accept a suffix k, m or g for kilo, mega and giga and
90 can be changed on remount. The size parameter also accepts a suffix %
91 to limit this tmpfs instance to that percentage of your physical RAM:
92 the default, when neither size nor nr_blocks is specified, is size=50%
93
94 If nr_blocks=0 (or size=0), blocks will not be limited in that instance;
95 if nr_inodes=0, inodes will not be limited. It is generally unwise to
96 mount with such options, since it allows any user with write access to
97 use up all the memory on the machine; but enhances the scalability of
98 that instance in a system with many CPUs making intensive use of it.
99
100 If nr_inodes is not 0, that limited space for inodes is also used up by
101 extended attributes: "df -i"'s IUsed and IUse% increase, IFree decreases.
102
103 tmpfs blocks may be swapped out, when there is a shortage of memory.
104 tmpfs has a mount option to disable its use of swap:
105
106 ====== ===========================================================
107 noswap Disables swap. Remounts must respect the original settings.
108 By default swap is enabled.
109 ====== ===========================================================
110
111 tmpfs also supports Transparent Huge Pages which requires a kernel
112 configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge supported for
113 your system (has_transparent_hugepage(), which is architecture specific).
114 The mount options for this are:
115
116 ================ ==============================================================
117 huge=never Do not allocate huge pages. This is the default.
118 huge=always Attempt to allocate huge page every time a new page is needed.
119 huge=within_size Only allocate huge page if it will be fully within i_size.
120 Also respect madvise(2) hints.
121 huge=advise Only allocate huge page if requested with madvise(2).
122 ================ ==============================================================
123
124 See also Documentation/admin-guide/mm/transhuge.rst, which describes the
125 sysfs file /sys/kernel/mm/transparent_hugepage/shmem_enabled: which can
126 be used to deny huge pages on all tmpfs mounts in an emergency, or to
127 force huge pages on all tmpfs mounts for testing.
128
129 tmpfs also supports quota with the following mount options
130
131 ======================== =================================================
132 quota User and group quota accounting and enforcement
133 is enabled on the mount. Tmpfs is using hidden
134 system quota files that are initialized on mount.
135 usrquota User quota accounting and enforcement is enabled
136 on the mount.
137 grpquota Group quota accounting and enforcement is enabled
138 on the mount.
139 usrquota_block_hardlimit Set global user quota block hard limit.
140 usrquota_inode_hardlimit Set global user quota inode hard limit.
141 grpquota_block_hardlimit Set global group quota block hard limit.
142 grpquota_inode_hardlimit Set global group quota inode hard limit.
143 ======================== =================================================
144
145 None of the quota related mount options can be set or changed on remount.
146
147 Quota limit parameters accept a suffix k, m or g for kilo, mega and giga
148 and can't be changed on remount. Default global quota limits are taking
149 effect for any and all user/group/project except root the first time the
150 quota entry for user/group/project id is being accessed - typically the
151 first time an inode with a particular id ownership is being created after
152 the mount. In other words, instead of the limits being initialized to zero,
153 they are initialized with the particular value provided with these mount
154 options. The limits can be changed for any user/group id at any time as they
155 normally can be.
156
157 Note that tmpfs quotas do not support user namespaces so no uid/gid
158 translation is done if quotas are enabled inside user namespaces.
159
160 tmpfs has a mount option to set the NUMA memory allocation policy for
161 all files in that instance (if CONFIG_NUMA is enabled) - which can be
162 adjusted on the fly via 'mount -o remount ...'
163
164 ======================== ==============================================
165 mpol=default use the process allocation policy
166 (see set_mempolicy(2))
167 mpol=prefer:Node prefers to allocate memory from the given Node
168 mpol=bind:NodeList allocates memory only from nodes in NodeList
169 mpol=interleave prefers to allocate from each node in turn
170 mpol=interleave:NodeList allocates from each node of NodeList in turn
171 mpol=local prefers to allocate memory from the local node
172 ======================== ==============================================
173
174 NodeList format is a comma-separated list of decimal numbers and ranges,
175 a range being two hyphen-separated decimal numbers, the smallest and
176 largest node numbers in the range. For example, mpol=bind:0-3,5,7,9-15
177
178 A memory policy with a valid NodeList will be saved, as specified, for
179 use at file creation time. When a task allocates a file in the file
180 system, the mount option memory policy will be applied with a NodeList,
181 if any, modified by the calling task's cpuset constraints
182 [See Documentation/admin-guide/cgroup-v1/cpusets.rst] and any optional flags,
183 listed below. If the resulting NodeLists is the empty set, the effective
184 memory policy for the file will revert to "default" policy.
185
186 NUMA memory allocation policies have optional flags that can be used in
187 conjunction with their modes. These optional flags can be specified
188 when tmpfs is mounted by appending them to the mode before the NodeList.
189 See Documentation/admin-guide/mm/numa_memory_policy.rst for a list of
190 all available memory allocation policy mode flags and their effect on
191 memory policy.
192
193 ::
194
195 =static is equivalent to MPOL_F_STATIC_NODES
196 =relative is equivalent to MPOL_F_RELATIVE_NODES
197
198 For example, mpol=bind=static:NodeList, is the equivalent of an
199 allocation policy of MPOL_BIND | MPOL_F_STATIC_NODES.
200
201 Note that trying to mount a tmpfs with an mpol option will fail if the
202 running kernel does not support NUMA; and will fail if its nodelist
203 specifies a node which is not online. If your system relies on that
204 tmpfs being mounted, but from time to time runs a kernel built without
205 NUMA capability (perhaps a safe recovery kernel), or with fewer nodes
206 online, then it is advisable to omit the mpol option from automatic
207 mount options. It can be added later, when the tmpfs is already mounted
208 on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'.
209
210
211 To specify the initial root directory you can use the following mount
212 options:
213
214 ==== ==================================
215 mode The permissions as an octal number
216 uid The user id
217 gid The group id
218 ==== ==================================
219
220 These options do not have any effect on remount. You can change these
221 parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.
222
223
224 tmpfs has a mount option to select whether it will wrap at 32- or 64-bit inode
225 numbers:
226
227 ======= ========================
228 inode64 Use 64-bit inode numbers
229 inode32 Use 32-bit inode numbers
230 ======= ========================
231
232 On a 32-bit kernel, inode32 is implicit, and inode64 is refused at mount time.
233 On a 64-bit kernel, CONFIG_TMPFS_INODE64 sets the default. inode64 avoids the
234 possibility of multiple files with the same inode number on a single device;
235 but risks glibc failing with EOVERFLOW once 33-bit inode numbers are reached -
236 if a long-lived tmpfs is accessed by 32-bit applications so ancient that
237 opening a file larger than 2GiB fails with EINVAL.
238
239
240 So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs'
241 will give you tmpfs instance on /mytmpfs which can allocate 10GB
242 RAM/SWAP in 10240 inodes and it is only accessible by root.
243
244 tmpfs has the following mounting options for case-insensitive lookup support:
245
246 ================= ==============================================================
247 casefold Enable casefold support at this mount point using the given
248 argument as the encoding standard. Currently only UTF-8
249 encodings are supported. If no argument is used, it will load
250 the latest UTF-8 encoding available.
251 strict_encoding Enable strict encoding at this mount point (disabled by
252 default). In this mode, the filesystem refuses to create file
253 and directory with names containing invalid UTF-8 characters.
254 ================= ==============================================================
255
256 This option doesn't render the entire filesystem case-insensitive. One needs to
257 still set the casefold flag per directory, by flipping the +F attribute in an
258 empty directory. Nevertheless, new directories will inherit the attribute. The
259 mountpoint itself cannot be made case-insensitive.
260
261 Example::
262
263 $ mount -t tmpfs -o casefold=utf8-12.1.0,strict_encoding fs_name /mytmpfs
264 $ mount -t tmpfs -o casefold fs_name /mytmpfs
265
266
267 :Author:
268 Christoph Rohland <cr@sap.com>, 1.12.01
269 :Updated:
270 Hugh Dickins, 4 June 2007
271 :Updated:
272 KOSAKI Motohiro, 16 Mar 2010
273 :Updated:
274 Chris Down, 13 July 2020
275 :Updated:
276 André Almeida, 23 Aug 2024
277

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

Tmpfs의 저장 방식과 용도

1-74

tmpfs는 모든 file을 virtual memory에 보관하는 임시 파일 시스템이다. hard drive에는 file을 만들지 않으며 instance를 unmount하면 내용이 모두 사라진다. kernel 내부 cache에서 file 크기에 맞춰 늘고 줄며 mount가 swap을 허용하면 사용하지 않는 page를 swap space로 내보낼 수 있고 THP도 지원한다.

ramfs에 user-configurable option, remount 기반 동적 변경, 크기 제한, POSIX ACL, `trusted.*`, `security.*`, `user.*` xattr를 더한 형태다. 현재 사용량 아래로 resize할 수는 없다. ramfs는 swap도 parameter 변경도 지원하지 않아 가용 memory 전체를 소진하지 않도록 주의해야 한다.

대안인 brd `/dev/ram*`은 physical RAM에 block device를 만들고 그 위에 일반 파일 시스템을 올린다. ramfs처럼 swap하지 못하고 초기 크기가 고정된다. tmpfs는 자체 파일 시스템이며 block layer를 전혀 거치지 않는다.

tmpfs page는 page cache와 선택적 swap에 있으므로 `/proc/meminfo`에서는 `Shmem`, `free(1)`에서는 `Shared`로 집계된다. 이 counter에는 일반 shared memory도 포함되므로 instance별 사용량은 `df(1)`과 `du(1)`가 가장 신뢰할 만하다.

kernel에는 `CONFIG_TMPFS`와 무관하게 shared anonymous mapping과 SYSV shared memory용 보이지 않는 내부 mount가 항상 있다. user-visible tmpfs만 config에 따라 빠진다. glibc 2.2 이상 POSIX shared memory `shm_open`·`shm_unlink`에는 `/dev/shm` mount가 필요하지만 SYSV shared memory에는 필요 없다. `/tmp`, `/var/tmp`와 큰 swap을 조합하거나 tmpfs file의 loop mount를 사용할 수도 있다.

tmpfs·ramfs·brd 비교
특성tmpfsramfsbrd ramdisk
Swap선택 가능불가불가
동적 resize가능, 현재 사용량 미만은 불가parameter 없음불가
Block layer사용 안 함사용 안 함block device로 사용
파일 시스템자체 tmpfs자체 ramfs별도 일반 FS 필요
주요 위험과도한 limitmemory 전체 소진고정 RAM 점유

세 RAM 기반 저장 방식의 차이다.

공유 메모리 mount
kernel 내부 tmpfs mount는 항상 존재SYSV shared memory는 내부 mount 사용POSIX `shm_open()`은 user-visible `/dev/shm` 사용`tmpfs /dev/shm tmpfs defaults 0 0`필요한 mountpoint directory 사전 생성

POSIX와 SYSV shared memory가 다른 mount 경로를 사용한다.

.. SPDX-License-Identifier: GPL-2.0

=====
Tmpfs
=====

Tmpfs is a file system which keeps all of its 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, if swap was enabled for the tmpfs
mount. tmpfs also supports THP.

tmpfs extends ramfs with a few userspace configurable options listed and
explained further below, some of which can be reconfigured dynamically on the
fly using a remount ('mount -o remount ...') of the filesystem. A tmpfs
filesystem can be resized but it cannot be resized to a size below its current
usage. tmpfs also supports POSIX ACLs, and extended attributes for the
trusted.*, security.* and user.* namespaces. ramfs does not use swap and you
cannot modify any parameter for a ramfs filesystem. The size limit of a ramfs
filesystem is how much memory you have available, and so care must be taken if
used so to not run out of memory.

An alternative to tmpfs and ramfs is to use brd to create RAM disks
(/dev/ram*), which allows you to simulate a block device disk in physical RAM.
To write data you would just then need to create an regular filesystem on top
this ramdisk. As with ramfs, brd ramdisks cannot swap. brd ramdisks are also
configured in size at initialization and you cannot dynamically resize them.
Contrary to brd ramdisks, tmpfs has its own filesystem, it does not rely on the
block layer at all.

Since tmpfs lives completely in the page cache and optionally 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).

tmpfs has the following uses:

1) There is always a kernel internal mount which you will not see at
   all. This is used for shared anonymous mappings and SYSV shared
   memory.

   This mount does not depend on CONFIG_TMPFS. If CONFIG_TMPFS is not
   set, the user visible part of tmpfs is not built. But the internal
   mechanisms are always present.

2) glibc 2.2 and above expects tmpfs to be mounted at /dev/shm for
   POSIX shared memory (shm_open, shm_unlink). Adding the following
   line to /etc/fstab should take care of this::

        tmpfs        /dev/shm        tmpfs        defaults        0 0

   Remember to create the directory that you intend to mount tmpfs on
   if necessary.

   This mount is _not_ needed for SYSV shared memory. The internal
   mount is used for that. (In the 2.3 kernel versions it was
   necessary to mount the predecessor of tmpfs (shm fs) to use SYSV
   shared memory.)

3) Some people (including me) find it very convenient to mount it
   e.g. on /tmp and /var/tmp and have a big swap partition. And now
   loop mounts of tmpfs files do work, so mkinitrd shipped by most
   distributions should succeed with a tmpfs /tmp.

4) And probably a lot more I do not know about :-)

크기·inode·swap 제한

75-110

`size`는 instance가 할당할 byte 상한이며 기본값은 swap을 제외한 physical RAM의 절반이다. 지나치게 크게 잡은 여러 tmpfs는 OOM handler가 그 memory를 해제할 수 없어 machine deadlock을 일으킬 수 있다. `nr_blocks`는 같은 제한을 PAGE_SIZE block 수로 표현한다.

`nr_inodes`는 inode 최대 수다. 기본값은 physical RAM page 수의 절반과 highmem 시스템의 lowmem page 수 중 작은 값이다. `k`, `m`, `g` suffix를 받고 remount에서 바꿀 수 있다. `size`는 physical RAM 백분율 `%`도 받으며 `size`와 `nr_blocks`를 모두 생략하면 `size=50%`다.

`nr_blocks=0` 또는 `size=0`은 block 무제한, `nr_inodes=0`은 inode 무제한이다. write 권한 사용자가 machine memory를 모두 쓸 수 있어 일반적으로 위험하지만 CPU가 많고 집중적으로 쓰는 환경에서는 scalability를 높일 수 있다. inode 제한이 0이 아니면 xattr도 inode 공간을 소비해 `df -i`의 IUsed·IUse%가 늘고 IFree가 줄어든다.

memory 부족 때 tmpfs block은 swap될 수 있다. `noswap`은 이를 끄며 기본은 swap 활성화다. remount는 최초 noswap 설정을 바꿀 수 없다.

Tmpfs sizing option
Option단위·기본값0의 의미Remount
sizebyte 또는 RAM %, 기본 50%block 무제한변경 가능
nr_blocksPAGE_SIZE blockblock 무제한변경 가능
nr_inodesinode 수, RAM page 기반inode 무제한변경 가능
noswap기본 swap 허용해당 없음초기 설정 유지

크기와 object 수 제한의 단위·기본값·remount 특성이다.

tmpfs has three mount options for sizing:

=========  ============================================================
size       The limit of allocated bytes for this tmpfs instance. The
           default is half of your physical RAM without swap. If you
           oversize your tmpfs instances the machine will deadlock
           since the OOM handler will not be able to free that memory.
nr_blocks  The same as size, but in blocks of PAGE_SIZE.
nr_inodes  The maximum number of inodes for this instance. The default
           is half of the number of your physical RAM pages, or (on a
           machine with highmem) the number of lowmem RAM pages,
           whichever is the lower.
=========  ============================================================

These parameters accept a suffix k, m or g for kilo, mega and giga and
can be changed on remount.  The size parameter also accepts a suffix %
to limit this tmpfs instance to that percentage of your physical RAM:
the default, when neither size nor nr_blocks is specified, is size=50%

If nr_blocks=0 (or size=0), blocks will not be limited in that instance;
if nr_inodes=0, inodes will not be limited.  It is generally unwise to
mount with such options, since it allows any user with write access to
use up all the memory on the machine; but enhances the scalability of
that instance in a system with many CPUs making intensive use of it.

If nr_inodes is not 0, that limited space for inodes is also used up by
extended attributes: "df -i"'s IUsed and IUse% increase, IFree decreases.

tmpfs blocks may be swapped out, when there is a shortage of memory.
tmpfs has a mount option to disable its use of swap:

======  ===========================================================
noswap  Disables swap. Remounts must respect the original settings.
        By default swap is enabled.
======  ===========================================================

Transparent Huge Page와 quota

111-159

THP에는 `CONFIG_TRANSPARENT_HUGEPAGE`와 architecture별 `has_transparent_hugepage()` 지원이 필요하다. `huge=never`는 기본으로 huge page를 쓰지 않고, `always`는 새 page마다 시도한다. `within_size`는 huge page 전체가 `i_size` 안에 있을 때만 할당하면서 `madvise(2)` hint도 존중하고, `advise`는 madvise 요청 때만 할당한다.

`Documentation/admin-guide/mm/transhuge.rst`와 `/sys/kernel/mm/transparent_hugepage/shmem_enabled`에서 전체 tmpfs mount의 huge page를 긴급 차단하거나 test용으로 강제할 수 있다.

`quota`는 user·group accounting과 enforcement를 모두 켜고 mount 때 초기화되는 hidden system quota file을 사용한다. `usrquota`, `grpquota`는 각각 user 또는 group만 켠다. `usrquota_block_hardlimit`, `usrquota_inode_hardlimit`, `grpquota_block_hardlimit`, `grpquota_inode_hardlimit`은 전역 기본 hard limit를 정한다.

quota 관련 mount option은 remount에서 설정하거나 변경할 수 없다. limit은 `k`, `m`, `g` suffix를 받는다. root를 제외한 user·group·project ID의 quota entry가 처음 접근될 때 0 대신 지정 기본값으로 초기화되며 이후 개별 ID limit은 일반 quota 방식으로 바꿀 수 있다.

tmpfs quota는 user namespace를 지원하지 않으므로 그 안에서 quota를 켜도 uid·gid translation을 하지 않는다.

Tmpfs huge policy
Mode동작
huge=neverhuge page를 할당하지 않음, 기본값
huge=always새 page가 필요할 때마다 huge page 시도
huge=within_size전체 huge page가 i_size 안일 때만, madvise 존중
huge=advisemadvise 요청 때만

THP allocation 조건을 비교한다.

Tmpfs quota option
Option효과
quotauser·group accounting/enforcement
usrquotauser quota
grpquotagroup quota
usrquota_block_hardlimit전역 user block hard limit
usrquota_inode_hardlimit전역 user inode hard limit
grpquota_block_hardlimit전역 group block hard limit
grpquota_inode_hardlimit전역 group inode hard limit

accounting 범위와 전역 초기 hard limit다.

tmpfs also supports Transparent Huge Pages which requires a kernel
configured with CONFIG_TRANSPARENT_HUGEPAGE and with huge supported for
your system (has_transparent_hugepage(), which is architecture specific).
The mount options for this are:

================ ==============================================================
huge=never       Do not allocate huge pages.  This is the default.
huge=always      Attempt to allocate huge page every time a new page is needed.
huge=within_size Only allocate huge page if it will be fully within i_size.
                 Also respect madvise(2) hints.
huge=advise      Only allocate huge page if requested with madvise(2).
================ ==============================================================

See also Documentation/admin-guide/mm/transhuge.rst, which describes the
sysfs file /sys/kernel/mm/transparent_hugepage/shmem_enabled: which can
be used to deny huge pages on all tmpfs mounts in an emergency, or to
force huge pages on all tmpfs mounts for testing.

tmpfs also supports quota with the following mount options

======================== =================================================
quota                    User and group quota accounting and enforcement
                         is enabled on the mount. Tmpfs is using hidden
                         system quota files that are initialized on mount.
usrquota                 User quota accounting and enforcement is enabled
                         on the mount.
grpquota                 Group quota accounting and enforcement is enabled
                         on the mount.
usrquota_block_hardlimit Set global user quota block hard limit.
usrquota_inode_hardlimit Set global user quota inode hard limit.
grpquota_block_hardlimit Set global group quota block hard limit.
grpquota_inode_hardlimit Set global group quota inode hard limit.
======================== =================================================

None of the quota related mount options can be set or changed on remount.

Quota limit parameters accept a suffix k, m or g for kilo, mega and giga
and can't be changed on remount. Default global quota limits are taking
effect for any and all user/group/project except root the first time the
quota entry for user/group/project id is being accessed - typically the
first time an inode with a particular id ownership is being created after
the mount. In other words, instead of the limits being initialized to zero,
they are initialized with the particular value provided with these mount
options. The limits can be changed for any user/group id at any time as they
normally can be.

Note that tmpfs quotas do not support user namespaces so no uid/gid
translation is done if quotas are enabled inside user namespaces.

NUMA memory allocation policy

160-210

`CONFIG_NUMA`가 켜지면 tmpfs instance의 모든 file에 적용할 NUMA allocation policy를 `mpol=`로 지정하고 remount에서 바꿀 수 있다. default는 process policy, prefer는 특정 node 선호, bind는 NodeList에만 할당, interleave는 node를 번갈아 사용, local은 local node를 선호한다.

NodeList는 comma-separated decimal number와 `최소-최대` range다. 예는 `mpol=bind:0-3,5,7,9-15`다. 유효한 policy는 지정 형태로 저장되지만 file 생성 때 caller의 cpuset 제약과 optional flag로 NodeList를 수정한다. 결과가 빈 집합이면 해당 file은 default policy로 돌아간다.

mode와 NodeList 사이에 optional flag를 붙일 수 있다. `=static`은 `MPOL_F_STATIC_NODES`, `=relative`는 `MPOL_F_RELATIVE_NODES`다. `mpol=bind=static:NodeList`는 `MPOL_BIND | MPOL_F_STATIC_NODES`와 같다.

NUMA 미지원 kernel이거나 NodeList에 offline node가 있으면 mpol mount가 실패한다. recovery kernel처럼 NUMA capability나 online node 수가 달라질 수 있는 자동 mount에서는 mpol을 빼고 먼저 mount한 뒤 `mount -o remount,mpol=Policy:NodeList MountPoint`로 추가하는 편이 안전하다.

Tmpfs NUMA policy
Policy의미
mpol=defaultprocess allocation policy 사용
mpol=prefer:Node지정 node 선호
mpol=bind:NodeList목록 node에만 할당
mpol=interleave각 node를 차례로 선호
mpol=interleave:NodeList목록 node를 차례로 사용
mpol=locallocal node 선호

allocation 대상 node 선택 방식이다.

NUMA policy 적용
mount의 `mpol` policy·NodeList 저장file 생성 task의 cpuset 제약 적용static·relative mode flag 적용유효 NodeList로 allocation빈 집합이면 default policy로 fallback

저장한 NodeList가 file 생성 시 caller 제약과 결합된다.

tmpfs has a mount option to set the NUMA memory allocation policy for
all files in that instance (if CONFIG_NUMA is enabled) - which can be
adjusted on the fly via 'mount -o remount ...'

======================== ==============================================
mpol=default             use the process allocation policy
                         (see set_mempolicy(2))
mpol=prefer:Node         prefers to allocate memory from the given Node
mpol=bind:NodeList       allocates memory only from nodes in NodeList
mpol=interleave          prefers to allocate from each node in turn
mpol=interleave:NodeList allocates from each node of NodeList in turn
mpol=local                 prefers to allocate memory from the local node
======================== ==============================================

NodeList format is a comma-separated list of decimal numbers and ranges,
a range being two hyphen-separated decimal numbers, the smallest and
largest node numbers in the range.  For example, mpol=bind:0-3,5,7,9-15

A memory policy with a valid NodeList will be saved, as specified, for
use at file creation time.  When a task allocates a file in the file
system, the mount option memory policy will be applied with a NodeList,
if any, modified by the calling task's cpuset constraints
[See Documentation/admin-guide/cgroup-v1/cpusets.rst] and any optional flags,
listed below.  If the resulting NodeLists is the empty set, the effective
memory policy for the file will revert to "default" policy.

NUMA memory allocation policies have optional flags that can be used in
conjunction with their modes.  These optional flags can be specified
when tmpfs is mounted by appending them to the mode before the NodeList.
See Documentation/admin-guide/mm/numa_memory_policy.rst for a list of
all available memory allocation policy mode flags and their effect on
memory policy.

::

        =static                is equivalent to        MPOL_F_STATIC_NODES
        =relative        is equivalent to        MPOL_F_RELATIVE_NODES

For example, mpol=bind=static:NodeList, is the equivalent of an
allocation policy of MPOL_BIND | MPOL_F_STATIC_NODES.

Note that trying to mount a tmpfs with an mpol option will fail if the
running kernel does not support NUMA; and will fail if its nodelist
specifies a node which is not online.  If your system relies on that
tmpfs being mounted, but from time to time runs a kernel built without
NUMA capability (perhaps a safe recovery kernel), or with fewer nodes
online, then it is advisable to omit the mpol option from automatic
mount options.  It can be added later, when the tmpfs is already mounted
on MountPoint, by 'mount -o remount,mpol=Policy:NodeList MountPoint'.

Root mode와 inode number 폭

211-243

초기 root directory는 `mode` octal permission, `uid`, `gid` option으로 설정한다. remount에는 효과가 없으며 mount 후 `chmod(1)`, `chown(1)`, `chgrp(1)`로 바꾼다.

`inode64`와 `inode32`는 inode number wrap 폭을 선택한다. 32-bit kernel에서는 inode32가 암시적이고 inode64 mount는 거부된다. 64-bit kernel 기본값은 `CONFIG_TMPFS_INODE64`가 정한다.

inode64는 한 device에서 여러 file이 같은 inode number를 가질 가능성을 피하지만, 매우 오래된 32-bit application이 장수 tmpfs의 33-bit inode를 만나면 glibc `EOVERFLOW` 위험이 있다. 이는 2GiB보다 큰 file open이 `EINVAL`로 실패하던 시대의 application을 뜻한다.

예제 `mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs`는 RAM·swap 10GB, inode 10240개 한도, root-only 접근인 instance를 `/mytmpfs`에 만든다.

Root와 inode option
Option효과Remount
moderoot permission octal효과 없음
uidroot user ID효과 없음
gidroot group ID효과 없음
inode3232-bit inode numberkernel 제약 적용
inode6464-bit inode number32-bit kernel에서 거부

초기 directory metadata와 inode 폭을 구분한다.

To specify the initial root directory you can use the following mount
options:

====        ==================================
mode        The permissions as an octal number
uid        The user id
gid        The group id
====        ==================================

These options do not have any effect on remount. You can change these
parameters with chmod(1), chown(1) and chgrp(1) on a mounted filesystem.


tmpfs has a mount option to select whether it will wrap at 32- or 64-bit inode
numbers:

=======   ========================
inode64   Use 64-bit inode numbers
inode32   Use 32-bit inode numbers
=======   ========================

On a 32-bit kernel, inode32 is implicit, and inode64 is refused at mount time.
On a 64-bit kernel, CONFIG_TMPFS_INODE64 sets the default.  inode64 avoids the
possibility of multiple files with the same inode number on a single device;
but risks glibc failing with EOVERFLOW once 33-bit inode numbers are reached -
if a long-lived tmpfs is accessed by 32-bit applications so ancient that
opening a file larger than 2GiB fails with EINVAL.


So 'mount -t tmpfs -o size=10G,nr_inodes=10k,mode=700 tmpfs /mytmpfs'
will give you tmpfs instance on /mytmpfs which can allocate 10GB
RAM/SWAP in 10240 inodes and it is only accessible by root.

Casefold와 strict UTF-8

244-266

`casefold`는 mountpoint에서 지정 encoding의 casefold 지원을 활성화한다. 현재 UTF-8만 지원하며 argument가 없으면 사용 가능한 최신 UTF-8을 load한다. `strict_encoding`은 기본 비활성이고, 켜면 잘못된 UTF-8 문자가 있는 file·directory 이름 생성을 거부한다.

mount option만으로 전체 파일 시스템이 case-insensitive가 되지는 않는다. 빈 directory에서 `+F` attribute를 켜 directory별 casefold를 설정해야 하며 새 하위 directory는 이를 상속한다. mountpoint 자체에는 case-insensitive를 설정할 수 없다.

예제는 version을 고정한 `casefold=utf8-12.1.0,strict_encoding`과 최신 UTF-8을 선택하는 단순 `casefold` mount를 보여 준다.

Tmpfs casefold option
설정효과
casefold=utf8-VERSION지정 UTF-8 표준 load
casefold최신 사용 가능 UTF-8 load
strict_encodinginvalid UTF-8 이름 생성 거부
directory `+F`해당 빈 directory를 case-insensitive로 설정
상속새 directory가 부모의 +F를 상속

mount-wide encoding 준비와 directory별 활성화를 나눈다.

tmpfs has the following mounting options for case-insensitive lookup support:

================= ==============================================================
casefold          Enable casefold support at this mount point using the given
                  argument as the encoding standard. Currently only UTF-8
                  encodings are supported. If no argument is used, it will load
                  the latest UTF-8 encoding available.
strict_encoding   Enable strict encoding at this mount point (disabled by
                  default). In this mode, the filesystem refuses to create file
                  and directory with names containing invalid UTF-8 characters.
================= ==============================================================

This option doesn't render the entire filesystem case-insensitive. One needs to
still set the casefold flag per directory, by flipping the +F attribute in an
empty directory. Nevertheless, new directories will inherit the attribute. The
mountpoint itself cannot be made case-insensitive.

Example::

    $ mount -t tmpfs -o casefold=utf8-12.1.0,strict_encoding fs_name /mytmpfs
    $ mount -t tmpfs -o casefold fs_name /mytmpfs

문서 작성·갱신 이력

267-276

최초 저자는 Christoph Rohland이며 Hugh Dickins, KOSAKI Motohiro, Chris Down, André Almeida가 2007년부터 2024년까지 문서를 갱신했다. 원문 줄과 표기는 아래 접이식 source에서 그대로 보존한다.

:Author:
   Christoph Rohland <cr@sap.com>, 1.12.01
:Updated:
   Hugh Dickins, 4 June 2007
:Updated:
   KOSAKI Motohiro, 16 Mar 2010
:Updated:
   Chris Down, 13 July 2020
:Updated:
   André Almeida, 23 Aug 2024