Debian Codegraph @

upstream/opensuse-leap-16-1/man5/btrfs.5

raw
1 '\" t
2 .\" Man page generated from reStructuredText.
3 .
4 .
5 .nr rst2man-indent-level 0
6 .
7 .de1 rstReportMargin
8 \\$1 \\n[an-margin]
9 level \\n[rst2man-indent-level]
10 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
11 -
12 \\n[rst2man-indent0]
13 \\n[rst2man-indent1]
14 \\n[rst2man-indent2]
15 ..
16 .de1 INDENT
17 .\" .rstReportMargin pre:
18 . RS \\$1
19 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
20 . nr rst2man-indent-level +1
21 .\" .rstReportMargin post:
22 ..
23 .de UNINDENT
24 . RE
25 .\" indent \\n[an-margin]
26 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
27 .nr rst2man-indent-level -1
28 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
29 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
30 ..
31 .TH "BTRFS" "5" "Mar 26, 2025" "6.14" "BTRFS"
32 .SH NAME
33 btrfs \- topics about the BTRFS filesystem (mount options, supported file attributes and other)
34 .SH DESCRIPTION
35 .sp
36 This document describes topics related to BTRFS that are not specific to the
37 tools. Currently covers:
38 .INDENT 0.0
39 .IP 1. 4
40 mount options
41 .IP 2. 4
42 filesystem features
43 .IP 3. 4
44 checksum algorithms
45 .IP 4. 4
46 compression
47 .IP 5. 4
48 sysfs interface
49 .IP 6. 4
50 filesystem exclusive operations
51 .IP 7. 4
52 filesystem limits
53 .IP 8. 4
54 bootloader support
55 .IP 9. 4
56 file attributes
57 .IP 10. 4
58 zoned mode
59 .IP 11. 4
60 control device
61 .IP 12. 4
62 filesystems with multiple block group profiles
63 .IP 13. 4
64 seeding device
65 .IP 14. 4
66 RAID56 status and recommended practices
67 .IP 15. 4
68 glossary
69 .IP 16. 4
70 storage model, hardware considerations
71 .UNINDENT
72 .SH MOUNT OPTIONS
73 .SS BTRFS SPECIFIC MOUNT OPTIONS
74 .sp
75 This section describes mount options specific to BTRFS. For the generic mount
76 options please refer to \X'tty: link https://man7.org/linux/man-pages/man8/mount.8.html'\fI\%mount(8)\fP\X'tty: link' manual page and also see the section
77 with BTRFS specifics \fI\%below\fP\&. The options are
78 sorted alphabetically (discarding the \fIno\fP prefix).
79 .sp
80 \fBNOTE:\fP
81 .INDENT 0.0
82 .INDENT 3.5
83 Most mount options apply to the whole filesystem and only options in the
84 first mounted subvolume will take effect. This is due to lack of implementation
85 and may change in the future. This means that (for example) you can\(aqt set
86 per\-subvolume \fInodatacow\fP, \fInodatasum\fP, or \fIcompress\fP using mount options. This
87 should eventually be fixed, but it has proved to be difficult to implement
88 correctly within the Linux VFS framework.
89 .UNINDENT
90 .UNINDENT
91 .sp
92 Mount options are processed in order, only the last occurrence of an option
93 takes effect and may disable other options due to constraints (see e.g.
94 \fInodatacow\fP and \fIcompress\fP). The output of \fBmount\fP command shows which options
95 have been applied.
96 .INDENT 0.0
97 .TP
98 .B acl, noacl
99 (default: on)
100 .sp
101 Enable/disable support for POSIX Access Control Lists (ACLs). See the
102 \X'tty: link https://man7.org/linux/man-pages/man5/acl.5.html'\fI\%acl(5)\fP\X'tty: link' manual page for more information about ACLs.
103 .sp
104 The support for ACL is build\-time configurable (BTRFS_FS_POSIX_ACL) and
105 mount fails if \fIacl\fP is requested but the feature is not compiled in.
106 .UNINDENT
107 .INDENT 0.0
108 .TP
109 .B autodefrag, noautodefrag
110 (since: 3.0, default: off)
111 .sp
112 Enable automatic file defragmentation.
113 When enabled, small random writes into files (in a range of tens of kilobytes,
114 currently it\(aqs 64KiB) are detected and queued up for the defragmentation process.
115 May not be well suited for large database workloads.
116 .sp
117 The read latency may increase due to reading the adjacent blocks that make up the
118 range for defragmentation, successive write will merge the blocks in the new
119 location.
120 .sp
121 \fBWARNING:\fP
122 .INDENT 7.0
123 .INDENT 3.5
124 Defragmenting with Linux kernel versions < 3.9 or ≥ 3.14\-rc2 as
125 well as with Linux stable kernel versions ≥ 3.10.31, ≥ 3.12.12 or
126 ≥ 3.13.4 will break up the reflinks of COW data (for example files
127 copied with \fBcp \-\-reflink\fP, snapshots or de\-duplicated data).
128 This may cause considerable increase of space usage depending on the
129 broken up reflinks.
130 .UNINDENT
131 .UNINDENT
132 .TP
133 .B barrier, nobarrier
134 (default: on)
135 .sp
136 Ensure that all IO write operations make it through the device cache and are stored
137 permanently when the filesystem is at its consistency checkpoint. This
138 typically means that a flush command is sent to the device that will
139 synchronize all pending data and ordinary metadata blocks, then writes the
140 superblock and issues another flush.
141 .sp
142 The write flushes incur a slight hit and also prevent the IO block
143 scheduler to reorder requests in a more effective way. Disabling barriers gets
144 rid of that penalty but will most certainly lead to a corrupted filesystem in
145 case of a crash or power loss. The ordinary metadata blocks could be yet
146 unwritten at the time the new superblock is stored permanently, expecting that
147 the block pointers to metadata were stored permanently before.
148 .sp
149 On a device with a volatile battery\-backed write\-back cache, the \fInobarrier\fP
150 option will not lead to filesystem corruption as the pending blocks are
151 supposed to make it to the permanent storage.
152 .TP
153 .B clear_cache
154 Force clearing and rebuilding of the free space cache if something
155 has gone wrong.
156 .sp
157 For free space cache \fIv1\fP, this only clears (and, unless \fInospace_cache\fP is
158 used, rebuilds) the free space cache for block groups that are modified while
159 the filesystem is mounted with that option. To actually clear an entire free
160 space cache \fIv1\fP, see \fBbtrfs check \-\-clear\-space\-cache v1\fP\&.
161 .sp
162 For free space cache \fIv2\fP, this clears the entire free space cache.
163 To do so without requiring to mounting the filesystem, see
164 \fBbtrfs check \-\-clear\-space\-cache v2\fP\&.
165 .sp
166 See also: \fIspace_cache\fP\&.
167 .TP
168 .B commit=<seconds>
169 (since: 3.12, default: 30)
170 .sp
171 Set the interval of periodic transaction commit when data are synchronized
172 to permanent storage. Higher interval values lead to larger amount of unwritten
173 data to accumulate in memory, which has obvious consequences when the
174 system crashes. The upper bound is not forced, but a warning is
175 printed if it\(aqs more than 300 seconds (5 minutes). Use with care.
176 .sp
177 The periodic commit is not the only mechanism to do the transaction commit,
178 this can also happen by explicit \fBsync\fP or indirectly by other
179 commands that affect the global filesystem state or internal kernel
180 mechanisms that flush based on various thresholds or policies (e.g. cgroups).
181 .TP
182 .B compress, compress=<type[:level]>, compress\-force, compress\-force=<type[:level]>
183 (default: off, level support since: 5.1)
184 .sp
185 Control BTRFS file data compression. Type may be specified as \fIzlib\fP,
186 \fIlzo\fP, \fIzstd\fP or \fIno\fP (for no compression, used for remounting). If no type
187 is specified, \fIzlib\fP is used. If \fIcompress\-force\fP is specified,
188 then compression will always be attempted, but the data may end up uncompressed
189 if the compression would make them larger.
190 .sp
191 Both \fIzlib\fP and \fIzstd\fP (since version 5.1) expose the compression level as a
192 tunable knob with higher levels trading speed and memory (\fIzstd\fP) for higher
193 compression ratios. This can be set by appending a colon and the desired level.
194 ZLIB accepts the range [1, 9] and ZSTD accepts [1, 15]. If no level is set,
195 both currently use a default level of 3. The value 0 is an alias for the
196 default level.
197 .sp
198 Otherwise some simple heuristics are applied to detect an incompressible file.
199 If the first blocks written to a file are not compressible, the whole file is
200 permanently marked to skip compression. As this is too simple, the
201 \fIcompress\-force\fP is a workaround that will compress most of the files at the
202 cost of some wasted CPU cycles on failed attempts.
203 Since kernel 4.15, a set of heuristic algorithms have been improved by using
204 frequency sampling, repeated pattern detection and Shannon entropy calculation
205 to avoid that.
206 .sp
207 \fBNOTE:\fP
208 .INDENT 7.0
209 .INDENT 3.5
210 If compression is enabled, \fInodatacow\fP and \fInodatasum\fP are disabled.
211 .UNINDENT
212 .UNINDENT
213 .TP
214 .B datacow, nodatacow
215 (default: on)
216 .sp
217 Enable data copy\-on\-write for newly created files.
218 \fINodatacow\fP implies \fInodatasum\fP, and disables \fIcompression\fP\&. All files created
219 under \fInodatacow\fP are also set the NOCOW file attribute (see \X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link').
220 .sp
221 \fBNOTE:\fP
222 .INDENT 7.0
223 .INDENT 3.5
224 If \fInodatacow\fP or \fInodatasum\fP are enabled, compression is disabled.
225 .UNINDENT
226 .UNINDENT
227 .sp
228 Updates in\-place improve performance for workloads that do frequent overwrites,
229 at the cost of potential partial writes, in case the write is interrupted
230 (system crash, device failure).
231 .TP
232 .B datasum, nodatasum
233 (default: on)
234 .sp
235 Enable data checksumming for newly created files.
236 \fIDatasum\fP implies \fIdatacow\fP, i.e. the normal mode of operation. All files created
237 under \fInodatasum\fP inherit the \(dqno checksums\(dq property, however there\(aqs no
238 corresponding file attribute (see \X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link').
239 .sp
240 \fBNOTE:\fP
241 .INDENT 7.0
242 .INDENT 3.5
243 If \fInodatacow\fP or \fInodatasum\fP are enabled, compression is disabled.
244 .UNINDENT
245 .UNINDENT
246 .sp
247 There is a slight performance gain when checksums are turned off, the
248 corresponding metadata blocks holding the checksums do not need to updated.
249 The cost of checksumming of the blocks in memory is much lower than the IO,
250 modern CPUs feature hardware support of the checksumming algorithm.
251 .UNINDENT
252 .INDENT 0.0
253 .TP
254 .B degraded
255 (default: off)
256 .sp
257 Allow mounts with fewer devices than the RAID profile constraints
258 require. A read\-write mount (or remount) may fail when there are too many devices
259 missing, for example if a stripe member is completely missing from RAID0.
260 .sp
261 Since 4.14, the constraint checks have been improved and are verified on the
262 chunk level, not at the device level. This allows degraded mounts of
263 filesystems with mixed RAID profiles for data and metadata, even if the
264 device number constraints would not be satisfied for some of the profiles.
265 .sp
266 Example: metadata \-\- raid1, data \-\- single, devices \-\- \fB/dev/sda\fP, \fB/dev/sdb\fP
267 .sp
268 Suppose the data are completely stored on \fIsda\fP, then missing \fIsdb\fP will not
269 prevent the mount, even if 1 missing device would normally prevent (any)
270 \fIsingle\fP profile to mount. In case some of the data chunks are stored on \fIsdb\fP,
271 then the constraint of single/data is not satisfied and the filesystem
272 cannot be mounted.
273 .UNINDENT
274 .INDENT 0.0
275 .TP
276 .B device=<devicepath>
277 Specify a path to a device that will be scanned for BTRFS filesystem during
278 mount. This is usually done automatically by a device manager (like udev) or
279 using the \fBbtrfs device scan\fP command (e.g. run from the initial ramdisk). In
280 cases where this is not possible the \fIdevice\fP mount option can help.
281 .sp
282 \fBNOTE:\fP
283 .INDENT 7.0
284 .INDENT 3.5
285 Booting e.g. a RAID1 system may fail even if all filesystem\(aqs \fIdevice\fP
286 paths are provided as the actual device nodes may not be discovered by the
287 system at that point.
288 .UNINDENT
289 .UNINDENT
290 .TP
291 .B discard, discard=sync, discard=async, nodiscard
292 (default: async when devices support it since 6.2, async support since: 5.6)
293 .sp
294 Enable discarding of freed file blocks. This is useful for SSD/NVMe
295 devices, thinly provisioned LUNs, or virtual machine images; however,
296 every storage layer must support discard for it to work.
297 .sp
298 In the synchronous mode (\fIsync\fP or without option value), lack of asynchronous
299 queued TRIM on the backing device TRIM can severely degrade performance,
300 because a synchronous TRIM operation will be attempted instead. Queued TRIM
301 requires SATA devices with chipsets revision newer than 3.1 and devices.
302 .sp
303 The asynchronous mode (\fIasync\fP) gathers extents in larger chunks before sending
304 them to the devices for TRIM. The overhead and performance impact should be
305 negligible compared to the previous mode and it\(aqs supposed to be the preferred
306 mode if needed.
307 .sp
308 If it is not necessary to immediately discard freed blocks, then the \fBfstrim\fP
309 tool can be used to discard all free blocks in a batch. Scheduling a TRIM
310 during a period of low system activity will prevent latent interference with
311 the performance of other operations. Also, a device may ignore the TRIM command
312 if the range is too small, so running a batch discard has a greater probability
313 of actually discarding the blocks.
314 .TP
315 .B enospc_debug, noenospc_debug
316 (default: off)
317 .sp
318 Enable verbose output for some ENOSPC conditions. It\(aqs safe to use but can
319 be noisy if the system reaches near\-full state.
320 .TP
321 .B fatal_errors=<action>
322 (since: 3.4, default: bug)
323 .sp
324 Action to take when encountering a fatal error.
325 .INDENT 7.0
326 .TP
327 .B bug
328 \fIBUG()\fP on a fatal error, the system will stay in the crashed state and may be
329 still partially usable, but reboot is required for full operation
330 .TP
331 .B panic
332 \fIpanic()\fP on a fatal error, depending on other system configuration, this may
333 be followed by a reboot. Please refer to the documentation of kernel boot
334 parameters, e.g. \fIpanic\fP, \fIoops\fP or \fIcrashkernel\fP\&.
335 .UNINDENT
336 .TP
337 .B flushoncommit, noflushoncommit
338 (default: off)
339 .sp
340 This option forces any data dirtied by a write in a prior transaction to commit
341 as part of the current commit, effectively a full filesystem sync.
342 .sp
343 This makes the committed state a fully consistent view of the file system from
344 the application\(aqs perspective (i.e. it includes all completed file system
345 operations). This was previously the behavior only when a snapshot was
346 created.
347 .sp
348 When off, the filesystem is consistent but buffered writes may last more than
349 one transaction commit.
350 .TP
351 .B fragment=<type>
352 (depends on compile\-time option CONFIG_BTRFS_DEBUG, since: 4.4, default: off)
353 .sp
354 A debugging helper to intentionally fragment given \fItype\fP of block groups. The
355 type can be \fIdata\fP, \fImetadata\fP or \fIall\fP\&. This mount option should not be used
356 outside of debugging environments and is not recognized if the kernel config
357 option \fICONFIG_BTRFS_DEBUG\fP is not enabled.
358 .TP
359 .B nologreplay
360 (default: off, even read\-only)
361 .sp
362 The tree\-log contains pending updates to the filesystem until the full commit.
363 The log is replayed on next mount, this can be disabled by this option. See
364 also \fItreelog\fP\&. Note that \fInologreplay\fP is the same as \fInorecovery\fP\&.
365 .sp
366 \fBWARNING:\fP
367 .INDENT 7.0
368 .INDENT 3.5
369 Currently, the tree log is replayed even with a read\-only mount! To
370 disable that behaviour, mount also with \fInologreplay\fP\&.
371 .UNINDENT
372 .UNINDENT
373 .TP
374 .B max_inline=<bytes>
375 (default: min(2048, page size) )
376 .sp
377 Specify the maximum amount of space, that can be inlined in
378 a metadata b\-tree leaf. The value is specified in bytes, optionally
379 with a K suffix (case insensitive). In practice, this value
380 is limited by the filesystem block size (named \fIsectorsize\fP at mkfs time),
381 and memory page size of the system. In case of sectorsize limit, there\(aqs
382 some space unavailable due to b\-tree leaf headers. For example, a 4KiB
383 sectorsize, maximum size of inline data is about 3900 bytes.
384 .sp
385 Inlining can be completely turned off by specifying 0. This will increase data
386 block slack if file sizes are much smaller than block size but will reduce
387 metadata consumption in return.
388 .sp
389 \fBNOTE:\fP
390 .INDENT 7.0
391 .INDENT 3.5
392 The default value has changed to 2048 in kernel 4.6.
393 .UNINDENT
394 .UNINDENT
395 .TP
396 .B metadata_ratio=<value>
397 (default: 0, internal logic)
398 .sp
399 Specifies that 1 metadata chunk should be allocated after every \fIvalue\fP data
400 chunks. Default behaviour depends on internal logic, some percent of unused
401 metadata space is attempted to be maintained but is not always possible if
402 there\(aqs not enough space left for chunk allocation. The option could be useful to
403 override the internal logic in favor of the metadata allocation if the expected
404 workload is supposed to be metadata intense (snapshots, reflinks, xattrs,
405 inlined files).
406 .TP
407 .B norecovery
408 (since: 4.5, default: off)
409 .sp
410 Do not attempt any data recovery at mount time. This will disable \fIlogreplay\fP
411 and avoids other write operations. Note that this option is the same as
412 \fInologreplay\fP\&.
413 .sp
414 \fBNOTE:\fP
415 .INDENT 7.0
416 .INDENT 3.5
417 The opposite option \fIrecovery\fP used to have different meaning but was
418 changed for consistency with other filesystems, where \fInorecovery\fP is used for
419 skipping log replay. BTRFS does the same and in general will try to avoid any
420 write operations.
421 .UNINDENT
422 .UNINDENT
423 .UNINDENT
424 .INDENT 0.0
425 .TP
426 .B rescan_uuid_tree
427 (since: 3.12, default: off)
428 .sp
429 Force check and rebuild procedure of the UUID tree. This should not
430 normally be needed. Alternatively the tree can be cleared from
431 userspace by command \fI\%btrfs rescue clear\-uuid\-tree\fP
432 and then it will be automatically rebuilt in kernel (the mount option
433 is not needed in that case).
434 .TP
435 .B rescue
436 (since: 5.9)
437 .sp
438 Modes allowing mount with damaged filesystem structures, all requires
439 the filesystem to be mounted read\-only and doesn\(aqt allow remount to read\-write.
440 This is supposed to provide unified and more fine grained tuning of
441 errors that affect filesystem operation.
442 .INDENT 7.0
443 .IP \(bu 2
444 \fIusebackuproot\fP (since 5.9)
445 .sp
446 Try to use backup root slots inside super block.
447 Replaces standalone option \fIusebackuproot\fP
448 .IP \(bu 2
449 \fInologreplay\fP (since 5.9)
450 .sp
451 Do not replay any dirty logs.
452 Replaces standalone option \fInologreplay\fP
453 .IP \(bu 2
454 \fIignorebadroots\fP, \fIibadroots\fP (since: 5.11)
455 .sp
456 Ignore bad tree roots, greatly improve the chance for data salvage.
457 .IP \(bu 2
458 \fIignoredatacsums\fP, \fIidatacsums\fP (since: 5.11)
459 .sp
460 Ignore data checksum verification.
461 .IP \(bu 2
462 \fIignoremetacsums\fP, \fIimetacsums\fP (since 6.12)
463 .sp
464 Ignore metadata checksum verification, useful for interrupted checksum conversion.
465 .IP \(bu 2
466 \fIall\fP (since: 5.9)
467 .sp
468 Enable all supported rescue options.
469 .UNINDENT
470 .TP
471 .B skip_balance
472 (since: 3.3, default: off)
473 .sp
474 Skip automatic resume of an interrupted balance operation. The operation can
475 later be resumed with \fBbtrfs balance resume\fP, or the paused state can be
476 removed with \fBbtrfs balance cancel\fP\&. The default behaviour is to resume an
477 interrupted balance immediately after the filesystem is mounted.
478 .TP
479 .B space_cache, space_cache=<version>, nospace_cache
480 (\fInospace_cache\fP since: 3.2, \fIspace_cache=v1\fP and \fIspace_cache=v2\fP since 4.5, default: \fIspace_cache=v2\fP)
481 .sp
482 Options to control the free space cache. The free space cache greatly improves
483 performance when reading block group free space into memory. However, managing
484 the space cache consumes some resources, including a small amount of disk
485 space.
486 .sp
487 There are two implementations of the free space cache. The original
488 one, referred to as \fIv1\fP, used to be a safe default but has been
489 superseded by \fIv2\fP\&. The \fIv1\fP space cache can be disabled at mount time
490 with \fInospace_cache\fP without clearing.
491 .sp
492 On very large filesystems (many terabytes) and certain workloads, the
493 performance of the \fIv1\fP space cache may degrade drastically. The \fIv2\fP
494 implementation, which adds a new b\-tree called the free space tree, addresses
495 this issue. Once enabled, the \fIv2\fP space cache will always be used and cannot
496 be disabled unless it is cleared. Use \fIclear_cache,space_cache=v1\fP or
497 \fIclear_cache,nospace_cache\fP to do so. If \fIv2\fP is enabled, and \fIv1\fP space
498 cache will be cleared (at the first mount) and kernels without \fIv2\fP
499 support will only be able to mount the filesystem in read\-only mode.
500 On an unmounted filesystem the caches (both versions) can be cleared by
501 \(dqbtrfs check \-\-clear\-space\-cache\(dq.
502 .sp
503 The \fI\%btrfs\-check(8)\fP and \fI:doc:\(gamkfs.btrfs\fP commands have full \fIv2\fP free space
504 cache support since v4.19.
505 .sp
506 If a version is not explicitly specified, the default implementation will be
507 chosen, which is \fIv2\fP\&.
508 .TP
509 .B ssd, ssd_spread, nossd, nossd_spread
510 (default: SSD autodetected)
511 .sp
512 Options to control SSD allocation schemes. By default, BTRFS will
513 enable or disable SSD optimizations depending on status of a device with
514 respect to rotational or non\-rotational type. This is determined by the
515 contents of \fB/sys/block/DEV/queue/rotational\fP). If it is 0, the
516 \fIssd\fP option is turned on. The option \fInossd\fP will disable the
517 autodetection.
518 .sp
519 The optimizations make use of the absence of the seek penalty that\(aqs inherent
520 for the rotational devices. The blocks can be typically written faster and
521 are not offloaded to separate threads.
522 .sp
523 \fBNOTE:\fP
524 .INDENT 7.0
525 .INDENT 3.5
526 Since 4.14, the block layout optimizations have been dropped. This used
527 to help with first generations of SSD devices. Their FTL (flash translation
528 layer) was not effective and the optimization was supposed to improve the wear
529 by better aligning blocks. This is no longer true with modern SSD devices and
530 the optimization had no real benefit. Furthermore it caused increased
531 fragmentation. The layout tuning has been kept intact for the option
532 \fIssd_spread\fP\&.
533 .UNINDENT
534 .UNINDENT
535 .sp
536 The \fIssd_spread\fP mount option attempts to allocate into bigger and aligned
537 chunks of unused space, and may perform better on low\-end SSDs. \fIssd_spread\fP
538 implies \fIssd\fP, enabling all other SSD heuristics as well. The option \fInossd\fP
539 will disable all SSD options while \fInossd_spread\fP only disables \fIssd_spread\fP\&.
540 .TP
541 .B subvol=<path>
542 Mount subvolume from \fIpath\fP rather than the toplevel subvolume. The
543 \fIpath\fP is always treated as relative to the toplevel subvolume.
544 This mount option overrides the default subvolume set for the given filesystem.
545 .TP
546 .B subvolid=<subvolid>
547 Mount subvolume specified by a \fIsubvolid\fP number rather than the toplevel
548 subvolume. You can use \fBbtrfs subvolume list\fP of \fBbtrfs subvolume show\fP to see
549 subvolume ID numbers.
550 This mount option overrides the default subvolume set for the given filesystem.
551 .sp
552 \fBNOTE:\fP
553 .INDENT 7.0
554 .INDENT 3.5
555 If both \fIsubvolid\fP and \fIsubvol\fP are specified, they must point at the
556 same subvolume, otherwise the mount will fail.
557 .UNINDENT
558 .UNINDENT
559 .TP
560 .B thread_pool=<number>
561 (default: min(NRCPUS + 2, 8) )
562 .sp
563 The number of worker threads to start. NRCPUS is number of on\-line CPUs
564 detected at the time of mount. Small number leads to less parallelism in
565 processing data and metadata, higher numbers could lead to a performance hit
566 due to increased locking contention, process scheduling, cache\-line bouncing or
567 costly data transfers between local CPU memories.
568 .TP
569 .B treelog, notreelog
570 (default: on)
571 .sp
572 Enable the tree logging used for \fIfsync\fP and \fIO_SYNC\fP writes. The tree log
573 stores changes without the need of a full filesystem sync. The log operations
574 are flushed at sync and transaction commit. If the system crashes between two
575 such syncs, the pending tree log operations are replayed during mount.
576 .sp
577 \fBWARNING:\fP
578 .INDENT 7.0
579 .INDENT 3.5
580 Currently, the tree log is replayed even with a read\-only mount! To
581 disable that behaviour, also mount with \fInologreplay\fP\&.
582 .UNINDENT
583 .UNINDENT
584 .sp
585 The tree log could contain new files/directories, these would not exist on
586 a mounted filesystem if the log is not replayed.
587 .TP
588 .B usebackuproot
589 (since: 4.6, default: off)
590 .sp
591 Enable autorecovery attempts if a bad tree root is found at mount time.
592 Currently this scans a backup list of several previous tree roots and tries to
593 use the first readable. This can be used with read\-only mounts as well.
594 .sp
595 \fBNOTE:\fP
596 .INDENT 7.0
597 .INDENT 3.5
598 This option has replaced \fIrecovery\fP which has been deprecated.
599 .UNINDENT
600 .UNINDENT
601 .TP
602 .B user_subvol_rm_allowed
603 (default: off)
604 .sp
605 Allow subvolumes to be deleted by their respective owner. Otherwise, only the
606 root user can do that.
607 .sp
608 \fBNOTE:\fP
609 .INDENT 7.0
610 .INDENT 3.5
611 Historically, any user could create a snapshot even if he was not owner
612 of the source subvolume, the subvolume deletion has been restricted for that
613 reason. The subvolume creation has been restricted but this mount option is
614 still required. This is a usability issue.
615 Since 4.18, the \X'tty: link https://man7.org/linux/man-pages/man2/rmdir.2.html'\fI\%rmdir(2)\fP\X'tty: link' syscall can delete an empty subvolume just like an
616 ordinary directory. Whether this is possible can be detected at runtime, see
617 \fIrmdir_subvol\fP feature in \fIFILESYSTEM FEATURES\fP\&.
618 .UNINDENT
619 .UNINDENT
620 .UNINDENT
621 .SS DEPRECATED MOUNT OPTIONS
622 .sp
623 List of mount options that have been removed, kept for backward compatibility.
624 .INDENT 0.0
625 .TP
626 .B recovery
627 (since: 3.2, default: off, deprecated since: 4.5)
628 .sp
629 \fBNOTE:\fP
630 .INDENT 7.0
631 .INDENT 3.5
632 This option has been replaced by \fIusebackuproot\fP and should not be used
633 but will work on 4.5+ kernels.
634 .UNINDENT
635 .UNINDENT
636 .TP
637 .B inode_cache, noinode_cache
638 (removed in: 5.11, since: 3.0, default: off)
639 .sp
640 \fBNOTE:\fP
641 .INDENT 7.0
642 .INDENT 3.5
643 The functionality has been removed in 5.11, any stale data created by
644 previous use of the \fIinode_cache\fP option can be removed by
645 \fI\%btrfs rescue clear\-ino\-cache\fP\&.
646 .UNINDENT
647 .UNINDENT
648 .TP
649 .B check_int, check_int_data, check_int_print_mask=<value>
650 (removed in: 6.7, since: 3.0, default: off)
651 .sp
652 These debugging options control the behavior of the integrity checking
653 module (the BTRFS_FS_CHECK_INTEGRITY config option required). The main goal is
654 to verify that all blocks from a given transaction period are properly linked.
655 .sp
656 \fIcheck_int\fP enables the integrity checker module, which examines all
657 block write requests to ensure on\-disk consistency, at a large
658 memory and CPU cost.
659 .sp
660 \fIcheck_int_data\fP includes extent data in the integrity checks, and
661 implies the \fIcheck_int\fP option.
662 .sp
663 \fIcheck_int_print_mask\fP takes a bit mask of BTRFSIC_PRINT_MASK_* values
664 as defined in \fIfs/btrfs/check\-integrity.c\fP, to control the integrity
665 checker module behavior.
666 .sp
667 See comments at the top of \fIfs/btrfs/check\-integrity.c\fP
668 for more information.
669 .UNINDENT
670 .SS NOTES ON GENERIC MOUNT OPTIONS
671 .sp
672 Some of the general mount options from \X'tty: link https://man7.org/linux/man-pages/man8/mount.8.html'\fI\%mount(8)\fP\X'tty: link' that affect BTRFS and are
673 worth mentioning.
674 .INDENT 0.0
675 .TP
676 .B context
677 The context refers to the SELinux contexts and policy definitions passed
678 as mount options. This works properly since version v6.8 (because the
679 mount option parser of BTRFS was ported to new API that also understood
680 the options).
681 .TP
682 .B noatime
683 under read intensive work\-loads, specifying \fInoatime\fP significantly improves
684 performance because no new access time information needs to be written. Without
685 this option, the default is \fIrelatime\fP, which only reduces the number of
686 inode atime updates in comparison to the traditional \fIstrictatime\fP\&. The worst
687 case for atime updates under \fIrelatime\fP occurs when many files are read whose
688 atime is older than 24 h and which are freshly snapshotted. In that case the
689 atime is updated and COW happens \- for each file \- in bulk. See also
690 \X'tty: link https://lwn.net/Articles/499293/'\fI\%https://lwn.net/Articles/499293/\fP\X'tty: link' \- \fIAtime and btrfs: a bad combination? (LWN, 2012\-05\-31)\fP\&.
691 .sp
692 Note that \fInoatime\fP may break applications that rely on atime uptimes like
693 the venerable Mutt (unless you use \fImaildir\fP mailboxes).
694 .UNINDENT
695 .SH FILESYSTEM FEATURES
696 .sp
697 The basic set of filesystem features gets extended over time. The backward
698 compatibility is maintained and the features are optional, need to be
699 explicitly asked for so accidental use will not create incompatibilities.
700 .sp
701 There are several classes and the respective tools to manage the features:
702 .INDENT 0.0
703 .TP
704 .B at mkfs time only
705 This is namely for core structures, like the b\-tree nodesize or checksum
706 algorithm, see \fI\%mkfs.btrfs(8)\fP for more details.
707 .TP
708 .B after mkfs, on an unmounted filesystem
709 Features that may optimize internal structures or add new structures to support
710 new functionality, see \fI\%btrfstune(8)\fP\&. The command
711 \fBbtrfs inspect\-internal dump\-super /dev/sdx\fP
712 will dump a superblock, you can map the value of
713 \fIincompat_flags\fP to the features listed below
714 .TP
715 .B after mkfs, on a mounted filesystem
716 The features of a filesystem (with a given UUID) are listed in
717 \fB/sys/fs/btrfs/UUID/features/\fP, one file per feature. The status is stored
718 inside the file. The value \fI1\fP is for enabled and active, while \fI0\fP means the
719 feature was enabled at mount time but turned off afterwards.
720 .sp
721 Whether a particular feature can be turned on a mounted filesystem can be found
722 in the directory \fB/sys/fs/btrfs/features/\fP, one file per feature. The value \fI1\fP
723 means the feature can be enabled.
724 .UNINDENT
725 .sp
726 List of features (see also \fI\%mkfs.btrfs(8)\fP section
727 \fI\%FILESYSTEM FEATURES\fP):
728 .INDENT 0.0
729 .TP
730 .B big_metadata
731 (since: 3.4)
732 .sp
733 the filesystem uses \fInodesize\fP for metadata blocks, this can be bigger than the
734 page size
735 .TP
736 .B block_group_tree
737 (since: 6.1)
738 .sp
739 block group item representation using a dedicated b\-tree, this can greatly
740 reduce mount time for large filesystems
741 .TP
742 .B compress_lzo
743 (since: 2.6.38)
744 .sp
745 the \fIlzo\fP compression has been used on the filesystem, either as a mount option
746 or via \fBbtrfs filesystem defrag\fP\&.
747 .TP
748 .B compress_zstd
749 (since: 4.14)
750 .sp
751 the \fIzstd\fP compression has been used on the filesystem, either as a mount option
752 or via \fBbtrfs filesystem defrag\fP\&.
753 .TP
754 .B default_subvol
755 (since: 2.6.34)
756 .sp
757 the default subvolume has been set on the filesystem
758 .TP
759 .B extended_iref
760 (since: 3.7)
761 .sp
762 increased hardlink limit per file in a directory to 65536, older kernels
763 supported a varying number of hardlinks depending on the sum of all file name
764 sizes that can be stored into one metadata block
765 .TP
766 .B free_space_tree
767 (since: 4.5)
768 .sp
769 free space representation using a dedicated b\-tree, successor of v1 space cache
770 .TP
771 .B metadata_uuid
772 (since: 5.0)
773 .sp
774 the main filesystem UUID is the metadata_uuid, which stores the new UUID only
775 in the superblock while all metadata blocks still have the UUID set at mkfs
776 time, see \fI\%btrfstune(8)\fP for more
777 .TP
778 .B mixed_backref
779 (since: 2.6.31)
780 .sp
781 the last major disk format change, improved backreferences, now default
782 .TP
783 .B mixed_groups
784 (since: 2.6.37)
785 .sp
786 mixed data and metadata block groups, i.e. the data and metadata are not
787 separated and occupy the same block groups, this mode is suitable for small
788 volumes as there are no constraints how the remaining space should be used
789 (compared to the split mode, where empty metadata space cannot be used for data
790 and vice versa)
791 .sp
792 on the other hand, the final layout is quite unpredictable and possibly highly
793 fragmented, which means worse performance
794 .TP
795 .B no_holes
796 (since: 3.14)
797 .sp
798 improved representation of file extents where holes are not explicitly
799 stored as an extent, saves a few percent of metadata if sparse files are used
800 .TP
801 .B raid1c34
802 (since: 5.5)
803 .sp
804 extended RAID1 mode with copies on 3 or 4 devices respectively
805 .TP
806 .B raid_stripe_tree
807 (since: 6.7)
808 .sp
809 a separate tree for tracking file extents on RAID profiles
810 .TP
811 .B RAID56
812 (since: 3.9)
813 .sp
814 the filesystem contains or contained a RAID56 profile of block groups
815 .TP
816 .B rmdir_subvol
817 (since: 4.18)
818 .sp
819 indicate that \X'tty: link https://man7.org/linux/man-pages/man2/rmdir.2.html'\fI\%rmdir(2)\fP\X'tty: link' syscall can delete an empty subvolume just like an
820 ordinary directory. Note that this feature only depends on the kernel version.
821 .TP
822 .B skinny_metadata
823 (since: 3.10)
824 .sp
825 reduced\-size metadata for extent references, saves a few percent of metadata
826 .TP
827 .B send_stream_version
828 (since: 5.10)
829 .sp
830 number of the highest supported send stream version
831 .TP
832 .B simple_quota
833 (since: 6.7)
834 .sp
835 simplified quota accounting
836 .TP
837 .B supported_checksums
838 (since: 5.5)
839 .sp
840 list of checksum algorithms supported by the kernel module, the respective
841 modules or built\-in implementing the algorithms need to be present to mount
842 the filesystem, see section \fI\%CHECKSUM ALGORITHMS\fP\&.
843 .TP
844 .B supported_sectorsizes
845 (since: 5.13)
846 .sp
847 list of values that are accepted as sector sizes (\fBmkfs.btrfs \-\-sectorsize\fP) by
848 the running kernel
849 .TP
850 .B supported_rescue_options
851 (since: 5.11)
852 .sp
853 list of values for the mount option \fIrescue\fP that are supported by the running
854 kernel, see \fI\%btrfs(5)\fP
855 .TP
856 .B zoned
857 (since: 5.12)
858 .sp
859 zoned mode is allocation/write friendly to host\-managed zoned devices,
860 allocation space is partitioned into fixed\-size zones that must be updated
861 sequentially, see section \fI\%ZONED MODE\fP
862 .UNINDENT
863 .SH SWAPFILE SUPPORT
864 .sp
865 A swapfile, when active, is a file\-backed swap area. It is supported since kernel 5.0.
866 Use \X'tty: link https://man7.org/linux/man-pages/man8/swapon.8.html'\fI\%swapon(8)\fP\X'tty: link' to activate it, until then (respectively again after deactivating it
867 with \X'tty: link https://man7.org/linux/man-pages/man8/swapoff.8.html'\fI\%swapoff(8)\fP\X'tty: link') it\(aqs just a normal file (with NODATACOW set), for which the special
868 restrictions for active swapfiles don\(aqt apply.
869 .sp
870 There are some limitations of the implementation in BTRFS and Linux swap
871 subsystem:
872 .INDENT 0.0
873 .IP \(bu 2
874 filesystem \- must be only single device
875 .IP \(bu 2
876 filesystem \- must have only \fIsingle\fP data profile
877 .IP \(bu 2
878 subvolume \- cannot be snapshotted if it contains any active swapfiles
879 .IP \(bu 2
880 swapfile \- must be preallocated (i.e. no holes)
881 .IP \(bu 2
882 swapfile \- must be NODATACOW (i.e. also NODATASUM, no compression)
883 .UNINDENT
884 .sp
885 The limitations come namely from the COW\-based design and mapping layer of
886 blocks that allows the advanced features like relocation and multi\-device
887 filesystems. However, the swap subsystem expects simpler mapping and no
888 background changes of the file block location once they\(aqve been assigned to
889 swap. The constraints mentioned above (single device and single profile) are
890 related to the swapfile itself, i.e. the extents and their placement. It is
891 possible to create swapfile on multi\-device filesystem as long as the extents
892 are on one device but this cannot be affected by user and depends on free space
893 fragmentation and available unused space for new chunks.
894 .sp
895 With active swapfiles, the following whole\-filesystem operations will skip
896 swapfile extents or may fail:
897 .INDENT 0.0
898 .IP \(bu 2
899 balance \- block groups with extents of any active swapfiles are skipped and
900 reported, the rest will be processed normally
901 .IP \(bu 2
902 resize grow \- unaffected
903 .IP \(bu 2
904 resize shrink \- works as long as the extents of any active swapfiles are
905 outside of the shrunk range
906 .IP \(bu 2
907 device add \- if the new devices do not interfere with any already active swapfiles
908 this operation will work, though no new swapfile can be activated
909 afterwards
910 .IP \(bu 2
911 device delete \- if the device has been added as above, it can be also deleted
912 .IP \(bu 2
913 device replace \- ditto
914 .UNINDENT
915 .sp
916 When there are no active swapfiles and a whole\-filesystem exclusive operation
917 is running (e.g. balance, device delete, shrink), the swapfiles cannot be
918 temporarily activated. The operation must finish first.
919 .sp
920 To create and activate a swapfile run the following commands:
921 .INDENT 0.0
922 .INDENT 3.5
923 .sp
924 .EX
925 # truncate \-s 0 swapfile
926 # chattr +C swapfile
927 # fallocate \-l 2G swapfile
928 # chmod 0600 swapfile
929 # mkswap swapfile
930 # swapon swapfile
931 .EE
932 .UNINDENT
933 .UNINDENT
934 .sp
935 Since version 6.1 it\(aqs possible to create the swapfile in a single command
936 (except the activation):
937 .INDENT 0.0
938 .INDENT 3.5
939 .sp
940 .EX
941 # btrfs filesystem mkswapfile \-\-size 2G swapfile
942 # swapon swapfile
943 .EE
944 .UNINDENT
945 .UNINDENT
946 .sp
947 Please note that the UUID returned by the \fImkswap\fP utility identifies the swap
948 \(dqfilesystem\(dq and because it\(aqs stored in a file, it\(aqs not generally visible and
949 usable as an identifier unlike if it was on a block device.
950 .sp
951 Once activated the file will appear in \fB/proc/swaps\fP:
952 .INDENT 0.0
953 .INDENT 3.5
954 .sp
955 .EX
956 # cat /proc/swaps
957 Filename Type Size Used Priority
958 /path/swapfile file 2097152 0 \-2
959 .EE
960 .UNINDENT
961 .UNINDENT
962 .sp
963 The swapfile can be created as one\-time operation or, once properly created,
964 activated on each boot by the \fBswapon \-a\fP command (usually started by the
965 service manager). Add the following entry to \fI/etc/fstab\fP, assuming the
966 filesystem that provides the \fI/path\fP has been already mounted at this point.
967 Additional mount options relevant for the swapfile can be set too (like
968 priority, not the BTRFS mount options).
969 .INDENT 0.0
970 .INDENT 3.5
971 .sp
972 .EX
973 /path/swapfile none swap defaults 0 0
974 .EE
975 .UNINDENT
976 .UNINDENT
977 .sp
978 From now on the subvolume with the active swapfile cannot be snapshotted until
979 the swapfile is deactivated again by \fBswapoff\fP\&. Then the swapfile is a
980 regular file and the subvolume can be snapshotted again, though this would prevent
981 another activation any swapfile that has been snapshotted. New swapfiles (not
982 snapshotted) can be created and activated.
983 .sp
984 Otherwise, an inactive swapfile does not affect the containing subvolume. Activation
985 creates a temporary in\-memory status and prevents some file operations, but is
986 not stored permanently.
987 .SH HIBERNATION
988 .sp
989 A swapfile can be used for hibernation but it\(aqs not straightforward. Before
990 hibernation a resume offset must be written to file \fI/sys/power/resume_offset\fP
991 or the kernel command line parameter \fIresume_offset\fP must be set.
992 .sp
993 The value is the physical offset on the device. Note that \fBthis is not the same
994 value that\fP \fBfilefrag\fP \fBprints as physical offset!\fP
995 .sp
996 Btrfs filesystem uses mapping between logical and physical addresses but here
997 the physical can still map to one or more device\-specific physical block
998 addresses. It\(aqs the device\-specific physical offset that is suitable as resume
999 offset.
1000 .sp
1001 Since version 6.1 there\(aqs a command \fI\%btrfs inspect\-internal map\-swapfile\fP
1002 that will print the device physical offset and the adjusted value for
1003 \fB/sys/power/resume_offset\fP\&. Note that the value is divided by page size, i.e.
1004 it\(aqs not the offset itself.
1005 .INDENT 0.0
1006 .INDENT 3.5
1007 .sp
1008 .EX
1009 # btrfs filesystem mkswapfile swapfile
1010 # btrfs inspect\-internal map\-swapfile swapfile
1011 Physical start: 811511726080
1012 Resume offset: 198122980
1013 .EE
1014 .UNINDENT
1015 .UNINDENT
1016 .sp
1017 For scripting and convenience the option \fI\-r\fP will print just the offset:
1018 .INDENT 0.0
1019 .INDENT 3.5
1020 .sp
1021 .EX
1022 # btrfs inspect\-internal map\-swapfile \-r swapfile
1023 198122980
1024 .EE
1025 .UNINDENT
1026 .UNINDENT
1027 .sp
1028 The command \fBmap\-swapfile\fP also verifies all the requirements, i.e. no holes,
1029 single device, etc.
1030 .SH TROUBLESHOOTING
1031 .sp
1032 If the swapfile activation fails please verify that you followed all the steps
1033 above or check the system log (e.g. \fBdmesg\fP or \fBjournalctl\fP) for more
1034 information.
1035 .sp
1036 Notably, the \fBswapon\fP utility exits with a message that does not say what
1037 failed:
1038 .INDENT 0.0
1039 .INDENT 3.5
1040 .sp
1041 .EX
1042 # swapon /path/swapfile
1043 swapon: /path/swapfile: swapon failed: Invalid argument
1044 .EE
1045 .UNINDENT
1046 .UNINDENT
1047 .sp
1048 The specific reason is likely to be printed to the system log by the btrfs
1049 module:
1050 .INDENT 0.0
1051 .INDENT 3.5
1052 .sp
1053 .EX
1054 # journalctl \-t kernel | grep swapfile
1055 kernel: BTRFS warning (device sda): swapfile must have single data profile
1056 .EE
1057 .UNINDENT
1058 .UNINDENT
1059 .SH CHECKSUM ALGORITHMS
1060 .sp
1061 Data and metadata are checksummed by default. The checksum is calculated before
1062 writing and verified after reading the blocks from devices. The whole metadata
1063 block has an inline checksum stored in the b\-tree node header. Each data block
1064 has a detached checksum stored in the checksum tree.
1065 .sp
1066 \fBNOTE:\fP
1067 .INDENT 0.0
1068 .INDENT 3.5
1069 Since a data checksum is calculated just before submitting to the block
1070 device, btrfs has a strong requirement that the corresponding data block must
1071 not be modified until the writeback is finished.
1072 .sp
1073 This requirement is met for a buffered write as btrfs has the full control on
1074 its page cache, but a direct write (\fBO_DIRECT\fP) bypasses page cache, and
1075 btrfs can not control the direct IO buffer (as it can be in user space memory).
1076 Thus it\(aqs possible that a user space program modifies its direct write buffer
1077 before the buffer is fully written back, and this can lead to a data
1078 checksum mismatch.
1079 .sp
1080 To avoid this, kernel starting with version 6.14 will force a direct
1081 write to fall back to buffered, if the inode requires a data checksum.
1082 This will bring a small performance penalty. If you require true zero\-copy
1083 direct writes, then set the \fBNODATASUM\fP flag for the inode and make
1084 sure the direct IO buffer is fully aligned to block size.
1085 .UNINDENT
1086 .UNINDENT
1087 .sp
1088 There are several checksum algorithms supported. The default and backward
1089 compatible algorithm is \fIcrc32c\fP\&. Since kernel 5.5 there are three more with different
1090 characteristics and trade\-offs regarding speed and strength. The following list
1091 may help you to decide which one to select.
1092 .INDENT 0.0
1093 .TP
1094 .B CRC32C (32 bits digest)
1095 Default, best backward compatibility. Very fast, modern CPUs have
1096 instruction\-level support, not collision\-resistant but still good error
1097 detection capabilities.
1098 .TP
1099 .B XXHASH (64 bits digest)
1100 Can be used as CRC32C successor. Very fast, optimized for modern CPUs utilizing
1101 instruction pipelining, good collision resistance and error detection.
1102 .TP
1103 .B SHA256 (256 bits digest)
1104 Cryptographic\-strength hash. Relatively slow but with possible CPU
1105 instruction acceleration or specialized hardware cards. FIPS certified and
1106 in wide use.
1107 .TP
1108 .B BLAKE2b (256 bits digest)
1109 Cryptographic\-strength hash. Relatively fast, with possible CPU acceleration
1110 using SIMD extensions. Not standardized but based on BLAKE which was a SHA3
1111 finalist, in wide use. The algorithm used is BLAKE2b\-256 that\(aqs optimized for
1112 64\-bit platforms.
1113 .UNINDENT
1114 .sp
1115 The \fIdigest size\fP affects overall size of data block checksums stored in the
1116 filesystem. The metadata blocks have a fixed area up to 256 bits (32 bytes), so
1117 there\(aqs no increase. Each data block has a separate checksum stored, with
1118 additional overhead of the b\-tree leaves.
1119 .sp
1120 Approximate relative performance of the algorithms, measured against CRC32C
1121 using implementations on a 11th gen 3.6GHz intel CPU:
1122 .TS
1123 box center;
1124 l|l|l|l.
1125 T{
1126 Digest
1127 T} T{
1128 Cycles/4KiB
1129 T} T{
1130 Ratio
1131 T} T{
1132 Implementation
1133 T}
1134 _
1135 T{
1136 CRC32C
1137 T} T{
1138 470
1139 T} T{
1140 1.00
1141 T} T{
1142 CPU instruction, PCL combination
1143 T}
1144 _
1145 T{
1146 XXHASH
1147 T} T{
1148 870
1149 T} T{
1150 1.9
1151 T} T{
1152 reference impl.
1153 T}
1154 _
1155 T{
1156 SHA256
1157 T} T{
1158 7600
1159 T} T{
1160 16
1161 T} T{
1162 libgcrypt
1163 T}
1164 _
1165 T{
1166 SHA256
1167 T} T{
1168 8500
1169 T} T{
1170 18
1171 T} T{
1172 openssl
1173 T}
1174 _
1175 T{
1176 SHA256
1177 T} T{
1178 8700
1179 T} T{
1180 18
1181 T} T{
1182 botan
1183 T}
1184 _
1185 T{
1186 SHA256
1187 T} T{
1188 32000
1189 T} T{
1190 68
1191 T} T{
1192 builtin, CPU instruction
1193 T}
1194 _
1195 T{
1196 SHA256
1197 T} T{
1198 37000
1199 T} T{
1200 78
1201 T} T{
1202 libsodium
1203 T}
1204 _
1205 T{
1206 SHA256
1207 T} T{
1208 78000
1209 T} T{
1210 166
1211 T} T{
1212 builtin, reference impl.
1213 T}
1214 _
1215 T{
1216 BLAKE2b
1217 T} T{
1218 10000
1219 T} T{
1220 21
1221 T} T{
1222 builtin/AVX2
1223 T}
1224 _
1225 T{
1226 BLAKE2b
1227 T} T{
1228 10900
1229 T} T{
1230 23
1231 T} T{
1232 libgcrypt
1233 T}
1234 _
1235 T{
1236 BLAKE2b
1237 T} T{
1238 13500
1239 T} T{
1240 29
1241 T} T{
1242 builtin/SSE41
1243 T}
1244 _
1245 T{
1246 BLAKE2b
1247 T} T{
1248 13700
1249 T} T{
1250 29
1251 T} T{
1252 libsodium
1253 T}
1254 _
1255 T{
1256 BLAKE2b
1257 T} T{
1258 14100
1259 T} T{
1260 30
1261 T} T{
1262 openssl
1263 T}
1264 _
1265 T{
1266 BLAKE2b
1267 T} T{
1268 14500
1269 T} T{
1270 31
1271 T} T{
1272 kcapi
1273 T}
1274 _
1275 T{
1276 BLAKE2b
1277 T} T{
1278 14500
1279 T} T{
1280 34
1281 T} T{
1282 builtin, reference impl.
1283 T}
1284 .TE
1285 .sp
1286 Many kernels are configured with SHA256 as built\-in and not as a module.
1287 The accelerated versions are however provided by the modules and must be loaded
1288 explicitly (\fBmodprobe sha256\fP) before mounting the filesystem to make use of
1289 them. You can check in \fB/sys/fs/btrfs/FSID/checksum\fP which one is used. If you
1290 see \fIsha256\-generic\fP, then you may want to unmount and mount the filesystem
1291 again. Changing that on a mounted filesystem is not possible.
1292 Check the file \fB/proc/crypto\fP, when the implementation is built\-in, you\(aqd find:
1293 .INDENT 0.0
1294 .INDENT 3.5
1295 .sp
1296 .EX
1297 name : sha256
1298 driver : sha256\-generic
1299 module : kernel
1300 priority : 100
1301 \&...
1302 .EE
1303 .UNINDENT
1304 .UNINDENT
1305 .sp
1306 While accelerated implementation is e.g.:
1307 .INDENT 0.0
1308 .INDENT 3.5
1309 .sp
1310 .EX
1311 name : sha256
1312 driver : sha256\-avx2
1313 module : sha256_ssse3
1314 priority : 170
1315 \&...
1316 .EE
1317 .UNINDENT
1318 .UNINDENT
1319 .SH COMPRESSION
1320 .sp
1321 Btrfs supports transparent file compression. There are three algorithms
1322 available: ZLIB, LZO and ZSTD (since v4.14), with various levels.
1323 The compression happens on the level of file extents and the algorithm is
1324 selected by file property, mount option or by a defrag command.
1325 You can have a single btrfs mount point that has some files that are
1326 uncompressed, some that are compressed with LZO, some with ZLIB, for instance
1327 (though you may not want it that way, it is supported).
1328 .sp
1329 Once the compression is set, all newly written data will be compressed, i.e.
1330 existing data are untouched. Data are split into smaller chunks (128KiB) before
1331 compression to make random rewrites possible without a high performance hit. Due
1332 to the increased number of extents the metadata consumption is higher. The
1333 chunks are compressed in parallel.
1334 .sp
1335 The algorithms can be characterized as follows regarding the speed/ratio
1336 trade\-offs:
1337 .INDENT 0.0
1338 .TP
1339 .B ZLIB
1340 .INDENT 7.0
1341 .IP \(bu 2
1342 slower, higher compression ratio
1343 .IP \(bu 2
1344 levels: 1 to 9, mapped directly, default level is 3
1345 .IP \(bu 2
1346 good backward compatibility
1347 .UNINDENT
1348 .TP
1349 .B LZO
1350 .INDENT 7.0
1351 .IP \(bu 2
1352 faster compression and decompression than ZLIB, worse compression ratio, designed to be fast
1353 .IP \(bu 2
1354 no levels
1355 .IP \(bu 2
1356 good backward compatibility
1357 .UNINDENT
1358 .TP
1359 .B ZSTD
1360 .INDENT 7.0
1361 .IP \(bu 2
1362 compression comparable to ZLIB with higher compression/decompression speeds and different ratio
1363 .IP \(bu 2
1364 levels: \-15..15, mapped directly, default is 3
1365 .IP \(bu 2
1366 support since 4.14
1367 .IP \(bu 2
1368 levels 1..15 supported since 5.1
1369 .IP \(bu 2
1370 levels \-15..\-1 supported since 6.15
1371 .UNINDENT
1372 .UNINDENT
1373 .sp
1374 The differences depend on the actual data set and cannot be expressed by a
1375 single number or recommendation. Higher levels consume more CPU time and may
1376 not bring a significant improvement, lower levels are close to real time.
1377 .SH HOW TO ENABLE COMPRESSION
1378 .sp
1379 Typically the compression can be enabled on the whole filesystem, specified for
1380 the mount point. Note that the compression mount options are shared among all
1381 mounts of the same filesystem, either bind mounts or subvolume mounts.
1382 Please refer to \fI\%btrfs(5)\fP section
1383 \fI\%MOUNT OPTIONS\fP\&.
1384 .INDENT 0.0
1385 .INDENT 3.5
1386 .sp
1387 .EX
1388 $ mount \-o compress=zstd /dev/sdx /mnt
1389 .EE
1390 .UNINDENT
1391 .UNINDENT
1392 .sp
1393 This will enable the \fBzstd\fP algorithm on the default level (which is 3).
1394 The level can be specified manually too like \fBzstd:3\fP\&. Higher levels compress
1395 better at the cost of time. This in turn may cause increased write latency, low
1396 levels are suitable for real\-time compression and on reasonably fast CPU don\(aqt
1397 cause noticeable performance drops.
1398 .INDENT 0.0
1399 .INDENT 3.5
1400 .sp
1401 .EX
1402 $ btrfs filesystem defrag \-czstd file
1403 .EE
1404 .UNINDENT
1405 .UNINDENT
1406 .sp
1407 The command above will start defragmentation of the whole \fIfile\fP and apply
1408 the compression, regardless of the mount option. (Note: specifying level is not
1409 yet implemented). The compression algorithm is not persistent and applies only
1410 to the defragmentation command, for any other writes other compression settings
1411 apply.
1412 .sp
1413 Persistent settings on a per\-file basis can be set in two ways:
1414 .INDENT 0.0
1415 .INDENT 3.5
1416 .sp
1417 .EX
1418 $ chattr +c file
1419 $ btrfs property set file compression zstd
1420 .EE
1421 .UNINDENT
1422 .UNINDENT
1423 .sp
1424 The first command is using legacy interface of file attributes inherited from
1425 ext2 filesystem and is not flexible, so by default the \fIzlib\fP compression is
1426 set. The other command sets a property on the file with the given algorithm.
1427 (Note: setting level that way is not yet implemented.)
1428 .SH COMPRESSION LEVELS
1429 .sp
1430 The level support of ZLIB has been added in v4.14, LZO does not support levels
1431 (the kernel implementation provides only one), ZSTD level support has been added
1432 in v5.1 and the negative levels in v6.15.
1433 .sp
1434 There are 9 levels of ZLIB supported (1 to 9), mapping 1:1 from the mount option
1435 to the algorithm defined level. The default is level 3, which provides the
1436 reasonably good compression ratio and is still reasonably fast. The difference
1437 in compression gain of levels 7, 8 and 9 is comparable but the higher levels
1438 take longer.
1439 .sp
1440 The ZSTD support includes levels \-15..15, a subset of full range of what ZSTD
1441 provides. Levels \-15..\-1 are real\-time with worse compression ratio, levels
1442 1..3 are near real\-time with good compression, 4..8 are slower with improved
1443 compression and 9..15 try even harder though the resulting size may not be
1444 significantly improved. Higher levels also require more memory and as they need
1445 more CPU the system performance is affected.
1446 .sp
1447 Level 0 always maps to the default. The compression level does not affect
1448 compatibility.
1449 .SH INCOMPRESSIBLE DATA
1450 .sp
1451 Files with already compressed data or with data that won\(aqt compress well with
1452 the CPU and memory constraints of the kernel implementations are using a simple
1453 decision logic. If the first portion of data being compressed is not smaller
1454 than the original, the compression of the file is disabled \-\- unless the
1455 filesystem is mounted with \fIcompress\-force\fP\&. In that case compression will
1456 always be attempted on the file only to be later discarded. This is not optimal
1457 and subject to optimizations and further development.
1458 .sp
1459 If a file is identified as incompressible, a flag is set (\fINOCOMPRESS\fP) and it\(aqs
1460 sticky. On that file compression won\(aqt be performed unless forced. The flag
1461 can be also set by \fBchattr +m\fP (since e2fsprogs 1.46.2) or by properties with
1462 value \fIno\fP or \fInone\fP\&. Empty value will reset it to the default that\(aqs currently
1463 applicable on the mounted filesystem.
1464 .sp
1465 There are two ways to detect incompressible data:
1466 .INDENT 0.0
1467 .IP \(bu 2
1468 actual compression attempt \- data are compressed, if the result is not smaller,
1469 it\(aqs discarded, so this depends on the algorithm and level
1470 .IP \(bu 2
1471 pre\-compression heuristics \- a quick statistical evaluation on the data is
1472 performed and based on the result either compression is performed or skipped,
1473 the NOCOMPRESS bit is not set just by the heuristic, only if the compression
1474 algorithm does not make an improvement
1475 .UNINDENT
1476 .INDENT 0.0
1477 .INDENT 3.5
1478 .sp
1479 .EX
1480 $ lsattr file
1481 \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-m file
1482 .EE
1483 .UNINDENT
1484 .UNINDENT
1485 .sp
1486 Using the forcing compression is not recommended, the heuristics are
1487 supposed to decide that and compression algorithms internally detect
1488 incompressible data too.
1489 .SH PRE-COMPRESSION HEURISTICS
1490 .sp
1491 The heuristics aim to do a few quick statistical tests on the compressed data
1492 in order to avoid probably costly compression that would turn out to be
1493 inefficient. Compression algorithms could have internal detection of
1494 incompressible data too but this leads to more overhead as the compression is
1495 done in another thread and has to write the data anyway. The heuristic is
1496 read\-only and can utilize cached memory.
1497 .sp
1498 The tests performed based on the following: data sampling, long repeated
1499 pattern detection, byte frequency, Shannon entropy.
1500 .SH COMPATIBILITY
1501 .sp
1502 Compression is done using the COW mechanism so it\(aqs incompatible with
1503 \fInodatacow\fP\&. Direct IO read works on compressed files but will fall back to
1504 buffered writes and leads to no compression even if force compression is set.
1505 Currently \fInodatasum\fP and compression don\(aqt work together.
1506 .sp
1507 The compression algorithms have been added over time so the version
1508 compatibility should be also considered, together with other tools that may
1509 access the compressed data like bootloaders.
1510 .SH SYSFS INTERFACE
1511 .sp
1512 Btrfs has a sysfs interface to provide extra knobs.
1513 .sp
1514 The top level path is \fB/sys/fs/btrfs/\fP, and the main directory layout is the following:
1515 .TS
1516 box center;
1517 l|l|l.
1518 T{
1519 Relative Path
1520 T} T{
1521 Description
1522 T} T{
1523 Version
1524 T}
1525 _
1526 T{
1527 features/
1528 T} T{
1529 All supported features
1530 T} T{
1531 3.14
1532 T}
1533 _
1534 T{
1535 <UUID>/
1536 T} T{
1537 Mounted fs UUID
1538 T} T{
1539 3.14
1540 T}
1541 _
1542 T{
1543 <UUID>/allocation/
1544 T} T{
1545 Space allocation info
1546 T} T{
1547 3.14
1548 T}
1549 _
1550 T{
1551 <UUID>/bdi/
1552 T} T{
1553 Backing device info (writeback)
1554 T} T{
1555 5.9
1556 T}
1557 _
1558 T{
1559 <UUID>/devices/<DEVID>/
1560 T} T{
1561 Symlink to each block device sysfs
1562 T} T{
1563 5.6
1564 T}
1565 _
1566 T{
1567 <UUID>/devinfo/<DEVID>/
1568 T} T{
1569 Btrfs specific info for each device
1570 T} T{
1571 5.6
1572 T}
1573 _
1574 T{
1575 <UUID>/discard/
1576 T} T{
1577 Discard stats and tunables
1578 T} T{
1579 6.1
1580 T}
1581 _
1582 T{
1583 <UUID>/features/
1584 T} T{
1585 Features of the filesystem
1586 T} T{
1587 3.14
1588 T}
1589 _
1590 T{
1591 <UUID>/qgroups/
1592 T} T{
1593 Global qgroup info
1594 T} T{
1595 5.9
1596 T}
1597 _
1598 T{
1599 <UUID>/qgroups/<LEVEL>_<ID>/
1600 T} T{
1601 Info for each qgroup
1602 T} T{
1603 5.9
1604 T}
1605 .TE
1606 .sp
1607 For \fB/sys/fs/btrfs/features/\fP directory, each file means a supported feature
1608 of the current kernel. Most files have value 0. Otherwise it depends on the file,
1609 value \fI1\fP typically means the feature can be turned on a mounted filesystem.
1610 .sp
1611 For \fB/sys/fs/btrfs/<UUID>/features/\fP directory, each file means an enabled
1612 feature on the mounted filesystem.
1613 .sp
1614 The features share the same name in section
1615 \fI\%FILESYSTEM FEATURES\fP\&.
1616 .SS UUID
1617 .sp
1618 Files in \fB/sys/fs/btrfs/<UUID>/\fP directory are:
1619 .INDENT 0.0
1620 .TP
1621 .B bg_reclaim_threshold
1622 (RW, since: 5.19)
1623 .sp
1624 Used space percentage of total device space to start auto block group claim.
1625 Mostly for zoned devices.
1626 .TP
1627 .B checksum
1628 (RO, since: 5.5)
1629 .sp
1630 The checksum used for the mounted filesystem.
1631 This includes both the checksum type (see section
1632 \fI\%CHECKSUM ALGORITHMS\fP)
1633 and the implemented driver (mostly shows if it\(aqs hardware accelerated).
1634 .TP
1635 .B clone_alignment
1636 (RO, since: 3.16)
1637 .sp
1638 The bytes alignment for \fIclone\fP and \fIdedupe\fP ioctls.
1639 .TP
1640 .B commit_stats
1641 (RW, since: 6.0)
1642 .sp
1643 The performance statistics for btrfs transaction commit since the first
1644 mount. Mostly for debugging purposes.
1645 .sp
1646 Writing into this file will reset the maximum commit duration
1647 (\fImax_commit_ms\fP) to 0. The file looks like:
1648 .INDENT 7.0
1649 .INDENT 3.5
1650 .sp
1651 .EX
1652 commits 70649
1653 last_commit_ms 2
1654 max_commit_ms 131
1655 total_commit_ms 170840
1656 .EE
1657 .UNINDENT
1658 .UNINDENT
1659 .INDENT 7.0
1660 .IP \(bu 2
1661 \fIcommits\fP \- number of transaction commits since the first mount
1662 .IP \(bu 2
1663 \fIlast_commit_ms\fP \- duration in milliseconds of the last commit
1664 .IP \(bu 2
1665 \fImax_commit_ms\fP \- maximum time a transaction commit took since first mount or last reset
1666 .IP \(bu 2
1667 \fItotal_commit_ms\fP \- sum of all transaction commit times
1668 .UNINDENT
1669 .TP
1670 .B exclusive_operation
1671 (RO, since: 5.10)
1672 .sp
1673 Shows the running exclusive operation.
1674 Check section
1675 \fI\%FILESYSTEM EXCLUSIVE OPERATIONS\fP
1676 for details.
1677 .TP
1678 .B generation
1679 (RO, since: 5.11)
1680 .sp
1681 Show the generation of the mounted filesystem.
1682 .TP
1683 .B label
1684 (RW, since: 3.14)
1685 .sp
1686 Show the current label of the mounted filesystem.
1687 .TP
1688 .B metadata_uuid
1689 (RO, since: 5.0)
1690 .sp
1691 Shows the metadata UUID of the mounted filesystem.
1692 Check \fImetadata_uuid\fP feature for more details.
1693 .TP
1694 .B nodesize
1695 (RO, since: 3.14)
1696 .sp
1697 Show the nodesize of the mounted filesystem.
1698 .TP
1699 .B quota_override
1700 (RW, since: 4.13)
1701 .sp
1702 Shows the current quota override status.
1703 0 means no quota override.
1704 1 means quota override, quota can ignore the existing limit settings.
1705 .TP
1706 .B read_policy
1707 (RW, since: 5.11)
1708 .sp
1709 Shows the current balance policy for reads.
1710 Currently only \fBpid\fP (balance using the process id (pid) value) is
1711 supported. More balancing policies are available in experimental
1712 build, namely round\-robin.
1713 .TP
1714 .B sectorsize
1715 (RO, since: 3.14)
1716 .sp
1717 Shows the sectorsize of the mounted filesystem.
1718 .TP
1719 .B temp_fsid
1720 (RO, since 6.7)
1721 .sp
1722 Indicate that this filesystem got assigned a temporary FSID at mount time,
1723 making possible to mount devices with the same FSID.
1724 .UNINDENT
1725 .SS UUID/allocations
1726 .sp
1727 Files and directories in \fB/sys/fs/btrfs/<UUID>/allocations\fP directory are:
1728 .INDENT 0.0
1729 .TP
1730 .B global_rsv_reserved
1731 (RO, since: 3.14)
1732 .sp
1733 The used bytes of the global reservation.
1734 .TP
1735 .B global_rsv_size
1736 (RO, since: 3.14)
1737 .sp
1738 The total size of the global reservation.
1739 .TP
1740 .B \fIdata/\fP, \fImetadata/\fP and \fIsystem/\fP directories
1741 (RO, since: 5.14)
1742 .sp
1743 Space info accounting for the 3 block group types.
1744 .UNINDENT
1745 .SS UUID/allocations/{data,metadata,system}
1746 .sp
1747 Files in \fB/sys/fs/btrfs/<UUID>/allocations/\fP\fIdata,metadata,system\fP directory are:
1748 .INDENT 0.0
1749 .TP
1750 .B bg_reclaim_threshold
1751 (RW, since: 5.19)
1752 .sp
1753 Reclaimable space percentage of block group\(aqs size (excluding
1754 permanently unusable space) to reclaim the block group.
1755 Can be used on regular or zoned devices.
1756 .TP
1757 .B bytes_*
1758 (RO)
1759 .sp
1760 Values of the corresponding data structures for the given block group
1761 type and profile that are used internally and may change rapidly depending
1762 on the load.
1763 .sp
1764 Complete list: bytes_may_use, bytes_pinned, bytes_readonly,
1765 bytes_reserved, bytes_used, bytes_zone_unusable
1766 .TP
1767 .B chunk_size
1768 (RW, since: 6.0)
1769 .sp
1770 Shows the chunk size. Can be changed for data and metadata (independently)
1771 and cannot be set for system block group type.
1772 Cannot be set for zoned devices as it depends on the fixed device zone size.
1773 Upper bound is 10% of the filesystem size, the value must be multiple of 256MiB
1774 and greater than 0.
1775 .TP
1776 .B size_classes
1777 (RO, since: 6.3)
1778 .sp
1779 Numbers of block groups of a given classes based on heuristics that
1780 measure extent length, age and fragmentation.
1781 .INDENT 7.0
1782 .INDENT 3.5
1783 .sp
1784 .EX
1785 none 136
1786 small 374
1787 medium 282
1788 large 93
1789 .EE
1790 .UNINDENT
1791 .UNINDENT
1792 .UNINDENT
1793 .SS UUID/bdi
1794 .sp
1795 Symlink to the sysfs directory of the backing device info (BDI), which is
1796 related to writeback process and infrastructure.
1797 .SS UUID/devices
1798 .sp
1799 Files in \fB/sys/fs/btrfs/<UUID>/devices\fP directory are symlinks named
1800 after device nodes (e.g. sda, dm\-0) and pointing to their sysfs directory.
1801 .SS UUID/devinfo
1802 .sp
1803 The directory contains subdirectories named after device ids (numeric values). Each
1804 subdirectory has information about the device of the given \fIdevid\fP\&.
1805 .SS UUID/devinfo/DEVID
1806 .sp
1807 Files in \fB/sys/fs/btrfs/<UUID>/devinfo/<DEVID>\fP directory are:
1808 .INDENT 0.0
1809 .TP
1810 .B error_stats:
1811 (RO, since: 5.14)
1812 .sp
1813 Shows device stats of this device, same as \fBbtrfs device stats\fP (\fI\%btrfs\-device(8)\fP).
1814 .INDENT 7.0
1815 .INDENT 3.5
1816 .sp
1817 .EX
1818 write_errs 0
1819 read_errs 0
1820 flush_errs 0
1821 corruption_errs 0
1822 generation_errs 0
1823 .EE
1824 .UNINDENT
1825 .UNINDENT
1826 .TP
1827 .B fsid:
1828 (RO, since: 5.17)
1829 .sp
1830 Shows the fsid which the device belongs to.
1831 It can be different than the \fBUUID\fP if it\(aqs a seed device.
1832 .TP
1833 .B in_fs_metadata
1834 (RO, since: 5.6)
1835 .sp
1836 Shows whether we have found the device.
1837 Should always be 1, as if this turns to 0, the \fBDEVID\fP directory
1838 would get removed automatically.
1839 .TP
1840 .B missing
1841 (RO, since: 5.6)
1842 .sp
1843 Shows whether the device is considered missing by the kernel module.
1844 .TP
1845 .B replace_target
1846 (RO, since: 5.6)
1847 .sp
1848 Shows whether the device is the replace target.
1849 If no device replace is running, this value is 0.
1850 .TP
1851 .B scrub_speed_max
1852 (RW, since: 5.14)
1853 .sp
1854 Shows the scrub speed limit for this device. The unit is Bytes/s.
1855 0 means no limit. The value can be set but is not persistent.
1856 .TP
1857 .B writeable
1858 (RO, since: 5.6)
1859 .sp
1860 Show if the device is writeable.
1861 .UNINDENT
1862 .SS UUID/qgroups
1863 .sp
1864 Files in \fB/sys/fs/btrfs/<UUID>/qgroups/\fP directory are:
1865 .INDENT 0.0
1866 .TP
1867 .B enabled
1868 (RO, since: 6.1)
1869 .sp
1870 Shows if qgroup is enabled.
1871 Also, if qgroup is disabled, the \fBqgroups\fP directory will
1872 be removed automatically.
1873 .TP
1874 .B inconsistent
1875 (RO, since: 6.1)
1876 .sp
1877 Shows if the qgroup numbers are inconsistent.
1878 If 1, it\(aqs recommended to do a qgroup rescan.
1879 .TP
1880 .B drop_subtree_threshold
1881 (RW, since: 6.1)
1882 .sp
1883 Shows the subtree drop threshold to automatically mark qgroup inconsistent.
1884 .sp
1885 When dropping large subvolumes with qgroup enabled, there would be a huge
1886 load for qgroup accounting.
1887 If we have a subtree whose level is larger than or equal to this value,
1888 we will not trigger qgroup account at all, but mark qgroup inconsistent to
1889 avoid the huge workload.
1890 .sp
1891 Default value is 3, which means that trees of low height will be accounted
1892 properly as this is sufficiently fast. The value was 8 until 6.13 where
1893 no subtree drop can trigger qgroup rescan making it less useful.
1894 .sp
1895 Lower value can reduce qgroup workload, at the cost of extra qgroup rescan
1896 to re\-calculate the numbers.
1897 .UNINDENT
1898 .SS UUID/qgroups/LEVEL_ID
1899 .sp
1900 Files in each \fB/sys/fs/btrfs/<UUID>/qgroups/<LEVEL>_<ID>/\fP directory are:
1901 .INDENT 0.0
1902 .TP
1903 .B exclusive
1904 (RO, since: 5.9)
1905 .sp
1906 Shows the exclusively owned bytes of the qgroup.
1907 .TP
1908 .B limit_flags
1909 (RO, since: 5.9)
1910 .sp
1911 Shows the numeric value of the limit flags.
1912 If 0, means no limit implied.
1913 .TP
1914 .B max_exclusive
1915 (RO, since: 5.9)
1916 .sp
1917 Shows the limits on exclusively owned bytes.
1918 .TP
1919 .B max_referenced
1920 (RO, since: 5.9)
1921 .sp
1922 Shows the limits on referenced bytes.
1923 .TP
1924 .B referenced
1925 (RO, since: 5.9)
1926 .sp
1927 Shows the referenced bytes of the qgroup.
1928 .TP
1929 .B rsv_data
1930 (RO, since: 5.9)
1931 .sp
1932 Shows the reserved bytes for data.
1933 .TP
1934 .B rsv_meta_pertrans
1935 (RO, since: 5.9)
1936 .sp
1937 Shows the reserved bytes for per transaction metadata.
1938 .TP
1939 .B rsv_meta_prealloc
1940 (RO, since: 5.9)
1941 .sp
1942 Shows the reserved bytes for preallocated metadata.
1943 .UNINDENT
1944 .SS UUID/discard
1945 .sp
1946 Files in \fB/sys/fs/btrfs/<UUID>/discard/\fP directory are:
1947 .INDENT 0.0
1948 .TP
1949 .B discardable_bytes
1950 (RO, since: 6.1)
1951 .sp
1952 Shows amount of bytes that can be discarded in the async discard and
1953 nodiscard mode.
1954 .TP
1955 .B discardable_extents
1956 (RO, since: 6.1)
1957 .sp
1958 Shows number of extents to be discarded in the async discard and
1959 nodiscard mode.
1960 .TP
1961 .B discard_bitmap_bytes
1962 (RO, since: 6.1)
1963 .sp
1964 Shows amount of discarded bytes from data tracked as bitmaps.
1965 .TP
1966 .B discard_extent_bytes
1967 (RO, since: 6.1)
1968 .sp
1969 Shows amount of discarded extents from data tracked as bitmaps.
1970 .TP
1971 .B discard_bytes_saved
1972 (RO, since: 6.1)
1973 .sp
1974 Shows the amount of bytes that were reallocated without being discarded.
1975 .TP
1976 .B kbps_limit
1977 (RW, since: 6.1)
1978 .sp
1979 Tunable limit of kilobytes per second issued as discard IO in the async
1980 discard mode.
1981 .TP
1982 .B iops_limit
1983 (RW, since: 6.1)
1984 .sp
1985 Tunable limit of number of discard IO operations to be issued in the
1986 async discard mode.
1987 .TP
1988 .B max_discard_size
1989 (RW, since: 6.1)
1990 .sp
1991 Tunable limit for size of one IO discard request.
1992 .UNINDENT
1993 .SH FILESYSTEM EXCLUSIVE OPERATIONS
1994 .sp
1995 There are several operations that affect the whole filesystem and cannot be run
1996 in parallel. Attempt to start one while another is running will fail (see
1997 exceptions below).
1998 .sp
1999 Since kernel 5.10 the currently running operation can be obtained from
2000 \fB/sys/fs/UUID/exclusive_operation\fP with following values and operations:
2001 .INDENT 0.0
2002 .IP \(bu 2
2003 balance
2004 .IP \(bu 2
2005 balance paused (since 5.17)
2006 .IP \(bu 2
2007 device add
2008 .IP \(bu 2
2009 device delete
2010 .IP \(bu 2
2011 device replace
2012 .IP \(bu 2
2013 resize
2014 .IP \(bu 2
2015 swapfile activate
2016 .IP \(bu 2
2017 none
2018 .UNINDENT
2019 .sp
2020 Enqueuing is supported for several btrfs subcommands so they can be started
2021 at once and then serialized.
2022 .sp
2023 There\(aqs an exception when a paused balance allows to start a device add
2024 operation as they don\(aqt really collide and this can be used to add more space
2025 for the balance to finish.
2026 .SH FILESYSTEM LIMITS
2027 .INDENT 0.0
2028 .TP
2029 .B maximum file name length
2030 255
2031 .sp
2032 This limit is imposed by Linux VFS, the structures of BTRFS could store
2033 larger file names.
2034 .TP
2035 .B maximum symlink target length
2036 depends on the \fInodesize\fP value, for 4KiB it\(aqs 3949 bytes, for larger nodesize
2037 it\(aqs 4095 due to the system limit PATH_MAX
2038 .sp
2039 The symlink target may not be a valid path, i.e. the path name components
2040 can exceed the limits (NAME_MAX), there\(aqs no content validation at \X'tty: link https://man7.org/linux/man-pages/man3/symlink.3.html'\fI\%symlink(3)\fP\X'tty: link'
2041 creation.
2042 .TP
2043 .B maximum number of inodes
2044 2\s-2\u64\d\s0 but depends on the available metadata space as the inodes are created
2045 dynamically
2046 .sp
2047 Each subvolume is an independent namespace of inodes and thus their
2048 numbers, so the limit is per subvolume, not for the whole filesystem.
2049 .TP
2050 .B inode numbers
2051 minimum number: 256 (for subvolumes), regular files and directories: 257,
2052 maximum number: (2\s-2\u64\d\s0 \- 256)
2053 .sp
2054 The inode numbers that can be assigned to user created files are from
2055 the whole 64bit space except first 256 and last 256 in that range that
2056 are reserved for internal b\-tree identifiers.
2057 .TP
2058 .B maximum file length
2059 inherent limit of BTRFS is 2\s-2\u64\d\s0 (16 EiB) but the practical
2060 limit of Linux VFS is 2\s-2\u63\d\s0 (8 EiB)
2061 .TP
2062 .B maximum number of subvolumes
2063 the subvolume ids can go up to 2\s-2\u48\d\s0 but the number of actual subvolumes
2064 depends on the available metadata space
2065 .sp
2066 The space consumed by all subvolume metadata includes bookkeeping of
2067 shared extents can be large (MiB, GiB). The range is not the full 64bit
2068 range because of qgroups that use the upper 16 bits for another
2069 purposes.
2070 .TP
2071 .B maximum number of hardlinks of a file in a directory
2072 65536 when the \fIextref\fP feature is turned on during mkfs (default), roughly
2073 100 otherwise and depends on file name length that fits into one metadata node
2074 .TP
2075 .B minimum filesystem size
2076 the minimal size of each device depends on the \fImixed\-bg\fP feature, without that
2077 (the default) it\(aqs about 109MiB, with mixed\-bg it\(aqs is 16MiB
2078 .UNINDENT
2079 .SH BOOTLOADER SUPPORT
2080 .sp
2081 GRUB2 (\X'tty: link https://www.gnu.org/software/grub'\fI\%https://www.gnu.org/software/grub\fP\X'tty: link') has the most advanced support of
2082 booting from BTRFS with respect to features.
2083 .sp
2084 U\-Boot (\X'tty: link https://www.denx.de/wiki/U-Boot/'\fI\%https://www.denx.de/wiki/U\-Boot/\fP\X'tty: link') has decent support for booting but
2085 not all BTRFS features are implemented, check the documentation.
2086 .sp
2087 In general, the first 1MiB on each device is unused with the exception of
2088 primary superblock that is on the offset 64KiB and spans 4KiB. The rest can be
2089 freely used by bootloaders or for other system information. Note that booting
2090 from a filesystem on \fI\%zoned device\fP is not supported.
2091 .SH FILE ATTRIBUTES
2092 .sp
2093 The btrfs filesystem supports setting file attributes or flags. Note there are
2094 old and new interfaces, with confusing names. The following list should clarify
2095 that:
2096 .INDENT 0.0
2097 .IP \(bu 2
2098 \fIattributes\fP: \X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link' or \X'tty: link https://man7.org/linux/man-pages/man1/lsattr.1.html'\fI\%lsattr(1)\fP\X'tty: link' utilities (the ioctls are
2099 FS_IOC_GETFLAGS and FS_IOC_SETFLAGS), due to the ioctl names the attributes
2100 are also called flags
2101 .IP \(bu 2
2102 \fIxflags\fP: to distinguish from the previous, it\(aqs extended flags, with tunable
2103 bits similar to the attributes but extensible and new bits will be added in
2104 the future (the ioctls are FS_IOC_FSGETXATTR and FS_IOC_FSSETXATTR but they
2105 are not related to extended attributes that are also called xattrs), there\(aqs
2106 no standard tool to change the bits, there\(aqs support in \X'tty: link https://man7.org/linux/man-pages/man8/xfs_io.8.html'\fI\%xfs_io(8)\fP\X'tty: link' as
2107 command \fBxfs_io \-c chattr\fP
2108 .UNINDENT
2109 .SS Attributes
2110 .INDENT 0.0
2111 .TP
2112 .B a
2113 \fIappend only\fP, new writes are always written at the end of the file
2114 .TP
2115 .B A
2116 \fIno atime updates\fP
2117 .TP
2118 .B c
2119 \fIcompress data\fP, all data written after this attribute is set will be compressed.
2120 Please note that compression is also affected by the mount options or the parent
2121 directory attributes.
2122 .sp
2123 When set on a directory, all newly created files will inherit this attribute.
2124 This attribute cannot be set with \(aqm\(aq at the same time.
2125 .TP
2126 .B C
2127 \fIno copy\-on\-write\fP, file data modifications are done in\-place
2128 .sp
2129 When set on a directory, all newly created files will inherit this attribute.
2130 .sp
2131 \fBNOTE:\fP
2132 .INDENT 7.0
2133 .INDENT 3.5
2134 Due to implementation limitations, this flag can be set/unset only on
2135 empty files.
2136 .UNINDENT
2137 .UNINDENT
2138 .TP
2139 .B d
2140 \fIno dump\fP, makes sense with 3rd party tools like \X'tty: link https://man7.org/linux/man-pages/man8/dump.8.html'\fI\%dump(8)\fP\X'tty: link', on BTRFS the
2141 attribute can be set/unset but no other special handling is done
2142 .TP
2143 .B D
2144 \fIsynchronous directory updates\fP, for more details search \X'tty: link https://man7.org/linux/man-pages/man2/open.2.html'\fI\%open(2)\fP\X'tty: link' for \fIO_SYNC\fP
2145 and \fIO_DSYNC\fP
2146 .TP
2147 .B i
2148 \fIimmutable\fP, no file data and metadata changes allowed even to the root user as
2149 long as this attribute is set (obviously the exception is unsetting the attribute)
2150 .TP
2151 .B m
2152 \fIno compression\fP, permanently turn off compression on the given file. Any
2153 compression mount options will not affect this file. (\X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link' support added in
2154 1.46.2)
2155 .sp
2156 When set on a directory, all newly created files will inherit this attribute.
2157 This attribute cannot be set with \fIc\fP at the same time.
2158 .TP
2159 .B S
2160 \fIsynchronous updates\fP, for more details search \X'tty: link https://man7.org/linux/man-pages/man2/open.2.html'\fI\%open(2)\fP\X'tty: link' for \fIO_SYNC\fP and
2161 \fIO_DSYNC\fP
2162 .UNINDENT
2163 .sp
2164 No other attributes are supported. For the complete list please refer to the
2165 \X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link' manual page.
2166 .SS XFLAGS
2167 .sp
2168 There\(aqs an overlap of letters assigned to the bits with the attributes, this list
2169 refers to what \X'tty: link https://man7.org/linux/man-pages/man8/xfs_io.8.html'\fI\%xfs_io(8)\fP\X'tty: link' provides:
2170 .INDENT 0.0
2171 .TP
2172 .B i
2173 \fIimmutable\fP, same as the attribute
2174 .TP
2175 .B a
2176 \fIappend only\fP, same as the attribute
2177 .TP
2178 .B s
2179 \fIsynchronous updates\fP, same as the attribute \fIS\fP
2180 .TP
2181 .B A
2182 \fIno atime updates\fP, same as the attribute
2183 .TP
2184 .B d
2185 \fIno dump\fP, same as the attribute
2186 .UNINDENT
2187 .SH ZONED MODE
2188 .sp
2189 Since version 5.12 btrfs supports so called \fIzoned mode\fP\&. This is a special
2190 on\-disk format and allocation/write strategy that\(aqs friendly to zoned devices.
2191 In short, a device is partitioned into fixed\-size zones and each zone can be
2192 updated by append\-only manner, or reset. As btrfs has no fixed data structures,
2193 except the super blocks, the zoned mode only requires block placement that
2194 follows the device constraints. You can learn about the whole architecture at
2195 \X'tty: link https://zonedstorage.io'\fI\%https://zonedstorage.io\fP\X'tty: link' .
2196 .sp
2197 The devices are also called SMR/ZBC/ZNS, in \fIhost\-managed\fP mode. Note that
2198 there are devices that appear as non\-zoned but actually are, this is
2199 \fIdrive\-managed\fP and using zoned mode won\(aqt help.
2200 .sp
2201 The zone size depends on the device, typical sizes are 256MiB or 1GiB. In
2202 general it must be a power of two. Emulated zoned devices like \fInull_blk\fP allow
2203 to set various zone sizes.
2204 .SS Requirements, limitations
2205 .INDENT 0.0
2206 .IP \(bu 2
2207 all devices must have the same zone size
2208 .IP \(bu 2
2209 maximum zone size is 8GiB
2210 .IP \(bu 2
2211 minimum zone size is 4MiB
2212 .IP \(bu 2
2213 mixing zoned and non\-zoned devices is possible, the zone writes are emulated,
2214 but this is namely for testing
2215 .IP \(bu 2
2216 the super block is handled in a special way and is at different locations than on a non\-zoned filesystem:
2217 .INDENT 2.0
2218 .IP \(bu 2
2219 primary: 0B (and the next two zones)
2220 .IP \(bu 2
2221 secondary: 512GiB (and the next two zones)
2222 .IP \(bu 2
2223 tertiary: 4TiB (4096GiB, and the next two zones)
2224 .UNINDENT
2225 .UNINDENT
2226 .SS Incompatible features
2227 .sp
2228 The main constraint of the zoned devices is lack of in\-place update of the data.
2229 This is inherently incompatible with some features:
2230 .INDENT 0.0
2231 .IP \(bu 2
2232 NODATACOW \- overwrite in\-place, cannot create such files
2233 .IP \(bu 2
2234 fallocate \- preallocating space for in\-place first write
2235 .IP \(bu 2
2236 mixed\-bg \- unordered writes to data and metadata, fixing that means using
2237 separate data and metadata block groups
2238 .IP \(bu 2
2239 booting \- the zone at offset 0 contains superblock, resetting the zone would
2240 destroy the bootloader data
2241 .UNINDENT
2242 .sp
2243 Initial support lacks some features but they\(aqre planned:
2244 .INDENT 0.0
2245 .IP \(bu 2
2246 only single (data, metadata) and DUP (metadata) profile is supported
2247 .IP \(bu 2
2248 fstrim \- due to dependency on free space cache v1
2249 .UNINDENT
2250 .SS Super block
2251 .sp
2252 As said above, super block is handled in a special way. In order to be crash
2253 safe, at least one zone in a known location must contain a valid superblock.
2254 This is implemented as a ring buffer in two consecutive zones, starting from
2255 known offsets 0B, 512GiB and 4TiB.
2256 .sp
2257 The values are different than on non\-zoned devices. Each new super block is
2258 appended to the end of the zone, once it\(aqs filled, the zone is reset and writes
2259 continue to the next one. Looking up the latest super block needs to read
2260 offsets of both zones and determine the last written version.
2261 .sp
2262 The amount of space reserved for super block depends on the zone size. The
2263 secondary and tertiary copies are at distant offsets as the capacity of the
2264 devices is expected to be large, tens of terabytes. Maximum zone size supported
2265 is 8GiB, which would mean that e.g. offset 0\-16GiB would be reserved just for
2266 the super block on a hypothetical device of that zone size. This is wasteful
2267 but required to guarantee crash safety.
2268 .SS Zone reclaim, garbage collection
2269 .sp
2270 As the zones are append\-only, overwriting data or COW changes in metadata
2271 make parts of the zones used but not connected to the filesystem structures.
2272 This makes the space unusable and grows over time. Once the ratio hits a
2273 (configurable) threshold a background reclaim process is started and relocates
2274 the remaining blocks in use to a new zone. The old one is reset and can be used
2275 again.
2276 .sp
2277 This process may take some time depending on other background work or
2278 amount of new data written. It is possible to hit an intermittent ENOSPC.
2279 Some devices also limit number of active zones.
2280 .SS Devices
2281 .SS Real hardware
2282 .sp
2283 The WD Ultrastar series 600 advertises HM\-SMR, i.e. the host\-managed zoned
2284 mode. There are two more: DA (device managed, no zoned information exported to
2285 the system), HA (host aware, can be used as regular disk but zoned writes
2286 improve performance). There are not many devices available at the moment, the
2287 information about exact zoned mode is hard to find, check data sheets or
2288 community sources gathering information from real devices.
2289 .sp
2290 Note: zoned mode won\(aqt work with DM\-SMR disks.
2291 .INDENT 0.0
2292 .IP \(bu 2
2293 Ultrastar® DC ZN540 NVMe ZNS SSD (\X'tty: link https://documents.westerndigital.com/content/dam/doc-library/en_us/assets/public/western-digital/collateral/product-brief/product-brief-ultrastar-dc-zn540.pdf'\fI\%product
2294 brief\fP\X'tty: link')
2295 .UNINDENT
2296 .SS Emulated: null_blk
2297 .sp
2298 The driver \fInull_blk\fP provides memory backed device and is suitable for
2299 testing. There are some quirks setting up the devices. The module must be
2300 loaded with \fInr_devices=0\fP or the numbering of device nodes will be offset. The
2301 \fIconfigfs\fP must be mounted at \fI/sys/kernel/config\fP and the administration of
2302 the null_blk devices is done in \fI/sys/kernel/config/nullb\fP\&. The device nodes
2303 are named like \fB/dev/nullb0\fP and are numbered sequentially. NOTE: the device
2304 name may be different than the named directory in sysfs!
2305 .sp
2306 Setup:
2307 .INDENT 0.0
2308 .INDENT 3.5
2309 .sp
2310 .EX
2311 modprobe\ configfs
2312 modprobe\ null_blk\ nr_devices=0
2313 .EE
2314 .UNINDENT
2315 .UNINDENT
2316 .sp
2317 Create a device \fImydev\fP, assuming no other previously created devices, size is
2318 2048MiB, zone size 256MiB. There are more tunable parameters, this is a minimal
2319 example taking defaults:
2320 .INDENT 0.0
2321 .INDENT 3.5
2322 .sp
2323 .EX
2324 cd\ /sys/kernel/config/nullb/
2325 mkdir\ mydev
2326 cd\ mydev
2327 echo\ 2048\ >\ size
2328 echo\ 1\ >\ zoned
2329 echo\ 1\ >\ memory_backed
2330 echo\ 256\ >\ zone_size
2331 echo\ 1\ >\ power
2332 .EE
2333 .UNINDENT
2334 .UNINDENT
2335 .sp
2336 This will create a device \fB/dev/nullb0\fP and the value of file \fIindex\fP will
2337 match the ending number of the device node.
2338 .sp
2339 Remove the device:
2340 .INDENT 0.0
2341 .INDENT 3.5
2342 .sp
2343 .EX
2344 rmdir\ /sys/kernel/config/nullb/mydev
2345 .EE
2346 .UNINDENT
2347 .UNINDENT
2348 .sp
2349 Then continue with \fBmkfs.btrfs /dev/nullb0\fP, the zoned mode is auto\-detected.
2350 .sp
2351 For convenience, there\(aqs a script wrapping the basic null_blk management operations
2352 \X'tty: link https://github.com/kdave/nullb.git'\fI\%https://github.com/kdave/nullb.git\fP\X'tty: link', the above commands become:
2353 .INDENT 0.0
2354 .INDENT 3.5
2355 .sp
2356 .EX
2357 nullb setup
2358 nullb create \-s 2g \-z 256
2359 mkfs.btrfs /dev/nullb0
2360 \&...
2361 nullb rm nullb0
2362 .EE
2363 .UNINDENT
2364 .UNINDENT
2365 .SS Emulated: TCMU runner
2366 .sp
2367 TCMU is a framework to emulate SCSI devices in userspace, providing various
2368 backends for the storage, with zoned support as well. A file\-backed zoned
2369 device can provide more options for larger storage and zone size. Please follow
2370 the instructions at \X'tty: link https://zonedstorage.io/projects/tcmu-runner/'\fI\%https://zonedstorage.io/projects/tcmu\-runner/\fP\X'tty: link' .
2371 .SS Compatibility, incompatibility
2372 .INDENT 0.0
2373 .IP \(bu 2
2374 the feature sets an incompat bit and requires new kernel to access the
2375 filesystem (for both read and write)
2376 .IP \(bu 2
2377 superblock needs to be handled in a special way, there are still 3 copies
2378 but at different offsets (0, 512GiB, 4TiB) and the 2 consecutive zones are a
2379 ring buffer of the superblocks, finding the latest one needs reading it from
2380 the write pointer or do a full scan of the zones
2381 .IP \(bu 2
2382 mixing zoned and non zoned devices is possible (zones are emulated) but is
2383 recommended only for testing
2384 .IP \(bu 2
2385 mixing zoned devices with different zone sizes is not possible
2386 .IP \(bu 2
2387 zone sizes must be power of two, zone sizes of real devices are e.g. 256MiB
2388 or 1GiB, larger size is expected, maximum zone size supported by btrfs is
2389 8GiB
2390 .UNINDENT
2391 .SS Status, stability, reporting bugs
2392 .sp
2393 The zoned mode has been released in 5.12 and there are still some rough edges
2394 and corner cases one can hit during testing. Please report bugs to
2395 \X'tty: link https://github.com/naota/linux/issues/'\fI\%https://github.com/naota/linux/issues/\fP\X'tty: link' .
2396 .SS References
2397 .INDENT 0.0
2398 .IP \(bu 2
2399 \X'tty: link https://zonedstorage.io'\fI\%https://zonedstorage.io\fP\X'tty: link'
2400 .INDENT 2.0
2401 .IP \(bu 2
2402 \X'tty: link https://zonedstorage.io/projects/libzbc/'\fI\%https://zonedstorage.io/projects/libzbc/\fP\X'tty: link' \-\- \fIlibzbc\fP is library and set
2403 of tools to directly manipulate devices with ZBC/ZAC support
2404 .IP \(bu 2
2405 \X'tty: link https://zonedstorage.io/projects/libzbd/'\fI\%https://zonedstorage.io/projects/libzbd/\fP\X'tty: link' \-\- \fIlibzbd\fP uses the kernel
2406 provided zoned block device interface based on the ioctl() system calls
2407 .UNINDENT
2408 .IP \(bu 2
2409 \X'tty: link https://hddscan.com/blog/2020/hdd-wd-smr.html'\fI\%https://hddscan.com/blog/2020/hdd\-wd\-smr.html\fP\X'tty: link' \-\- some details about exact device types
2410 .IP \(bu 2
2411 \X'tty: link https://lwn.net/Articles/853308/'\fI\%https://lwn.net/Articles/853308/\fP\X'tty: link' \-\- \fIBtrfs on zoned block devices\fP
2412 .IP \(bu 2
2413 \X'tty: link https://www.usenix.org/conference/vault20/presentation/bjorling'\fI\%https://www.usenix.org/conference/vault20/presentation/bjorling\fP\X'tty: link' \-\- Zone
2414 Append: A New Way of Writing to Zoned Storage
2415 .UNINDENT
2416 .SH CONTROL DEVICE
2417 .sp
2418 There\(aqs a character special device \fB/dev/btrfs\-control\fP with major and minor
2419 numbers 10 and 234 (the device can be found under the \fImisc\fP category).
2420 .INDENT 0.0
2421 .INDENT 3.5
2422 .sp
2423 .EX
2424 $ ls \-l /dev/btrfs\-control
2425 crw\-\-\-\-\-\-\- 1 root root 10, 234 Jan 1 12:00 /dev/btrfs\-control
2426 .EE
2427 .UNINDENT
2428 .UNINDENT
2429 .sp
2430 The device accepts some ioctl calls that can perform following actions on the
2431 filesystem module:
2432 .INDENT 0.0
2433 .IP \(bu 2
2434 scan devices for btrfs filesystem (i.e. to let multi\-device filesystems mount
2435 automatically) and register them with the kernel module
2436 .IP \(bu 2
2437 similar to scan, but also wait until the device scanning process is finished
2438 for a given filesystem
2439 .IP \(bu 2
2440 get the supported features (can be also found under \fB/sys/fs/btrfs/features\fP)
2441 .UNINDENT
2442 .sp
2443 The device is created when btrfs is initialized, either as a module or a
2444 built\-in functionality and makes sense only in connection with that. Running
2445 e.g. mkfs without the module loaded will not register the device and will
2446 probably warn about that.
2447 .sp
2448 In rare cases when the module is loaded but the device is not present (most
2449 likely accidentally deleted), it\(aqs possible to recreate it by
2450 .INDENT 0.0
2451 .INDENT 3.5
2452 .sp
2453 .EX
2454 # mknod \-\-mode=600 /dev/btrfs\-control c 10 234
2455 .EE
2456 .UNINDENT
2457 .UNINDENT
2458 .sp
2459 or (since 5.11) by a convenience command
2460 .INDENT 0.0
2461 .INDENT 3.5
2462 .sp
2463 .EX
2464 # btrfs rescue create\-control\-device
2465 .EE
2466 .UNINDENT
2467 .UNINDENT
2468 .sp
2469 The control device is not strictly required but the device scanning will not
2470 work and a workaround would need to be used to mount a multi\-device filesystem.
2471 The mount option \fIdevice\fP can trigger the device scanning during mount, see
2472 also \fBbtrfs device scan\fP\&.
2473 .SH FILESYSTEM WITH MULTIPLE PROFILES
2474 .sp
2475 It is possible that a btrfs filesystem contains multiple block group profiles
2476 of the same type. This could happen when a profile conversion using balance
2477 filters is interrupted (see \fI\%btrfs\-balance(8)\fP). Some
2478 \fBbtrfs\fP commands perform
2479 a test to detect this kind of condition and print a warning like this:
2480 .INDENT 0.0
2481 .INDENT 3.5
2482 .sp
2483 .EX
2484 WARNING: Multiple block group profiles detected, see \(aqman btrfs(5)\(aq.
2485 WARNING: Data: single, raid1
2486 WARNING: Metadata: single, raid1
2487 .EE
2488 .UNINDENT
2489 .UNINDENT
2490 .sp
2491 The corresponding output of \fBbtrfs filesystem df\fP might look like:
2492 .INDENT 0.0
2493 .INDENT 3.5
2494 .sp
2495 .EX
2496 WARNING: Multiple block group profiles detected, see \(aqman btrfs(5)\(aq.
2497 WARNING: Data: single, raid1
2498 WARNING: Metadata: single, raid1
2499 Data, RAID1: total=832.00MiB, used=0.00B
2500 Data, single: total=1.63GiB, used=0.00B
2501 System, single: total=4.00MiB, used=16.00KiB
2502 Metadata, single: total=8.00MiB, used=112.00KiB
2503 Metadata, RAID1: total=64.00MiB, used=32.00KiB
2504 GlobalReserve, single: total=16.25MiB, used=0.00B
2505 .EE
2506 .UNINDENT
2507 .UNINDENT
2508 .sp
2509 There\(aqs more than one line for type \fIData\fP and \fIMetadata\fP, while the profiles
2510 are \fIsingle\fP and \fIRAID1\fP\&.
2511 .sp
2512 This state of the filesystem OK but most likely needs the user/administrator to
2513 take an action and finish the interrupted tasks. This cannot be easily done
2514 automatically, also the user knows the expected final profiles.
2515 .sp
2516 In the example above, the filesystem started as a single device and \fIsingle\fP
2517 block group profile. Then another device was added, followed by balance with
2518 \fIconvert=raid1\fP but for some reason hasn\(aqt finished. Restarting the balance
2519 with \fIconvert=raid1\fP will continue and end up with filesystem with all block
2520 group profiles \fIRAID1\fP\&.
2521 .sp
2522 \fBNOTE:\fP
2523 .INDENT 0.0
2524 .INDENT 3.5
2525 If you\(aqre familiar with balance filters, you can use
2526 \fIconvert=raid1,profiles=single,soft\fP, which will take only the unconverted
2527 \fIsingle\fP profiles and convert them to \fIraid1\fP\&. This may speed up the conversion
2528 as it would not try to rewrite the already convert \fIraid1\fP profiles.
2529 .UNINDENT
2530 .UNINDENT
2531 .sp
2532 Having just one profile is desired as this also clearly defines the profile of
2533 newly allocated block groups, otherwise this depends on internal allocation
2534 policy. When there are multiple profiles present, the order of selection is
2535 RAID56, RAID10, RAID1, RAID0 as long as the device number constraints are
2536 satisfied.
2537 .sp
2538 Commands that print the warning were chosen so they\(aqre brought to user
2539 attention when the filesystem state is being changed in that regard. This is:
2540 \fBdevice add\fP, \fBdevice delete\fP, \fBbalance cancel\fP, \fBbalance pause\fP\&. Commands
2541 that report space usage: \fBfilesystem df\fP, \fBdevice usage\fP\&. The command
2542 \fBfilesystem usage\fP provides a line in the overall summary:
2543 .INDENT 0.0
2544 .INDENT 3.5
2545 .sp
2546 .EX
2547 Multiple profiles: yes (data, metadata)
2548 .EE
2549 .UNINDENT
2550 .UNINDENT
2551 .SH SEEDING DEVICE
2552 .sp
2553 The COW mechanism and multiple devices under one hood enable an interesting
2554 concept, called a seeding device: extending a read\-only filesystem on a
2555 device with another device that captures all writes. For example
2556 imagine an immutable golden image of an operating system enhanced with another
2557 device that allows to use the data from the golden image and normal operation.
2558 This idea originated on CD\-ROMs with base OS and allowing to use them for live
2559 systems, but this became obsolete. There are technologies providing similar
2560 functionality, like \X'tty: link https://en.wikipedia.org/wiki/Union_mount'\fI\%unionmount\fP\X'tty: link',
2561 \X'tty: link https://en.wikipedia.org/wiki/OverlayFS'\fI\%overlayfs\fP\X'tty: link' or
2562 \X'tty: link https://en.wikipedia.org/wiki/Qcow#qcow2'\fI\%qcow2\fP\X'tty: link' image snapshot.
2563 .sp
2564 The seeding device starts as a normal filesystem, once the contents is ready,
2565 \fBbtrfstune \-S 1\fP is used to flag it as a seeding device. Mounting such device
2566 will not allow any writes, except adding a new device by \fBbtrfs device add\fP\&.
2567 Then the filesystem can be remounted as read\-write.
2568 .sp
2569 Given that the filesystem on the seeding device is always recognized as
2570 read\-only, it can be used to seed multiple filesystems from one device at the
2571 same time. The UUID that is normally attached to a device is automatically
2572 changed to a random UUID on each mount.
2573 .sp
2574 Once the seeding device is mounted, it needs the writable device. After adding
2575 it, unmounting and mounting with \fBumount /path; mount /dev/writable
2576 /path\fP or remounting read\-write with \fBremount \-o remount,rw\fP makes the
2577 filesystem at \fB/path\fP ready for use.
2578 .sp
2579 \fBNOTE:\fP
2580 .INDENT 0.0
2581 .INDENT 3.5
2582 There is a known bug with using remount to make the mount writeable:
2583 remount will leave the filesystem in a state where it is unable to
2584 clean deleted snapshots, so it will leak space until it is unmounted
2585 and mounted properly.
2586 .UNINDENT
2587 .UNINDENT
2588 .sp
2589 Furthermore, deleting the seeding device from the filesystem can turn it into
2590 a normal filesystem, provided that the writable device can also contain all the
2591 data from the seeding device.
2592 .sp
2593 The seeding device flag can be cleared again by \fBbtrfstune \-f \-S 0\fP, e.g.
2594 allowing to update with newer data but please note that this will invalidate
2595 all existing filesystems that use this particular seeding device. This works
2596 for some use cases, not for others, and the forcing flag to the command is
2597 mandatory to avoid accidental mistakes.
2598 .sp
2599 Example how to create and use one seeding device:
2600 .INDENT 0.0
2601 .INDENT 3.5
2602 .sp
2603 .EX
2604 # mkfs.btrfs /dev/sda
2605 # mount /dev/sda /mnt/mnt1
2606 \&... fill mnt1 with data
2607 # umount /mnt/mnt1
2608
2609 # btrfstune \-S 1 /dev/sda
2610
2611 # mount /dev/sda /mnt/mnt1
2612 # btrfs device add /dev/sdb /mnt/mnt1
2613 # umount /mnt/mnt1
2614 # mount /dev/sdb /mnt/mnt1
2615 \&... /mnt/mnt1 is now writable
2616 .EE
2617 .UNINDENT
2618 .UNINDENT
2619 .sp
2620 Now \fB/mnt/mnt1\fP can be used normally. The device \fB/dev/sda\fP can be mounted
2621 again with a another writable device:
2622 .INDENT 0.0
2623 .INDENT 3.5
2624 .sp
2625 .EX
2626 # mount /dev/sda /mnt/mnt2
2627 # btrfs device add /dev/sdc /mnt/mnt2
2628 # umount /mnt/mnt2
2629 # mount /dev/sdc /mnt/mnt2
2630 \&... /mnt/mnt2 is now writable
2631 .EE
2632 .UNINDENT
2633 .UNINDENT
2634 .sp
2635 The writable device (file:\fI/dev/sdb\fP) can be decoupled from the seeding device and
2636 used independently:
2637 .INDENT 0.0
2638 .INDENT 3.5
2639 .sp
2640 .EX
2641 # btrfs device delete /dev/sda /mnt/mnt1
2642 .EE
2643 .UNINDENT
2644 .UNINDENT
2645 .sp
2646 As the contents originated in the seeding device, it\(aqs possible to turn
2647 \fB/dev/sdb\fP to a seeding device again and repeat the whole process.
2648 .sp
2649 A few things to note:
2650 .INDENT 0.0
2651 .IP \(bu 2
2652 it\(aqs recommended to use only single device for the seeding device, it works
2653 for multiple devices but the \fIsingle\fP profile must be used in order to make
2654 the seeding device deletion work
2655 .IP \(bu 2
2656 block group profiles \fIsingle\fP and \fIdup\fP support the use cases above
2657 .IP \(bu 2
2658 the label is copied from the seeding device and can be changed by \fBbtrfs filesystem label\fP
2659 .IP \(bu 2
2660 each new mount of the seeding device gets a new random UUID
2661 .IP \(bu 2
2662 \fBumount /path; mount /dev/writable /path\fP can be replaced with
2663 \fBmount \-o remount,rw /path\fP
2664 but it won\(aqt reclaim space of deleted subvolumes until the seeding device
2665 is mounted read\-write again before making it seeding again
2666 .UNINDENT
2667 .SS Chained seeding devices
2668 .sp
2669 Though it\(aqs not recommended and is rather an obscure and untested use case,
2670 chaining seeding devices is possible. In the first example, the writable device
2671 \fB/dev/sdb\fP can be turned onto another seeding device again, depending on the
2672 unchanged seeding device \fB/dev/sda\fP\&. Then using \fB/dev/sdb\fP as the primary
2673 seeding device it can be extended with another writable device, say \fB/dev/sdd\fP,
2674 and it continues as before as a simple tree structure on devices.
2675 .INDENT 0.0
2676 .INDENT 3.5
2677 .sp
2678 .EX
2679 # mkfs.btrfs /dev/sda
2680 # mount /dev/sda /mnt/mnt1
2681 \&... fill mnt1 with data
2682 # umount /mnt/mnt1
2683
2684 # btrfstune \-S 1 /dev/sda
2685
2686 # mount /dev/sda /mnt/mnt1
2687 # btrfs device add /dev/sdb /mnt/mnt1
2688 # mount \-o remount,rw /mnt/mnt1
2689 \&... /mnt/mnt1 is now writable
2690 # umount /mnt/mnt1
2691
2692 # btrfstune \-S 1 /dev/sdb
2693
2694 # mount /dev/sdb /mnt/mnt1
2695 # btrfs device add /dev/sdc /mnt
2696 # mount \-o remount,rw /mnt/mnt1
2697 \&... /mnt/mnt1 is now writable
2698 # umount /mnt/mnt1
2699 .EE
2700 .UNINDENT
2701 .UNINDENT
2702 .sp
2703 As a result we have:
2704 .INDENT 0.0
2705 .IP \(bu 2
2706 \fIsda\fP is a single seeding device, with its initial contents
2707 .IP \(bu 2
2708 \fIsdb\fP is a seeding device but requires \fIsda\fP, the contents are from the time
2709 when \fIsdb\fP is made seeding, i.e. contents of \fIsda\fP with any later changes
2710 .IP \(bu 2
2711 \fIsdc\fP last writable, can be made a seeding one the same way as was \fIsdb\fP,
2712 preserving its contents and depending on \fIsda\fP and \fIsdb\fP
2713 .UNINDENT
2714 .sp
2715 As long as the seeding devices are unmodified and available, they can be used
2716 to start another branch.
2717 .SH RAID56 STATUS AND RECOMMENDED PRACTICES
2718 .sp
2719 The RAID56 feature provides striping and parity over several devices, same as
2720 the traditional RAID5/6. There are some implementation and design deficiencies
2721 that make it unreliable for some corner cases and the feature \fBshould not be
2722 used in production, only for evaluation or testing\fP\&. The power failure safety
2723 for metadata with RAID56 is not 100%.
2724 .SS Metadata
2725 .sp
2726 Do not use \fIraid5\fP nor \fIraid6\fP for metadata. Use \fIraid1\fP or \fIraid1c3\fP
2727 respectively.
2728 .sp
2729 The substitute profiles provide the same guarantees against loss of 1 or 2
2730 devices, and in some respect can be an improvement. Recovering from one
2731 missing device will only need to access the remaining 1st or 2nd copy, that in
2732 general may be stored on some other devices due to the way RAID1 works on
2733 btrfs, unlike on a striped profile (similar to \fIraid0\fP) that would need all
2734 devices all the time.
2735 .sp
2736 The space allocation pattern and consumption is different (e.g. on N devices):
2737 for \fIraid5\fP as an example, a 1GiB chunk is reserved on each device, while with
2738 \fIraid1\fP there\(aqs each 1GiB chunk stored on 2 devices. The consumption of each
2739 1GiB of used metadata is then \fIN * 1GiB\fP for vs \fI2 * 1GiB\fP\&. Using \fIraid1\fP
2740 is also more convenient for balancing/converting to other profile due to lower
2741 requirement on the available chunk space.
2742 .SS Missing/incomplete support
2743 .sp
2744 When RAID56 is on the same filesystem with different raid profiles, the space
2745 reporting is inaccurate, e.g. \fBdf\fP, \fBbtrfs filesystem df\fP or
2746 \fBbtrfs filesystem usage\fP\&. When there\(aqs only a one profile per block
2747 group type (e.g. RAID5 for data) the reporting is accurate.
2748 .sp
2749 When scrub is started on a RAID56 filesystem, it\(aqs started on all devices that
2750 degrade the performance. The workaround is to start it on each device
2751 separately. Due to that the device stats may not match the actual state and
2752 some errors might get reported multiple times.
2753 .sp
2754 The \fIwrite hole\fP problem. An unclean shutdown could leave a partially written
2755 stripe in a state where the some stripe ranges and the parity are from the old
2756 writes and some are new. The information which is which is not tracked. Write
2757 journal is not implemented. Alternatively a full read\-modify\-write would make
2758 sure that a full stripe is always written, avoiding the write hole completely,
2759 but performance in that case turned out to be too bad for use.
2760 .sp
2761 The striping happens on all available devices (at the time the chunks were
2762 allocated), so in case a new device is added it may not be utilized
2763 immediately and would require a rebalance. A fixed configured stripe width is
2764 not implemented.
2765 .SH GLOSSARY
2766 .sp
2767 Terms in \fIitalics\fP also appear in this glossary.
2768 .INDENT 0.0
2769 .TP
2770 .B allocator
2771 Usually \fIallocator\fP means the \fIblock\fP allocator, i.e. the logic
2772 inside the filesystem which decides where to place newly allocated blocks
2773 in order to maintain several constraints (like data locality, low
2774 fragmentation).
2775 .sp
2776 In btrfs, allocator may also refer to \fIchunk\fP allocator, i.e. the
2777 logic behind placing chunks on devices.
2778 .TP
2779 .B balance
2780 An operation that can be done to a btrfs filesystem, for example
2781 through \fBbtrfs balance /path\fP\&. A
2782 balance passes all data in the filesystem through the \fIallocator\fP
2783 again. It is primarily intended to rebalance the data in the filesystem
2784 across the \fIdevices\fP when a device is added or removed. A balance
2785 will regenerate missing copies for the redundant \fIRAID\fP levels, if a
2786 device has failed. As of Linux kernel 3.3, a balance operation can be
2787 made selective about which parts of the filesystem are rewritten
2788 using \fI\%filters\fP\&.
2789 .TP
2790 .B barrier
2791 An instruction to the underlying hardware to ensure that everything before
2792 the barrier is physically written to permanent storage before anything
2793 after it. Used in btrfs\(aqs \fIcopy on write\fP approach to ensure
2794 filesystem consistency.
2795 .TP
2796 .B block
2797 A single physically and logically contiguous piece of storage on a
2798 device, of size e.g. 4K. In some contexts also referred to as \fIsector\fP,
2799 though the term \fIblock\fP is preferred.
2800 .TP
2801 .B block group
2802 The unit of allocation of space in btrfs. A block group is laid out on
2803 the disk by the btrfs \fIallocator\fP, and will consist of one or more
2804 \fIchunks\fP, each stored on a different \fIdevice\fP\&. The number of chunks
2805 used in a block group will depend on its \fIRAID\fP level.
2806 .TP
2807 .B B\-tree
2808 The fundamental storage data structure used in btrfs. Except for the
2809 \fIsuperblocks\fP, all of btrfs \fImetadata\fP is stored in one of several
2810 B\-trees on disk. B\-trees store key/item pairs. While the same code is
2811 used to implement all of the B\-trees, there are a few different
2812 categories of B\-tree. The name \fIbtrfs\fP refers to its use of B\-trees.
2813 .TP
2814 .B btrfsck, fsck, btrfs\-check
2815 Tool in \fIbtrfs\-progs\fP that checks an unmounted filesystem (\fIoffline\fP)
2816 and reports on any errors in the filesystem structures it finds. By
2817 default the tool runs in read\-only mode as fixing errors is potentially
2818 dangerous. See also \fIscrub\fP\&.
2819 .TP
2820 .B btrfs\-progs
2821 User mode tools to manage btrfs\-specific features. Maintained at
2822 \X'tty: link http://github.com/kdave/btrfs-progs.git'\fI\%http://github.com/kdave/btrfs\-progs.git\fP\X'tty: link' . The main frontend to btrfs
2823 features is the standalone tool \fIbtrfs\fP, although
2824 other tools such as \fImkfs.btrfs\fP and \fIbtrfstune\fP are also part of
2825 btrfs\-progs.
2826 .TP
2827 .B chunk
2828 A part of a \fIblock group\fP\&. Chunks are either 1 GiB in size (for data)
2829 or 256 MiB (for \fImetadata\fP), depending on the overall filesystem size.
2830 .TP
2831 .B chunk tree
2832 A layer that keeps information about mapping between physical and
2833 logical block addresses. It\(aqs stored within the \fIsystem\fP group.
2834 .TP
2835 .B cleaner
2836 Usually referred to in context of deleted subvolumes. It\(aqs a background
2837 process that removes the actual data once a subvolume has been deleted.
2838 Cleaning can involve lots of IO and CPU activity depending on the
2839 fragmentation and amount of shared data with other subvolumes.
2840 .sp
2841 The cleaner kernel thread also processes defragmentation triggered by the
2842 \fIautodefrag\fP mount option, removing of empty blocks groups and some
2843 other finalization tasks.
2844 .TP
2845 .B copy\-on\-write, COW
2846 Also known as \fICOW\fP\&. The method that btrfs uses for modifying data.
2847 Instead of directly overwriting data in place, btrfs takes a copy of
2848 the data, alters it, and then writes the modified data back to a
2849 different (unused) location on the disk. It then updates the \fImetadata\fP
2850 to reflect the new location of the data. In order to update the
2851 metadata, the affected metadata blocks are also treated in the same
2852 way. In COW filesystems, files tend to fragment as they are modified.
2853 Copy\-on\-write is also used in the implementation of \fIsnapshots\fP and
2854 \fIreflink copies\fP\&. A copy\-on\-write filesystem is, in theory,
2855 \fIalways\fP consistent, provided the underlying hardware supports
2856 \fIbarriers\fP\&.
2857 .TP
2858 .B default subvolume
2859 The \fIsubvolume\fP in a btrfs filesystem which is mounted when mounting
2860 the filesystem without using the \fBsubvol=\fP mount option.
2861 .TP
2862 .B device
2863 A Linux block device, e.g. a whole disk, partition, LVM logical volume,
2864 loopback device, or network block device. A btrfs filesystem can reside
2865 on one or more devices.
2866 .TP
2867 .B df
2868 A standard Unix tool for reporting the amount of space used and free in
2869 a filesystem. The standard tool does not give accurate results, but the
2870 \fIbtrfs\fP command from \fIbtrfs\-progs\fP has
2871 an implementation of \fIdf\fP which shows space available in more detail. See
2872 the
2873 [[FAQ#Why_does_df_show_incorrect_free_space_for_my_RAID_volume.3F|FAQ]]
2874 for a more detailed explanation of btrfs free space accounting.
2875 .TP
2876 .B DUP
2877 A form of \(dq\fIRAID\fP\(dq which stores two copies of each piece of data on
2878 the same \fIdevice\fP\&. This is similar to \fIRAID1\fP, and protects
2879 against \fIblock\fP\-level errors on the device, but does not provide any
2880 guarantees if the entire device fails. By default, btrfs uses \fIDUP\fP
2881 profile for metadata on single device filesystem.s
2882 .TP
2883 .B ENOSPC
2884 Error code returned by the OS to a user program when the filesystem
2885 cannot allocate enough data to fulfill the user request. In most
2886 filesystems, it indicates there is no free space available in the
2887 filesystem. Due to the additional space requirements from btrfs\(aqs
2888 \fICOW\fP behaviour, btrfs can sometimes return ENOSPC when there is
2889 apparently (in terms of \fIdf\fP) a large amount of space free. This is
2890 effectively a bug in btrfs, and (if it is repeatable), using the mount
2891 option \fBenospc_debug\fP may give a report
2892 that will help the btrfs developers. See the
2893 [[FAQ#if_your_device_is_large_.28.3E16GiB.29|FAQ entry]] on free space.
2894 .TP
2895 .B extent
2896 Contiguous sequence of bytes on disk that holds file data. It\(aqs a compact
2897 representation that tracks the start and length of the byte range, so the
2898 logic behind allocating blocks (\fIdelayed allocation\fP) strives for
2899 maximizing the length before writing the extents to the devices.
2900 .TP
2901 .B extent buffer
2902 An abstraction of a \fIb\-tree\fP metadata block storing item keys and item
2903 data. The underlying related structures are physical device block and a
2904 CPU memory page.
2905 .TP
2906 .B fallocate
2907 Command line tool in util\-linux, and a syscall, that reserves space in
2908 the filesystem for a file, without actually writing any file data to
2909 the filesystem. First data write will turn the preallocated extents
2910 into regular ones. See \X'tty: link https://man7.org/linux/man-pages/man1/fallocate.1.html'\fI\%fallocate(1)\fP\X'tty: link' and \X'tty: link https://man7.org/linux/man-pages/man2/fallocate.2.html'\fI\%fallocate(2)\fP\X'tty: link' manual pages
2911 for more details.
2912 .TP
2913 .B filefrag
2914 A tool to show the number of extents in a file, and hence the amount of
2915 fragmentation in the file. It is usually part of the e2fsprogs package
2916 on most Linux distributions. While initially developed for the ext2
2917 filesystem, it works on Btrfs as well. It uses the \fIFIEMAP\fP ioctl.
2918 .TP
2919 .B free space cache
2920 Also known as \(dqspace cache v1\(dq. A separate cache tracking free space as
2921 btrfs only tracks the allocated space. The free space is by definition
2922 any hole between allocated ranges. Finding the free ranges can be
2923 I/O intensive so the cache stores a condensed representation of it.
2924 It is updated every \fItransaction\fP commit.
2925 .sp
2926 The v1 free space cache has been superseded by free space tree.
2927 .TP
2928 .B free space tree
2929 Successor of \fIfree space cache\fP, also known as \(dqspace cache v2\(dq and now
2930 default. The free space is tracked in a better way and using COW
2931 unlike a custom mechanism of v1.
2932 .TP
2933 .B fsync
2934 On Unix and Unix\-like operating systems (of which Linux is the latter),
2935 the \X'tty: link https://man7.org/linux/man-pages/man2/fsync.2.html'\fI\%fsync(2)\fP\X'tty: link' system call causes all buffered file
2936 descriptor related data changes to be flushed to the underlying block
2937 device. When a file is modified on a modern operating system the
2938 changes are generally not written to the disk immediately but rather
2939 those changes are buffered in memory for performance reasons,
2940 calling \X'tty: link https://man7.org/linux/man-pages/man2/fsync.2.html'\fI\%fsync(2)\fP\X'tty: link' causes any in\-memory changes to be written
2941 to disk.
2942 .TP
2943 .B generation
2944 An internal counter which updates for each \fItransaction\fP\&. When a
2945 \fImetadata\fP block is written (using \fIcopy on write\fP), current
2946 generation is stored in the block, so that blocks which are too new
2947 (and hence possibly inconsistent) can be identified.
2948 .TP
2949 .B key
2950 A fixed sized tuple used to identify and sort items in a \fIB\-tree\fP\&.
2951 The key is broken up into 3 parts: \fIobjectid\fP, \fItype\fP, and
2952 \fIoffset\fP\&. The \fItype\fP field indicates how each of the other two
2953 fields should be used, and what to expect to find in the item.
2954 .TP
2955 .B item
2956 A variable sized structure stored in B\-tree leaves. Items hold
2957 different types of data depending on key type.
2958 .TP
2959 .B log tree
2960 A b\-tree that temporarily tracks ongoing metadata updates until a full
2961 transaction commit is done. It\(aqs a performance optimization of
2962 \fIfsync\fP\&. The log tracked in the tree are replayed if the filesystem
2963 is not unmounted cleanly.
2964 .TP
2965 .B metadata
2966 Data about data. In btrfs, this includes all of the internal data
2967 structures of the filesystem, including directory structures,
2968 filenames, file permissions, checksums, and the location of each file\(aqs
2969 \fIextents\fP\&. All btrfs metadata is stored in \fIB\-trees\fP\&.
2970 .TP
2971 .B mkfs.btrfs
2972 The tool (from \fIbtrfs\-progs\fP) to create a btrfs filesystem.
2973 .TP
2974 .B offline
2975 A filesystem which is not mounted is offline. Some tools (e.g.
2976 \fIbtrfsck\fP) will only work on offline filesystems. Compare \fIonline\fP\&.
2977 .TP
2978 .B online
2979 A filesystem which is mounted is online. Most btrfs tools will only
2980 work on online filesystems. Compare \fIoffline\fP\&.
2981 .TP
2982 .B orphan
2983 A file that\(aqs still in use (opened by a running process) but all
2984 directory entries of that file have been removed.
2985 .TP
2986 .B RAID
2987 A class of different methods for writing some additional redundant data
2988 across multiple \fIdevices\fP so that if one device fails, the missing
2989 data can be reconstructed from the remaining ones. See \fIRAID0\fP,
2990 \fIRAID1\fP, \fIRAID5\fP, \fIRAID6\fP, \fIRAID10\fP, \fIDUP\fP and
2991 \fIsingle\fP\&. Traditional RAID methods operate across multiple devices of
2992 equal size, whereas btrfs\(aq RAID implementation works inside \fIblock
2993 groups\fP\&.
2994 .TP
2995 .B RAID0
2996 A form of \fIRAID\fP which provides no guarantees of error recovery, but
2997 stripes a single copy of data across multiple devices for performance
2998 purposes. The stripe size is fixed to 64KB for now.
2999 .TP
3000 .B RAID1, RAID1C3, RAID1C4
3001 A form of \fIRAID\fP which stores two/three/four complete copies of each
3002 piece of data. Each copy is stored on a different \fIdevice\fP\&. btrfs
3003 requires a minimum of two devices to use RAID\-1 or three/four respectively.
3004 This is the default block group profile for btrfs\(aqs \fImetadata\fP on more
3005 than one device.
3006 .TP
3007 .B RAID5
3008 A form of \fIRAID\fP which stripes a single copy of data across multiple
3009 \fIdevices\fP, including one device\(aqs worth of additional parity data.
3010 Can be used to recover from a single device failure.
3011 .TP
3012 .B RAID6
3013 A form of \fIRAID\fP which stripes a single copy of data across multiple
3014 \fIdevices\fP, including two device\(aqs worth of additional parity data. Can
3015 be used to recover from the failure of two devices.
3016 .TP
3017 .B RAID10
3018 A form of \fIRAID\fP which stores two complete copies of each piece of
3019 data, and also stripes each copy across multiple devices for
3020 performance.
3021 .TP
3022 .B reflink
3023 Commonly used as a reference to a shallow copy of file extents that share
3024 the extents until the first change. Reflinked files (e.g. by the \fBcp\fP)
3025 are different files but point to the same extents, any change will be
3026 detected and new copy of the data created, keeping the files independent.
3027 Related to that is extent range cloning, that works on a range of a file.
3028 .TP
3029 .B relocation
3030 The process of moving block groups within the filesystem while
3031 maintaining full filesystem integrity and consistency. This
3032 functionality is underlying \fIbalance\fP and \fIdevice\fP removing features.
3033 .TP
3034 .B \fI\%scrub\fP
3035 An \fIonline\fP filesystem checking tool. Reads all the data and metadata
3036 on the filesystem, verifies \fIchecksums\fP and eventually uses redundant
3037 copies from \fIRAID\fP or \fIDUP\fP repair any corrupt data/metadata.
3038 .TP
3039 .B \fI\%seed device\fP
3040 A readonly device can be used as a filesystem seed or template (e.g. a
3041 CD\-ROM containing an OS image). Read/write devices can be added to
3042 store modifications (using \fIcopy on write\fP), changes to the writable
3043 devices are persistent across reboots. The original device remains
3044 unchanged and can be removed at any time (after Btrfs has been
3045 instructed to copy over all missing blocks). Multiple read/write file
3046 systems can be built from the same seed.
3047 .TP
3048 .B single
3049 A block group profile storing a single copy of each piece of data.
3050 .TP
3051 .B \fI\%snapshot\fP
3052 A \fIsubvolume\fP which is a \fIcopy on write\fP copy of another subvolume. The
3053 two subvolumes share all of their common (unmodified) data, which means
3054 that snapshots can be used to keep the historical state of a filesystem
3055 very cheaply. After the snapshot is made, the original subvolume and
3056 the snapshot are of equal status: the original does not \(dqown\(dq the
3057 snapshot, and either one can be deleted without affecting the other
3058 one.
3059 .TP
3060 .B \fI\%subvolume\fP
3061 A tree of files and directories inside a btrfs that can be mounted as
3062 if it were an independent filesystem. A subvolume is created by taking
3063 a reference on the root of another subvolume. Each btrfs filesystem has
3064 at least one subvolume, the \fItop\-level subvolume\fP, which contains
3065 everything else in the filesystem. Additional subvolumes can be created
3066 and deleted with the \fIbtrfs<\fP tool. All subvolumes share the same pool
3067 of free space in the filesystem. See also \fIdefault subvolume\fP\&.
3068 .TP
3069 .B super block
3070 A special metadata block that is a main access point of the filesystem
3071 structures. It\(aqs size is fixed and there are fixed locations on the devices
3072 used for detecting and opening the filesystem. Updating the superblock
3073 defines one \fItransaction\fP\&. The super blocks contains filesystem
3074 identification (UUID), checksum type, block pointers to fundamental
3075 trees, features and creation parameters.
3076 .TP
3077 .B system array
3078 A technical term for \fIsuper block\fP metadata describing how to assemble a
3079 filesystem from multiple device, storing information about chunks and devices that are
3080 required to be scanned/registered at the time the mount happens.
3081 Scanning is done by command \fBbtrfs device scan\fP, alternatively
3082 all the required devices can be specified by a mount option \fIdevice=/path\fP\&.
3083 .TP
3084 .B top\-level subvolume
3085 The \fIsubvolume\fP at the very top of the filesystem. This is the only
3086 subvolume present in a newly\-created btrfs filesystem, and internally has ID 5,
3087 otherwise could be referenced as 0 (e.g. within the \fIset\-default\fP subcommand of
3088 \fIbtrfs\fP).
3089 .TP
3090 .B transaction
3091 A consistent set of changes. To avoid generating very large amounts of
3092 disk activity, btrfs caches changes in RAM for up to 30 seconds
3093 (sometimes more often if the filesystem is running short on space or
3094 doing a lot of \fIfsync*s), and then writes (commits) these changes out
3095 to disk in one go (using *copy on write\fP behaviour). This period of
3096 caching is called a transaction. Only one transaction is active on the
3097 filesystem at any one time.
3098 .TP
3099 .B transid
3100 An alternative term for \fIgeneration\fP\&.
3101 .TP
3102 .B writeback
3103 \fIWriteback\fP in the context of the Linux kernel can be defined as the
3104 process of writing \(dqdirty\(dq memory from the page cache to the disk,
3105 when certain conditions are met (timeout, number of dirty pages over a
3106 ratio).
3107 .UNINDENT
3108 .SH STORAGE MODEL, HARDWARE CONSIDERATIONS
3109 .SS Storage model
3110 .sp
3111 \fIA storage model is a model that captures key physical aspects of data
3112 structure in a data store. A filesystem is the logical structure organizing
3113 data on top of the storage device.\fP
3114 .sp
3115 The filesystem assumes several features or limitations of the storage device
3116 and utilizes them or applies measures to guarantee reliability. BTRFS in
3117 particular is based on a COW (copy on write) mode of writing, i.e. not updating
3118 data in place but rather writing a new copy to a different location and then
3119 atomically switching the pointers.
3120 .sp
3121 In an ideal world, the device does what it promises. The filesystem assumes
3122 that this may not be true so additional mechanisms are applied to either detect
3123 misbehaving hardware or get valid data by other means. The devices may (and do)
3124 apply their own detection and repair mechanisms but we won\(aqt assume any.
3125 .sp
3126 The following assumptions about storage devices are considered (sorted by
3127 importance, numbers are for further reference):
3128 .INDENT 0.0
3129 .IP 1. 3
3130 atomicity of reads and writes of blocks/sectors (the smallest unit of data
3131 the device presents to the upper layers)
3132 .IP 2. 3
3133 there\(aqs a flush command that instructs the device to forcibly order writes
3134 before and after the command; alternatively there\(aqs a barrier command that
3135 facilitates the ordering but may not flush the data
3136 .IP 3. 3
3137 data sent to write to a given device offset will be written without further
3138 changes to the data and to the offset
3139 .IP 4. 3
3140 writes can be reordered by the device, unless explicitly serialized by the
3141 flush command
3142 .IP 5. 3
3143 reads and writes can be freely reordered and interleaved
3144 .UNINDENT
3145 .sp
3146 The consistency model of BTRFS builds on these assumptions. The logical data
3147 updates are grouped, into a generation, written on the device, serialized by
3148 the flush command and then the super block is written ending the generation.
3149 All logical links among metadata comprising a consistent view of the data may
3150 not cross the generation boundary.
3151 .SS When things go wrong
3152 .sp
3153 \fBNo or partial atomicity of block reads/writes (1)\fP
3154 .INDENT 0.0
3155 .IP \(bu 2
3156 \fIProblem\fP: a partial block contents is written (\fItorn write\fP), e.g. due to a
3157 power glitch or other electronics failure during the read/write
3158 .IP \(bu 2
3159 \fIDetection\fP: checksum mismatch on read
3160 .IP \(bu 2
3161 \fIRepair\fP: use another copy or rebuild from multiple blocks using some encoding
3162 scheme
3163 .UNINDENT
3164 .sp
3165 \fBThe flush command does not flush (2)\fP
3166 .sp
3167 This is perhaps the most serious problem and impossible to mitigate by
3168 filesystem without limitations and design restrictions. What could happen in
3169 the worst case is that writes from one generation bleed to another one, while
3170 still letting the filesystem consider the generations isolated. Crash at any
3171 point would leave data on the device in an inconsistent state without any hint
3172 what exactly got written, what is missing and leading to stale metadata link
3173 information.
3174 .sp
3175 Devices usually honor the flush command, but for performance reasons may do
3176 internal caching, where the flushed data are not yet persistently stored. A
3177 power failure could lead to a similar scenario as above, although it\(aqs less
3178 likely that later writes would be written before the cached ones. This is
3179 beyond what a filesystem can take into account. Devices or controllers are
3180 usually equipped with batteries or capacitors to write the cache contents even
3181 after power is cut. (\fIBattery backed write cache\fP)
3182 .sp
3183 \fBData get silently changed on write (3)\fP
3184 .sp
3185 Such thing should not happen frequently, but still can happen spuriously due
3186 the complex internal workings of devices or physical effects of the storage
3187 media itself.
3188 .INDENT 0.0
3189 .IP \(bu 2
3190 \fIProblem\fP: while the data are written atomically, the contents get changed
3191 .IP \(bu 2
3192 \fIDetection\fP: checksum mismatch on read
3193 .IP \(bu 2
3194 \fIRepair\fP: use another copy or rebuild from multiple blocks using some
3195 encoding scheme
3196 .UNINDENT
3197 .sp
3198 \fBData get silently written to another offset (3)\fP
3199 .sp
3200 This would be another serious problem as the filesystem has no information
3201 when it happens. For that reason the measures have to be done ahead of time.
3202 This problem is also commonly called \fIghost write\fP\&.
3203 .sp
3204 The metadata blocks have the checksum embedded in the blocks, so a correct
3205 atomic write would not corrupt the checksum. It\(aqs likely that after reading
3206 such block the data inside would not be consistent with the rest. To rule that
3207 out there\(aqs embedded block number in the metadata block. It\(aqs the logical
3208 block number because this is what the logical structure expects and verifies.
3209 .sp
3210 The following is based on information publicly available, user feedback,
3211 community discussions or bug report analyses. It\(aqs not complete and further
3212 research is encouraged when in doubt.
3213 .SS Main memory
3214 .sp
3215 The data structures and raw data blocks are temporarily stored in computer
3216 memory before they get written to the device. It is critical that memory is
3217 reliable because even simple bit flips can have vast consequences and lead to
3218 damaged structures, not only in the filesystem but in the whole operating
3219 system.
3220 .sp
3221 Based on experience in the community, memory bit flips are more common than one
3222 would think. When it happens, it\(aqs reported by the tree\-checker or by a checksum
3223 mismatch after reading blocks. There are some very obvious instances of bit
3224 flips that happen, e.g. in an ordered sequence of keys in metadata blocks. We can
3225 easily infer from the other data what values get damaged and how. However, fixing
3226 that is not straightforward and would require cross\-referencing data from the
3227 entire filesystem to see the scope.
3228 .sp
3229 If available, ECC memory should lower the chances of bit flips, but this
3230 type of memory is not available in all cases. A memory test should be performed
3231 in case there\(aqs a visible bit flip pattern, though this may not detect a faulty
3232 memory module because the actual load of the system could be the factor making
3233 the problems appear. In recent years attacks on how the memory modules operate
3234 have been demonstrated (\fIrowhammer\fP) achieving specific bits to be flipped.
3235 While these were targeted, this shows that a series of reads or writes can
3236 affect unrelated parts of memory.
3237 .sp
3238 Block group profiles with redundancy (like RAID1) will not protect against
3239 memory errors as the blocks are first stored in memory before they are written
3240 to the devices from the same source.
3241 .sp
3242 A filesystem mounted read\-only will not affect the underlying block device in
3243 almost 100% (with highly unlikely exceptions). The exception is a tree\-log that
3244 needs to be replayed during mount (and before the read\-only mount takes place),
3245 working memory is needed for that and that can be affected by bit flips.
3246 There\(aqs a theoretical case where bit flip changes the filesystem status from
3247 read\-only to read\-write.
3248 .sp
3249 Further reading:
3250 .INDENT 0.0
3251 .IP \(bu 2
3252 \X'tty: link https://en.wikipedia.org/wiki/Row_hammer'\fI\%https://en.wikipedia.org/wiki/Row_hammer\fP\X'tty: link'
3253 .IP \(bu 2
3254 memory overclocking, XMP, potential risks
3255 .UNINDENT
3256 .sp
3257 What to do:
3258 .INDENT 0.0
3259 .IP \(bu 2
3260 run \fImemtest\fP, note that sometimes memory errors happen only when the system
3261 is under heavy load that the default memtest cannot trigger
3262 .IP \(bu 2
3263 memory errors may appear as filesystem going read\-only due to \(dqpre write\(dq
3264 check, that verify meta data before they get written but fail some basic
3265 consistency checks
3266 .IP \(bu 2
3267 newly built systems should be tested before being put to production use,
3268 ideally start a IO/CPU load that will be run on such system later; namely
3269 systems that will utilize overclocking or special performance features
3270 .UNINDENT
3271 .SS Direct memory access (DMA)
3272 .sp
3273 Another class of errors is related to DMA (direct memory access) performed
3274 by device drivers. While this could be considered a software error, the
3275 data transfers that happen without CPU assistance may accidentally corrupt
3276 other pages. Storage devices utilize DMA for performance reasons, the
3277 filesystem structures and data pages are passed back and forth, making
3278 errors possible in case page life time is not properly tracked.
3279 .sp
3280 There are lots of quirks (device\-specific workarounds) in Linux kernel
3281 drivers (regarding not only DMA) that are added when found. The quirks
3282 may avoid specific errors or disable some features to avoid worse problems.
3283 .sp
3284 What to do:
3285 .INDENT 0.0
3286 .IP \(bu 2
3287 use up\-to\-date kernel (recent releases or maintained long term support versions)
3288 .IP \(bu 2
3289 as this may be caused by faulty drivers, keep the systems up\-to\-date
3290 .UNINDENT
3291 .SS Rotational disks (HDD)
3292 .sp
3293 Rotational HDDs typically fail at the level of individual sectors or small clusters.
3294 Read failures are caught on the levels below the filesystem and are returned to
3295 the user as \fIEIO \- Input/output error\fP\&. Reading the blocks repeatedly may
3296 return the data eventually, but this is better done by specialized tools and
3297 filesystem takes the result of the lower layers. Rewriting the sectors may
3298 trigger internal remapping but this inevitably leads to data loss.
3299 .sp
3300 Disk firmware is technically software but from the filesystem perspective is
3301 part of the hardware. IO requests are processed, and caching or various
3302 other optimizations are performed, which may lead to bugs under high load or
3303 unexpected physical conditions or unsupported use cases.
3304 .sp
3305 Disks are connected by cables with two ends, both of which can cause problems
3306 when not attached properly. Data transfers are protected by checksums and the
3307 lower layers try hard to transfer the data correctly or not at all. The errors
3308 from badly\-connecting cables may manifest as large amount of failed read or
3309 write requests, or as short error bursts depending on physical conditions.
3310 .sp
3311 What to do:
3312 .INDENT 0.0
3313 .IP \(bu 2
3314 check \fBsmartctl\fP for potential issues
3315 .UNINDENT
3316 .SS Solid state drives (SSD)
3317 .sp
3318 The mechanism of information storage is different from HDDs and this affects
3319 the failure mode as well. The data are stored in cells grouped in large blocks
3320 with limited number of resets and other write constraints. The firmware tries
3321 to avoid unnecessary resets and performs optimizations to maximize the storage
3322 media lifetime. The known techniques are deduplication (blocks with same
3323 fingerprint/hash are mapped to same physical block), compression or internal
3324 remapping and garbage collection of used memory cells. Due to the additional
3325 processing there are measures to verify the data e.g. by ECC codes.
3326 .sp
3327 The observations of failing SSDs show that the whole electronic fails at once
3328 or affects a lot of data (e.g. stored on one chip). Recovering such data
3329 may need specialized equipment and reading data repeatedly does not help as
3330 it\(aqs possible with HDDs.
3331 .sp
3332 There are several technologies of the memory cells with different
3333 characteristics and price. The lifetime is directly affected by the type and
3334 frequency of data written. Writing \(dqtoo much\(dq distinct data (e.g. encrypted)
3335 may render the internal deduplication ineffective and lead to a lot of rewrites
3336 and increased wear of the memory cells.
3337 .sp
3338 There are several technologies and manufacturers so it\(aqs hard to describe them
3339 but there are some that exhibit similar behaviour:
3340 .INDENT 0.0
3341 .IP \(bu 2
3342 expensive SSD will use more durable memory cells and is optimized for
3343 reliability and high load
3344 .IP \(bu 2
3345 cheap SSD is projected for a lower load (\(dqdesktop user\(dq) and is optimized for
3346 cost, it may employ the optimizations and/or extended error reporting
3347 partially or not at all
3348 .UNINDENT
3349 .sp
3350 It\(aqs not possible to reliably determine the expected lifetime of an SSD due to
3351 lack of information about how it works or due to lack of reliable stats provided
3352 by the device.
3353 .sp
3354 Metadata writes tend to be the biggest component of lifetime writes to a SSD,
3355 so there is some value in reducing them. Depending on the device class (high
3356 end/low end) the features like DUP block group profiles may affect the
3357 reliability in both ways:
3358 .INDENT 0.0
3359 .IP \(bu 2
3360 \fIhigh end\fP are typically more reliable and using \fIsingle\fP for data and
3361 metadata could be suitable to reduce device wear
3362 .IP \(bu 2
3363 \fIlow end\fP could lack ability to identify errors so an additional redundancy
3364 at the filesystem level (checksums, \fIDUP\fP) could help
3365 .UNINDENT
3366 .sp
3367 Only users who consume 50 to 100% of the SSD\(aqs actual lifetime writes need to be
3368 concerned by the write amplification of btrfs DUP metadata. Most users will be
3369 far below 50% of the actual lifetime, or will write the drive to death and
3370 discover how many writes 100% of the actual lifetime was. SSD firmware often
3371 adds its own write multipliers that can be arbitrary and unpredictable and
3372 dependent on application behavior, and these will typically have far greater
3373 effect on SSD lifespan than DUP metadata. It\(aqs more or less impossible to
3374 predict when a SSD will run out of lifetime writes to within a factor of two, so
3375 it\(aqs hard to justify wear reduction as a benefit.
3376 .sp
3377 Further reading:
3378 .INDENT 0.0
3379 .IP \(bu 2
3380 \X'tty: link https://www.snia.org/educational-library/ssd-and-deduplication-end-spinning-disk-2012'\fI\%https://www.snia.org/educational\-library/ssd\-and\-deduplication\-end\-spinning\-disk\-2012\fP\X'tty: link'
3381 .IP \(bu 2
3382 \X'tty: link https://www.snia.org/educational-library/realities-solid-state-storage-2013-2013'\fI\%https://www.snia.org/educational\-library/realities\-solid\-state\-storage\-2013\-2013\fP\X'tty: link'
3383 .IP \(bu 2
3384 \X'tty: link https://www.snia.org/educational-library/ssd-performance-primer-2013'\fI\%https://www.snia.org/educational\-library/ssd\-performance\-primer\-2013\fP\X'tty: link'
3385 .IP \(bu 2
3386 \X'tty: link https://www.snia.org/educational-library/how-controllers-maximize-ssd-life-2013'\fI\%https://www.snia.org/educational\-library/how\-controllers\-maximize\-ssd\-life\-2013\fP\X'tty: link'
3387 .UNINDENT
3388 .sp
3389 What to do:
3390 .INDENT 0.0
3391 .IP \(bu 2
3392 run \fBsmartctl\fP or self\-tests to look for potential issues
3393 .IP \(bu 2
3394 keep the firmware up\-to\-date
3395 .UNINDENT
3396 .SS NVM express, non\-volatile memory (NVMe)
3397 .sp
3398 NVMe is a type of persistent memory usually connected over a system bus (PCIe)
3399 or similar interface and the speeds are an order of magnitude faster than SSD.
3400 It is also a non\-rotating type of storage, and is not typically connected by a
3401 cable. It\(aqs not a SCSI type device either but rather a complete specification
3402 for logical device interface.
3403 .sp
3404 In a way the errors could be compared to a combination of SSD class and regular
3405 memory. Errors may exhibit as random bit flips or IO failures. There are tools
3406 to access the internal log (\fBnvme log\fP and \fBnvme\-cli\fP) for a more detailed
3407 analysis.
3408 .sp
3409 There are separate error detection and correction steps performed e.g. on the
3410 bus level and in most cases never making in to the filesystem level. Once this
3411 happens it could mean there\(aqs some systematic error like overheating or bad
3412 physical connection of the device. You may want to run self\-tests (using
3413 \fBsmartctl\fP).
3414 .INDENT 0.0
3415 .IP \(bu 2
3416 \X'tty: link https://en.wikipedia.org/wiki/NVM_Express'\fI\%https://en.wikipedia.org/wiki/NVM_Express\fP\X'tty: link'
3417 .IP \(bu 2
3418 \X'tty: link https://www.smartmontools.org/wiki/NVMe_Support'\fI\%https://www.smartmontools.org/wiki/NVMe_Support\fP\X'tty: link'
3419 .UNINDENT
3420 .SS Drive firmware
3421 .sp
3422 Firmware is technically still software but embedded into the hardware. As all
3423 software has bugs, so does firmware. Storage devices can update the firmware
3424 and fix known bugs. In some cases the it\(aqs possible to avoid certain bugs by
3425 quirks (device\-specific workarounds) in Linux kernel.
3426 .sp
3427 A faulty firmware can cause wide range of corruptions from small and localized
3428 to large affecting lots of data. Self\-repair capabilities may not be sufficient.
3429 .sp
3430 What to do:
3431 .INDENT 0.0
3432 .IP \(bu 2
3433 check for firmware updates in case there are known problems, note that
3434 updating firmware can be risky on itself
3435 .IP \(bu 2
3436 use up\-to\-date kernel (recent releases or maintained long term support versions)
3437 .UNINDENT
3438 .SS SD flash cards
3439 .sp
3440 There are a lot of devices with low power consumption and thus using storage
3441 media based on low power consumption too, typically flash memory stored on
3442 a chip enclosed in a detachable card package. An improperly inserted card may be
3443 damaged by electrical spikes when the device is turned on or off. The chips
3444 storing data in turn may be damaged permanently. All types of flash memory
3445 have a limited number of rewrites, so the data are internally translated by FTL
3446 (flash translation layer). This is implemented in firmware (technically a
3447 software) and prone to bugs that manifest as hardware errors.
3448 .sp
3449 Adding redundancy like using DUP profiles for both data and metadata can help
3450 in some cases but a full backup might be the best option once problems appear
3451 and replacing the card could be required as well.
3452 .SS Hardware as the main source of filesystem corruptions
3453 .sp
3454 \fBIf you use unreliable hardware and don\(aqt know about that, don\(aqt blame the
3455 filesystem when it tells you.\fP
3456 .SH SEE ALSO
3457 .sp
3458 \X'tty: link https://man7.org/linux/man-pages/man5/acl.5.html'\fI\%acl(5)\fP\X'tty: link',
3459 \fI\%btrfs(8)\fP,
3460 \X'tty: link https://man7.org/linux/man-pages/man1/chattr.1.html'\fI\%chattr(1)\fP\X'tty: link',
3461 \X'tty: link https://man7.org/linux/man-pages/man8/fstrim.8.html'\fI\%fstrim(8)\fP\X'tty: link',
3462 \X'tty: link https://man7.org/linux/man-pages/man2/ioctl.2.html'\fI\%ioctl(2)\fP\X'tty: link',
3463 \fI\%btrfs\-ioctl(2)\fP,
3464 \fI\%mkfs.btrfs(8)\fP,
3465 \X'tty: link https://man7.org/linux/man-pages/man8/mount.8.html'\fI\%mount(8)\fP\X'tty: link',
3466 \X'tty: link https://man7.org/linux/man-pages/man8/swapon.8.html'\fI\%swapon(8)\fP\X'tty: link'
3467 .\" Generated by docutils manpage writer.
3468 .