Debian Codegraph @

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