{
    "mode": "man",
    "parameter": "BTRFS",
    "section": "5",
    "url": "https://www.chedong.com/phpMan.php/man/BTRFS/5/json",
    "generated": "2026-09-12T03:10:09Z",
    "sections": {
        "NAME": {
            "content": "btrfs  -  topics  about  the  BTRFS  filesystem (mount options, supported file attributes and\nother)\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This document describes topics related to BTRFS that are not specific  to  the  tools.   Cur‐\nrently covers:\n\n1.  mount options\n\n2.  filesystem features\n\n3.  checksum algorithms\n\n4.  compression\n\n5.  sysfs interface\n\n6.  filesystem exclusive operations\n\n7.  filesystem limits\n\n8.  bootloader support\n\n9.  file attributes\n\n10. zoned mode\n\n11. control device\n\n12. filesystems with multiple block group profiles\n\n13. seeding device\n\n14. RAID56 status and recommended practices\n\n15. storage model, hardware considerations\n",
            "subsections": []
        },
        "MOUNT OPTIONS": {
            "content": "BTRFS SPECIFIC MOUNT OPTIONS\nThis section describes mount options specific to BTRFS.  For the generic mount options please\nrefer  to mount(8) manual page. The options are sorted alphabetically (discarding the no pre‐\nfix).\n",
            "subsections": [
                {
                    "name": "NOTE:",
                    "content": "Most mount options apply to the whole filesystem and only options  in  the  first  mounted\nsubvolume  will  take  effect. This is due to lack of implementation and may change in the\nfuture. This means that (for example) you can't set per-subvolume nodatacow, nodatasum, or\ncompress using mount options. This should eventually be fixed, but it  has  proved  to  be\ndifficult to implement correctly within the Linux VFS framework.\n\nMount  options are processed in order, only the last occurrence of an option takes effect and\nmay disable other options due to constraints (see e.g.  nodatacow and compress).  The  output\nof mount command shows which options have been applied.\n"
                },
                {
                    "name": "acl, noacl",
                    "content": "(default: on)\n\nEnable/disable  support  for POSIX Access Control Lists (ACLs).  See the acl(5) manual\npage for more information about ACLs.\n\nThe support for ACL is build-time configurable (BTRFSFSPOSIXACL) and mount fails if\nacl is requested but the feature is not compiled in.\n"
                },
                {
                    "name": "autodefrag, noautodefrag",
                    "content": "(since: 3.0, default: off)\n\nEnable automatic file defragmentation.  When enabled, small random writes  into  files\n(in a range of tens of kilobytes, currently it's 64KiB) are detected and queued up for\nthe defragmentation process.  May not be well suited for large database workloads.\n\nThe  read  latency  may  increase  due to reading the adjacent blocks that make up the\nrange for defragmentation, successive write will merge the blocks in the new location.\n\nWARNING:\nDefragmenting with Linux kernel versions < 3.9 or ≥ 3.14-rc2 as well as with  Linux\nstable  kernel versions ≥ 3.10.31, ≥ 3.12.12 or ≥ 3.13.4 will break up the reflinks\nof COW data (for example files copied with cp --reflink, snapshots or de-duplicated\ndata).  This may cause considerable increase of space usage depending on the broken\nup reflinks.\n"
                },
                {
                    "name": "barrier, nobarrier",
                    "content": "(default: on)\n\nEnsure that all IO write operations make it through the device cache  and  are  stored\npermanently when the filesystem is at its consistency checkpoint. This typically means\nthat  a flush command is sent to the device that will synchronize all pending data and\nordinary metadata blocks, then writes the superblock and issues another flush.\n\nThe write flushes incur a slight hit and also prevent the IO block  scheduler  to  re‐\norder  requests  in  a more effective way. Disabling barriers gets rid of that penalty\nbut will most certainly lead to a corrupted filesystem in case of  a  crash  or  power\nloss.  The  ordinary  metadata  blocks  could be yet unwritten at the time the new su‐\nperblock is stored permanently, expecting that the block  pointers  to  metadata  were\nstored permanently before.\n\nOn a device with a volatile battery-backed write-back cache, the nobarrier option will\nnot lead to filesystem corruption as the pending blocks are supposed to make it to the\npermanent storage.\n"
                },
                {
                    "name": "check_int, check_int_data, check_int_print_mask=<value>",
                    "content": "(since: 3.0, default: off)\n\nThese  debugging  options  control  the behavior of the integrity checking module (the\nBTRFSFSCHECKINTEGRITY config option required). The main goal is to verify that  all\nblocks from a given transaction period are properly linked.\n\ncheckint  enables  the  integrity  checker module, which examines all block write re‐\nquests to ensure on-disk consistency, at a large memory and CPU cost.\n\ncheckintdata includes extent data in the integrity checks, and implies the checkint\noption.\n\ncheckintprintmask takes a bitmask of  BTRFSICPRINTMASK*  values  as  defined  in\nfs/btrfs/check-integrity.c, to control the integrity checker module behavior.\n\nSee comments at the top of fs/btrfs/check-integrity.c for more information.\n"
                },
                {
                    "name": "clear_cache",
                    "content": "Force clearing and rebuilding of the free space cache if something has gone wrong.\n\nFor  free  space  cache  v1,  this only clears (and, unless nospacecache is used, re‐\nbuilds) the free space cache for block groups that are modified while  the  filesystem\nis  mounted  with  that  option.  To actually clear an entire free space cache v1, see\nbtrfs check --clear-space-cache v1.\n\nFor free space cache v2, this clears the entire free space cache.  To  do  so  without\nrequiring to mounting the filesystem, see btrfs check --clear-space-cache v2.\n\nSee also: spacecache.\n"
                },
                {
                    "name": "commit=<seconds>",
                    "content": "(since: 3.12, default: 30)\n\nSet  the  interval of periodic transaction commit when data are synchronized to perma‐\nnent storage. Higher interval values lead to larger amount of  unwritten  data,  which\nhas  obvious consequences when the system crashes.  The upper bound is not forced, but\na warning is printed if it's more than 300 seconds (5 minutes). Use with care.\n"
                },
                {
                    "name": "compress, compress=<type[:level]>, compress-force, compress-force=<type[:level]>",
                    "content": "(default: off, level support since: 5.1)\n\nControl BTRFS file data compression.  Type may be specified as zlib, lzo, zstd  or  no\n(for no compression, used for remounting).  If no type is specified, zlib is used.  If\ncompress-force  is  specified, then compression will always be attempted, but the data\nmay end up uncompressed if the compression would make them larger.\n\nBoth zlib and zstd (since version 5.1) expose the compression level as a tunable  knob\nwith higher levels trading speed and memory (zstd) for higher compression ratios. This\ncan  be set by appending a colon and the desired level.  ZLIB accepts the range [1, 9]\nand ZSTD accepts [1, 15]. If no level is set, both currently use a default level of 3.\nThe value 0 is an alias for the default level.\n\nOtherwise some simple heuristics are applied to detect an incompressible file.  If the\nfirst blocks written to a file are not compressible, the  whole  file  is  permanently\nmarked  to skip compression. As this is too simple, the compress-force is a workaround\nthat will compress most of the files at the cost of some wasted CPU cycles  on  failed\nattempts.   Since kernel 4.15, a set of heuristic algorithms have been improved by us‐\ning frequency sampling, repeated pattern detection and Shannon entropy calculation  to\navoid that.\n\nNOTE:\nIf compression is enabled, nodatacow and nodatasum are disabled.\n"
                },
                {
                    "name": "datacow, nodatacow",
                    "content": "(default: on)\n\nEnable  data  copy-on-write for newly created files.  Nodatacow implies nodatasum, and\ndisables compression. All files created under nodatacow are also set  the  NOCOW  file\nattribute (see chattr(1)).\n\nNOTE:\nIf nodatacow or nodatasum are enabled, compression is disabled.\n\nUpdates in-place improve performance for workloads that do frequent overwrites, at the\ncost  of potential partial writes, in case the write is interrupted (system crash, de‐\nvice failure).\n"
                },
                {
                    "name": "datasum, nodatasum",
                    "content": "(default: on)\n\nEnable data checksumming for newly created files.  Datasum implies datacow,  i.e.  the\nnormal mode of operation. All files created under nodatasum inherit the \"no checksums\"\nproperty, however there's no corresponding file attribute (see chattr(1)).\n\nNOTE:\nIf nodatacow or nodatasum are enabled, compression is disabled.\n\nThere  is  a  slight performance gain when checksums are turned off, the corresponding\nmetadata blocks holding the checksums do not need to updated.  The cost  of  checksum‐\nming  of  the blocks in memory is much lower than the IO, modern CPUs feature hardware\nsupport of the checksumming algorithm.\n"
                },
                {
                    "name": "degraded",
                    "content": "(default: off)\n\nAllow mounts with  fewer  devices  than  the  RAID  profile  constraints  require.   A\nread-write  mount  (or  remount) may fail when there are too many devices missing, for\nexample if a stripe member is completely missing from RAID0.\n\nSince 4.14, the constraint checks have been improved and are  verified  on  the  chunk\nlevel,  not at the device level. This allows degraded mounts of filesystems with mixed\nRAID profiles for data and metadata, even if the device number constraints  would  not\nbe satisfied for some of the profiles.\n\nExample: metadata -- raid1, data -- single, devices -- /dev/sda, /dev/sdb\n\nSuppose  the  data are completely stored on sda, then missing sdb will not prevent the\nmount, even if 1 missing device would normally prevent (any) single profile to  mount.\nIn  case some of the data chunks are stored on sdb, then the constraint of single/data\nis not satisfied and the filesystem cannot be mounted.\n"
                },
                {
                    "name": "device=<devicepath>",
                    "content": "Specify a path to a device that will be scanned for  BTRFS  filesystem  during  mount.\nThis  is usually done automatically by a device manager (like udev) or using the btrfs\ndevice scan command (e.g. run from the initial ramdisk). In cases where  this  is  not\npossible the device mount option can help.\n\nNOTE:\nBooting e.g. a RAID1 system may fail even if all filesystem's device paths are pro‐\nvided as the actual device nodes may not be discovered by the system at that point.\n"
                },
                {
                    "name": "discard, discard=sync, discard=async, nodiscard",
                    "content": "(default: async when devices support it since 6.2, async support since: 5.6)\n\nEnable discarding of freed file blocks.  This is useful for SSD devices, thinly provi‐\nsioned LUNs, or virtual machine images; however, every storage layer must support dis‐\ncard for it to work.\n\nIn  the  synchronous  mode (sync or without option value), lack of asynchronous queued\nTRIM on the backing device TRIM can severely degrade performance, because  a  synchro‐\nnous  TRIM  operation  will be attempted instead. Queued TRIM requires newer than SATA\nrevision 3.1 chipsets and devices.\n\nThe asynchronous mode (async) gathers extents in larger chunks before sending them  to\nthe  devices  for  TRIM. The overhead and performance impact should be negligible com‐\npared to the previous mode and it's supposed to be the preferred mode if needed.\n\nIf it is not necessary to immediately discard freed blocks, then the fstrim  tool  can\nbe  used  to  discard all free blocks in a batch. Scheduling a TRIM during a period of\nlow system activity will prevent latent interference with the performance of other op‐\nerations. Also, a device may ignore the TRIM command if the range  is  too  small,  so\nrunning a batch discard has a greater probability of actually discarding the blocks.\n"
                },
                {
                    "name": "enospc_debug, noenospc_debug",
                    "content": "(default: off)\n\nEnable verbose output for some ENOSPC conditions. It's safe to use but can be noisy if\nthe system reaches near-full state.\n"
                },
                {
                    "name": "fatal_errors=<action>",
                    "content": "(since: 3.4, default: bug)\n\nAction to take when encountering a fatal error.\n\nbug    BUG()  on  a  fatal error, the system will stay in the crashed state and may be\nstill partially usable, but reboot is required for full operation\n\npanic  panic() on a fatal error, depending on other system configuration, this may  be\nfollowed  by a reboot. Please refer to the documentation of kernel boot parame‐\nters, e.g. panic, oops or crashkernel.\n"
                },
                {
                    "name": "flushoncommit, noflushoncommit",
                    "content": "(default: off)\n\nThis option forces any data dirtied by a write in a prior  transaction  to  commit  as\npart of the current commit, effectively a full filesystem sync.\n\nThis makes the committed state a fully consistent view of the file system from the ap‐\nplication's  perspective (i.e. it includes all completed file system operations). This\nwas previously the behavior only when a snapshot was created.\n\nWhen off, the filesystem is consistent but buffered writes  may  last  more  than  one\ntransaction commit.\n"
                },
                {
                    "name": "fragment=<type>",
                    "content": "(depends on compile-time option CONFIGBTRFSDEBUG, since: 4.4, default: off)\n\nA  debugging helper to intentionally fragment given type of block groups. The type can\nbe data, metadata or all. This mount option should not be used  outside  of  debugging\nenvironments  and  is not recognized if the kernel config option CONFIGBTRFSDEBUG is\nnot enabled.\n"
                },
                {
                    "name": "nologreplay",
                    "content": "(default: off, even read-only)\n\nThe tree-log contains pending updates to the filesystem until the  full  commit.   The\nlog is replayed on next mount, this can be disabled by this option.  See also treelog.\nNote that nologreplay is the same as norecovery.\n\nWARNING:\nCurrently,  the  tree  log is replayed even with a read-only mount! To disable that\nbehaviour, mount also with nologreplay.\n"
                },
                {
                    "name": "max_inline=<bytes>",
                    "content": "(default: min(2048, page size) )\n\nSpecify the maximum amount of space, that can be inlined in a  metadata  b-tree  leaf.\nThe  value  is  specified in bytes, optionally with a K suffix (case insensitive).  In\npractice, this value is limited by the filesystem block size (named sectorsize at mkfs\ntime), and memory page size of the system. In case of sectorsize limit,  there's  some\nspace unavailable due to b-tree leaf headers.  For example, a 4KiB sectorsize, maximum\nsize of inline data is about 3900 bytes.\n\nInlining  can  be completely turned off by specifying 0. This will increase data block\nslack if file sizes are much smaller than block size but will reduce metadata consump‐\ntion in return.\n\nNOTE:\nThe default value has changed to 2048 in kernel 4.6.\n"
                },
                {
                    "name": "metadata_ratio=<value>",
                    "content": "(default: 0, internal logic)\n\nSpecifies that 1 metadata chunk should be allocated after every value data chunks. De‐\nfault behaviour depends on internal logic, some percent of unused  metadata  space  is\nattempted to be maintained but is not always possible if there's not enough space left\nfor chunk allocation. The option could be useful to override the internal logic in fa‐\nvor of the metadata allocation if the expected workload is supposed to be metadata in‐\ntense (snapshots, reflinks, xattrs, inlined files).\n"
                },
                {
                    "name": "norecovery",
                    "content": "(since: 4.5, default: off)\n\nDo not attempt any data recovery at mount time. This will disable logreplay and avoids\nother write operations. Note that this option is the same as nologreplay.\n\nNOTE:\nThe  opposite  option  recovery  used to have different meaning but was changed for\nconsistency with other filesystems, where norecovery is used for skipping  log  re‐\nplay. BTRFS does the same and in general will try to avoid any write operations.\n"
                },
                {
                    "name": "rescan_uuid_tree",
                    "content": "(since: 3.12, default: off)\n\nForce  check  and  rebuild  procedure  of  the  UUID tree. This should not normally be\nneeded.\n\nrescue (since: 5.9)\n\nModes allowing mount with damaged filesystem structures.\n\n• usebackuproot (since: 5.9, replaces standalone option usebackuproot)\n\n• nologreplay (since: 5.9, replaces standalone option nologreplay)\n\n• ignorebadroots, ibadroots (since: 5.11)\n\n• ignoredatacsums, idatacsums (since: 5.11)\n\n• all (since: 5.9)\n"
                },
                {
                    "name": "skip_balance",
                    "content": "(since: 3.3, default: off)\n\nSkip automatic resume of an interrupted balance operation. The operation can later  be\nresumed  with btrfs balance resume, or the paused state can be removed with btrfs bal‐\nance cancel. The default behaviour is to resume an interrupted balance immediately af‐\nter a volume is mounted.\n"
                },
                {
                    "name": "space_cache, space_cache=<version>, nospace_cache",
                    "content": "(nospacecache since: 3.2,  spacecache=v1  and  spacecache=v2  since  4.5,  default:\nspacecache=v2)\n\nOptions to control the free space cache. The free space cache greatly improves perfor‐\nmance  when  reading  block  group free space into memory. However, managing the space\ncache consumes some resources, including a small amount of disk space.\n\nThere are two implementations of the free space cache. The original one,  referred  to\nas  v1,  used  to be a safe default but has been superseded by v2.  The v1 space cache\ncan be disabled at mount time with nospacecache without clearing.\n\nOn very large filesystems (many terabytes) and certain workloads, the  performance  of\nthe  v1  space  cache may degrade drastically. The v2 implementation, which adds a new\nb-tree called the free space tree, addresses this issue. Once enabled,  the  v2  space\ncache  will  always  be  used  and  cannot  be  disabled  unless  it  is  cleared. Use\nclearcache,spacecache=v1 or clearcache,nospacecache to do so. If  v2  is  enabled,\nand v1 space cache will be cleared (at the first mount) and kernels without v2 support\nwill only be able to mount the filesystem in read-only mode.  On an unmounted filesys‐\ntem the caches (both versions) can be cleared by \"btrfs check --clear-space-cache\".\n\nThe btrfs-check(8) and :doc:`mkfs.btrfs commands have full v2 free space cache support\nsince v4.19.\n\nIf  a  version is not explicitly specified, the default implementation will be chosen,\nwhich is v2.\n"
                },
                {
                    "name": "ssd, ssd_spread, nossd, nossd_spread",
                    "content": "(default: SSD autodetected)\n\nOptions to control SSD allocation schemes.  By default, BTRFS will enable  or  disable\nSSD  optimizations  depending  on  status  of  a  device with respect to rotational or\nnon-rotational type. This is determined by the contents of  /sys/block/DEV/queue/rota‐\ntional).  If  it is 0, the ssd option is turned on.  The option nossd will disable the\nautodetection.\n\nThe optimizations make use of the absence of the seek penalty that's inherent for  the\nrotational  devices.  The blocks can be typically written faster and are not offloaded\nto separate threads.\n\nNOTE:\nSince 4.14, the block layout optimizations have been dropped.  This  used  to  help\nwith  first generations of SSD devices. Their FTL (flash translation layer) was not\neffective and the optimization was supposed to improve the wear by better  aligning\nblocks.  This is no longer true with modern SSD devices and the optimization had no\nreal benefit. Furthermore it caused increased fragmentation. The layout tuning  has\nbeen kept intact for the option ssdspread.\n\nThe ssdspread mount option attempts to allocate into bigger and aligned chunks of un‐\nused  space, and may perform better on low-end SSDs.  ssdspread implies ssd, enabling\nall other SSD heuristics as well. The option nossd will disable all SSD options  while\nnossdspread only disables ssdspread.\n"
                },
                {
                    "name": "subvol=<path>",
                    "content": "Mount  subvolume  from  path  rather  than  the toplevel subvolume. The path is always\ntreated as relative to the toplevel subvolume.  This mount option  overrides  the  de‐\nfault subvolume set for the given filesystem.\n"
                },
                {
                    "name": "subvolid=<subvolid>",
                    "content": "Mount  subvolume  specified  by  a subvolid number rather than the toplevel subvolume.\nYou can use btrfs subvolume list of btrfs subvolume show to see subvolume ID  numbers.\nThis mount option overrides the default subvolume set for the given filesystem.\n\nNOTE:\nIf  both  subvolid and subvol are specified, they must point at the same subvolume,\notherwise the mount will fail.\n"
                },
                {
                    "name": "thread_pool=<number>",
                    "content": "(default: min(NRCPUS + 2, 8) )\n\nThe number of worker threads to start. NRCPUS is number of on-line  CPUs  detected  at\nthe time of mount. Small number leads to less parallelism in processing data and meta‐\ndata,  higher  numbers  could  lead to a performance hit due to increased locking con‐\ntention, process scheduling, cache-line bouncing or costly data transfers between  lo‐\ncal CPU memories.\n"
                },
                {
                    "name": "treelog, notreelog",
                    "content": "(default: on)\n\nEnable  the tree logging used for fsync and OSYNC writes. The tree log stores changes\nwithout the need of a full filesystem sync. The log operations are flushed at sync and\ntransaction commit. If the system crashes between two such syncs, the pending tree log\noperations are replayed during mount.\n\nWARNING:\nCurrently, the tree log is replayed even with a read-only mount!  To  disable  that\nbehaviour, also mount with nologreplay.\n\nThe  tree  log could contain new files/directories, these would not exist on a mounted\nfilesystem if the log is not replayed.\n"
                },
                {
                    "name": "usebackuproot",
                    "content": "(since: 4.6, default: off)\n\nEnable autorecovery attempts if a bad tree root is found  at  mount  time.   Currently\nthis  scans  a  backup  list of several previous tree roots and tries to use the first\nreadable. This can be used with read-only mounts as well.\n\nNOTE:\nThis option has replaced recovery.\n"
                },
                {
                    "name": "user_subvol_rm_allowed",
                    "content": "(default: off)\n\nAllow subvolumes to be deleted by their respective owner.  Otherwise,  only  the  root\nuser can do that.\n\nNOTE:\nHistorically,  any  user  could  create  a snapshot even if he was not owner of the\nsource subvolume, the subvolume deletion has been restricted for that  reason.  The\nsubvolume  creation  has  been  restricted but this mount option is still required.\nThis is a usability issue.  Since 4.18, the rmdir(2) syscall can  delete  an  empty\nsubvolume just like an ordinary directory. Whether this is possible can be detected\nat runtime, see rmdirsubvol feature in FILESYSTEM FEATURES.\n\nDEPRECATED MOUNT OPTIONS\nList of mount options that have been removed, kept for backward compatibility.\n"
                },
                {
                    "name": "recovery",
                    "content": "(since: 3.2, default: off, deprecated since: 4.5)\n\nNOTE:\nThis option has been replaced by usebackuproot and should not be used but will work\non 4.5+ kernels.\n"
                },
                {
                    "name": "inode_cache, noinode_cache",
                    "content": "(removed in: 5.11, since: 3.0, default: off)\n\nNOTE:\nThe  functionality has been removed in 5.11, any stale data created by previous use\nof the inodecache option can be removed by btrfs rescue clear-ino-cache.\n\nNOTES ON GENERIC MOUNT OPTIONS\nSome of the general mount options from mount(8) that affect BTRFS and are worth mentioning.\n"
                },
                {
                    "name": "noatime",
                    "content": "under read intensive work-loads, specifying noatime significantly improves performance\nbecause no new access time information needs to be written. Without this  option,  the\ndefault  is relatime, which only reduces the number of inode atime updates in compari‐\nson to the traditional strictatime. The worst case for atime  updates  under  relatime\noccurs  when  many files are read whose atime is older than 24 h and which are freshly\nsnapshotted. In that case the atime is updated and COW happens - for each  file  -  in\nbulk.  See also https://lwn.net/Articles/499293/ - Atime and btrfs: a bad combination?\n(LWN, 2012-05-31).\n\nNote that noatime may break applications that rely on atime uptimes like the venerable\nMutt (unless you use maildir mailboxes).\n"
                }
            ]
        },
        "FILESYSTEM FEATURES": {
            "content": "The basic set of filesystem features gets extended over time. The backward  compatibility  is\nmaintained  and  the features are optional, need to be explicitly asked for so accidental use\nwill not create incompatibilities.\n\nThere are several classes and the respective tools to manage the features:\n",
            "subsections": [
                {
                    "name": "at mkfs time only",
                    "content": "This is namely for core structures, like the b-tree nodesize  or  checksum  algorithm,\nsee mkfs.btrfs(8) for more details.\n"
                },
                {
                    "name": "after mkfs, on an unmounted filesystem",
                    "content": "Features  that  may  optimize internal structures or add new structures to support new\nfunctionality,  see  btrfstune(8).  The  command  btrfs  inspect-internal   dump-super\n/dev/sdx  will  dump a superblock, you can map the value of incompatflags to the fea‐\ntures listed below\n"
                },
                {
                    "name": "after mkfs, on a mounted filesystem",
                    "content": "The features of a filesystem (with a given UUID) are listed in /sys/fs/btrfs/UUID/fea‐\ntures/, one file per feature. The status is stored inside the file. The value 1 is for\nenabled and active, while 0 means the feature was enabled at mount time but turned off\nafterwards.\n\nWhether a particular feature can be turned on a mounted filesystem can be found in the\ndirectory /sys/fs/btrfs/features/, one file per feature. The value 1 means the feature\ncan be enabled.\n\nList of features (see also mkfs.btrfs(8) section FILESYSTEM FEATURES):\n"
                },
                {
                    "name": "big_metadata",
                    "content": "(since: 3.4)\n\nthe filesystem uses nodesize for metadata blocks, this can be  bigger  than  the  page\nsize\n"
                },
                {
                    "name": "block_group_tree",
                    "content": "(since: 6.1)\n\nblock  group  item  representation  using  a dedicated b-tree, this can greatly reduce\nmount time for large filesystems\n"
                },
                {
                    "name": "compress_lzo",
                    "content": "(since: 2.6.38)\n\nthe lzo compression has been used on the filesystem, either as a mount option  or  via\nbtrfs filesystem defrag.\n"
                },
                {
                    "name": "compress_zstd",
                    "content": "(since: 4.14)\n\nthe  zstd compression has been used on the filesystem, either as a mount option or via\nbtrfs filesystem defrag.\n"
                },
                {
                    "name": "default_subvol",
                    "content": "(since: 2.6.34)\n\nthe default subvolume has been set on the filesystem\n"
                },
                {
                    "name": "extended_iref",
                    "content": "(since: 3.7)\n\nincreased hardlink limit per file in a directory to 65536, older kernels  supported  a\nvarying  number  of  hardlinks depending on the sum of all file name sizes that can be\nstored into one metadata block\n"
                },
                {
                    "name": "free_space_tree",
                    "content": "(since: 4.5)\n\nfree space representation using a dedicated b-tree, successor of v1 space cache\n"
                },
                {
                    "name": "metadata_uuid",
                    "content": "(since: 5.0)\n\nthe main filesystem UUID is the metadatauuid, which stores the new UUID only  in  the\nsuperblock  while  all  metadata  blocks  still  have  the  UUID set at mkfs time, see\nbtrfstune(8) for more\n"
                },
                {
                    "name": "mixed_backref",
                    "content": "(since: 2.6.31)\n\nthe last major disk format change, improved backreferences, now default\n"
                },
                {
                    "name": "mixed_groups",
                    "content": "(since: 2.6.37)\n\nmixed data and metadata block groups, i.e. the data and metadata are not separated and\noccupy the same block groups, this mode is suitable for small volumes as there are  no\nconstraints  how the remaining space should be used (compared to the split mode, where\nempty metadata space cannot be used for data and vice versa)\n\non the other hand, the final layout is quite unpredictable and possibly  highly  frag‐\nmented, which means worse performance\n"
                },
                {
                    "name": "no_holes",
                    "content": "(since: 3.14)\n\nimproved  representation  of  file extents where holes are not explicitly stored as an\nextent, saves a few percent of metadata if sparse files are used\n"
                },
                {
                    "name": "raid1c34",
                    "content": "(since: 5.5)\n\nextended RAID1 mode with copies on 3 or 4 devices respectively\n\nRAID56 (since: 3.9)\n\nthe filesystem contains or contained a RAID56 profile of block groups\n"
                },
                {
                    "name": "rmdir_subvol",
                    "content": "(since: 4.18)\n\nindicate that rmdir(2) syscall can delete an empty subvolume just like an ordinary di‐\nrectory. Note that this feature only depends on the kernel version.\n"
                },
                {
                    "name": "skinny_metadata",
                    "content": "(since: 3.10)\n\nreduced-size metadata for extent references, saves a few percent of metadata\n"
                },
                {
                    "name": "send_stream_version",
                    "content": "(since: 5.10)\n\nnumber of the highest supported send stream version\n"
                },
                {
                    "name": "supported_checksums",
                    "content": "(since: 5.5)\n\nlist of checksum algorithms supported by the kernel module, the respective modules  or\nbuilt-in  implementing  the algorithms need to be present to mount the filesystem, see\nsection CHECKSUM ALGORITHMS.\n"
                },
                {
                    "name": "supported_sectorsizes",
                    "content": "(since: 5.13)\n\nlist of values that are accepted as sector sizes (mkfs.btrfs --sectorsize) by the run‐\nning kernel\n"
                },
                {
                    "name": "supported_rescue_options",
                    "content": "(since: 5.11)\n\nlist of values for the mount option rescue that are supported by the  running  kernel,\nsee btrfs(5)\n\nzoned  (since: 5.12)\n\nzoned  mode  is  allocation/write  friendly  to host-managed zoned devices, allocation\nspace is partitioned into fixed-size zones that must be updated sequentially, see sec‐\ntion ZONED MODE\n"
                }
            ]
        },
        "SWAPFILE SUPPORT": {
            "content": "A swapfile, when active, is a file-backed swap area.  It is supported since kernel 5.0.   Use\nswapon(8)  to  activate  it,  until  then  (respectively  again  after  deactivating  it with\nswapoff(8)) it's just a normal file (with NODATACOW set), for which the special  restrictions\nfor active swapfiles don't apply.\n\nThere are some limitations of the implementation in BTRFS and Linux swap subsystem:\n\n• filesystem - must be only single device\n\n• filesystem - must have only single data profile\n\n• subvolume - cannot be snapshotted if it contains any active swapfiles\n\n• swapfile - must be preallocated (i.e. no holes)\n\n• swapfile - must be NODATACOW (i.e. also NODATASUM, no compression)\n\nThe limitations come namely from the COW-based design and mapping layer of blocks that allows\nthe advanced features like relocation and multi-device filesystems. However, the swap subsys‐\ntem expects simpler mapping and no background changes of the file block location once they've\nbeen assigned to swap.\n\nWith  active  swapfiles, the following whole-filesystem operations will skip swapfile extents\nor may fail:\n\n• balance - block groups with extents of any active swapfiles are skipped and  reported,  the\nrest will be processed normally\n\n• resize grow - unaffected\n\n• resize  shrink  -  works  as long as the extents of any active swapfiles are outside of the\nshrunk range\n\n• device add - if the new devices do not interfere with any already active swapfiles this op‐\neration will work, though no new swapfile can be activated afterwards\n\n• device delete - if the device has been added as above, it can be also deleted\n\n• device replace - ditto\n\nWhen there are no active swapfiles and a  whole-filesystem  exclusive  operation  is  running\n(e.g. balance, device delete, shrink), the swapfiles cannot be temporarily activated. The op‐\neration must finish first.\n\nTo create and activate a swapfile run the following commands:\n\n# truncate -s 0 swapfile\n# chattr +C swapfile\n# fallocate -l 2G swapfile\n# chmod 0600 swapfile\n# mkswap swapfile\n# swapon swapfile\n\nSince  version 6.1 it's possible to create the swapfile in a single command (except the acti‐\nvation):\n\n# btrfs filesystem mkswapfile --size 2G swapfile\n# swapon swapfile\n\nPlease note that the UUID returned by the mkswap utility identifies the swap \"filesystem\" and\nbecause it's stored in a file, it's not generally visible and usable as an identifier  unlike\nif it was on a block device.\n\nOnce activated the file will appear in /proc/swaps:\n\n# cat /proc/swaps\nFilename          Type          Size           Used      Priority\n/path/swapfile    file          2097152        0         -2\n\nThe  swapfile  can  be  created as one-time operation or, once properly created, activated on\neach boot by the swapon -a command (usually started by the service manager). Add the  follow‐\ning  entry  to  /etc/fstab,  assuming the filesystem that provides the /path has been already\nmounted at this point.  Additional mount options relevant for the swapfile  can  be  set  too\n(like priority, not the BTRFS mount options).\n\n/path/swapfile        none        swap        defaults      0 0\n\nFrom  now  on the subvolume with the active swapfile cannot be snapshotted until the swapfile\nis deactivated again by swapoff. Then the swapfile is a regular file and the subvolume can be\nsnapshotted again, though this would prevent another activation any swapfile  that  has  been\nsnapshotted. New swapfiles (not snapshotted) can be created and activated.\n\nOtherwise,  an inactive swapfile does not affect the containing subvolume. Activation creates\na temporary in-memory status and prevents some file operations,  but  is  not  stored  perma‐\nnently.\n",
            "subsections": []
        },
        "HIBERNATION": {
            "content": "A swapfile can be used for hibernation but it's not straightforward. Before hibernation a re‐\nsume offset must be written to file /sys/power/resumeoffset or the kernel command line para‐\nmeter resumeoffset must be set.\n\nThe  value  is  the  physical offset on the device. Note that this is not the same value that",
            "subsections": [
                {
                    "name": "filefrag prints as physical offset!",
                    "content": "Btrfs filesystem uses mapping between logical and physical addresses but  here  the  physical\ncan  still  map to one or more device-specific physical block addresses. It's the device-spe‐\ncific physical offset that is suitable as resume offset.\n\nSince version 6.1 there's a command btrfs inspect-internal map-swapfile that will  print  the\ndevice  physical  offset  and the adjusted value for /sys/power/resumeoffset.  Note that the\nvalue is divided by page size, i.e.  it's not the offset itself.\n\n# btrfs filesystem mkswapfile swapfile\n# btrfs inspect-internal map-swapfile swapfile\nPhysical start: 811511726080\nResume offset:     198122980\n\nFor scripting and convenience the option -r will print just the offset:\n\n# btrfs inspect-internal map-swapfile -r swapfile\n198122980\n\nThe command map-swapfile also verifies all the requirements, i.e. no  holes,  single  device,\netc.\n"
                }
            ]
        },
        "TROUBLESHOOTING": {
            "content": "If the swapfile activation fails please verify that you followed all the steps above or check\nthe system log (e.g. dmesg or journalctl) for more information.\n\nNotably, the swapon utility exits with a message that does not say what failed:\n\n# swapon /path/swapfile\nswapon: /path/swapfile: swapon failed: Invalid argument\n\nThe specific reason is likely to be printed to the system log by the btrfs module:\n\n# journalctl -t kernel | grep swapfile\nkernel: BTRFS warning (device sda): swapfile must have single data profile\n",
            "subsections": []
        },
        "CHECKSUM ALGORITHMS": {
            "content": "Data  and  metadata  are  checksummed by default, the checksum is calculated before write and\nverified after reading the blocks from devices. The  whole  metadata  block  has  a  checksum\nstored  inline  in  the b-tree node header, each data block has a detached checksum stored in\nthe checksum tree.\n\nThere are several checksum algorithms supported.  The  default  and  backward  compatible  is\ncrc32c.   Since kernel 5.5 there are three more with different characteristics and trade-offs\nregarding speed and strength. The following list may help you to decide which one to select.\n",
            "subsections": [
                {
                    "name": "CRC32C (32bit digest)",
                    "content": "default, best backward compatibility, very fast, modern  CPUs  have  instruction-level\nsupport, not collision-resistant but still good error detection capabilities\n"
                },
                {
                    "name": "XXHASH (64bit digest)",
                    "content": "can  be  used  as CRC32C successor, very fast, optimized for modern CPUs utilizing in‐\nstruction pipelining, good collision resistance and error detection\n"
                },
                {
                    "name": "SHA256 (256bit digest)",
                    "content": "a cryptographic-strength hash, relatively slow but with possible CPU  instruction  ac‐\nceleration or specialized hardware cards, FIPS certified and in wide use\n"
                },
                {
                    "name": "BLAKE2b (256bit digest)",
                    "content": "a  cryptographic-strength  hash,  relatively fast with possible CPU acceleration using\nSIMD extensions, not standardized but based on BLAKE which was  a  SHA3  finalist,  in\nwide use, the algorithm used is BLAKE2b-256 that's optimized for 64bit platforms\n\nThe  digest  size affects overall size of data block checksums stored in the filesystem.  The\nmetadata blocks have a fixed area up to 256 bits (32 bytes), so  there's  no  increase.  Each\ndata block has a separate checksum stored, with additional overhead of the b-tree leaves.\n\nApproximate  relative  performance of the algorithms, measured against CRC32C using reference\nsoftware implementations on a 3.5GHz intel CPU:\n┌─────────┬─────────────┬───────┬─────────────────┐\n│ Digest  │ Cycles/4KiB │ Ratio │ Implementation  │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ CRC32C  │ 1700        │ 1.00  │ CPU instruction │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ XXHASH  │ 2500        │ 1.44  │ reference impl. │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ SHA256  │ 105000      │ 61    │ reference impl. │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ SHA256  │ 36000       │ 21    │ libgcrypt/AVX2  │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ SHA256  │ 63000       │ 37    │ libsodium/AVX2  │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ BLAKE2b │ 22000       │ 13    │ reference impl. │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ BLAKE2b │ 19000       │ 11    │ libgcrypt/AVX2  │\n├─────────┼─────────────┼───────┼─────────────────┤\n│ BLAKE2b │ 19000       │ 11    │ libsodium/AVX2  │\n└─────────┴─────────────┴───────┴─────────────────┘\n\nMany kernels are configured with SHA256 as built-in and not as  a  module.   The  accelerated\nversions  are however provided by the modules and must be loaded explicitly (modprobe sha256)\nbefore   mounting   the   filesystem   to   make   use   of   them.   You   can   check    in\n/sys/fs/btrfs/FSID/checksum  which  one is used. If you see sha256-generic, then you may want\nto unmount and mount the filesystem again, changing that on a mounted filesystem is not  pos‐\nsible.  Check the file /proc/crypto, when the implementation is built-in, you'd find\n\nname         : sha256\ndriver       : sha256-generic\nmodule       : kernel\npriority     : 100\n...\n\nwhile accelerated implementation is e.g.\n\nname         : sha256\ndriver       : sha256-avx2\nmodule       : sha256ssse3\npriority     : 170\n...\n"
                }
            ]
        },
        "COMPRESSION": {
            "content": "Btrfs  supports transparent file compression. There are three algorithms available: ZLIB, LZO\nand ZSTD (since v4.14), with various levels.  The compression happens on the  level  of  file\nextents  and the algorithm is selected by file property, mount option or by a defrag command.\nYou can have a single btrfs mount point that has some files that are uncompressed, some  that\nare  compressed  with LZO, some with ZLIB, for instance (though you may not want it that way,\nit is supported).\n\nOnce the compression is set, all newly written data will be compressed, i.e.   existing  data\nare  untouched. Data are split into smaller chunks (128KiB) before compression to make random\nrewrites possible without a high performance hit. Due to the increased number of extents  the\nmetadata consumption is higher. The chunks are compressed in parallel.\n\nThe algorithms can be characterized as follows regarding the speed/ratio trade-offs:\n\nZLIB\n\n• slower, higher compression ratio\n\n• levels: 1 to 9, mapped directly, default level is 3\n\n• good backward compatibility\n\nLZO\n\n• faster compression and decompression than ZLIB, worse compression ratio, designed to\nbe fast\n\n• no levels\n\n• good backward compatibility\n\nZSTD\n\n• compression comparable to ZLIB with higher compression/decompression speeds and dif‐\nferent ratio\n\n• levels: 1 to 15, mapped directly (higher levels are not available)\n\n• since 4.14, levels since 5.1\n\nThe  differences  depend on the actual data set and cannot be expressed by a single number or\nrecommendation. Higher levels consume more CPU time and may not bring a significant  improve‐\nment, lower levels are close to real time.\n",
            "subsections": []
        },
        "HOW TO ENABLE COMPRESSION": {
            "content": "Typically  the  compression  can  be enabled on the whole filesystem, specified for the mount\npoint. Note that the compression mount options are  shared  among  all  mounts  of  the  same\nfilesystem,  either  bind mounts or subvolume mounts.  Please refer to btrfs(5) section MOUNT\nOPTIONS.\n\n$ mount -o compress=zstd /dev/sdx /mnt\n\nThis will enable the zstd algorithm on the default level (which is  3).   The  level  can  be\nspecified  manually  too like zstd:3. Higher levels compress better at the cost of time. This\nin turn may cause increased write latency, low levels are suitable for real-time  compression\nand on reasonably fast CPU don't cause noticeable performance drops.\n\n$ btrfs filesystem defrag -czstd file\n\nThe command above will start defragmentation of the whole file and apply the compression, re‐\ngardless  of  the mount option. (Note: specifying level is not yet implemented). The compres‐\nsion algorithm is not persistent and applies only to the  defragmentation  command,  for  any\nother writes other compression settings apply.\n\nPersistent settings on a per-file basis can be set in two ways:\n\n$ chattr +c file\n$ btrfs property set file compression zstd\n\nThe first command is using legacy interface of file attributes inherited from ext2 filesystem\nand  is  not  flexible,  so  by default the zlib compression is set. The other command sets a\nproperty on the file with the given algorithm.  (Note: setting level that way is not yet  im‐\nplemented.)\n",
            "subsections": []
        },
        "COMPRESSION LEVELS": {
            "content": "The  level  support  of ZLIB has been added in v4.14, LZO does not support levels (the kernel\nimplementation provides only one), ZSTD level support has been added in v5.1.\n\nThere are 9 levels of ZLIB supported (1 to 9), mapping 1:1 from the mount option to the algo‐\nrithm defined level. The default is level 3, which provides the reasonably  good  compression\nratio  and  is still reasonably fast. The difference in compression gain of levels 7, 8 and 9\nis comparable but the higher levels take longer.\n\nThe ZSTD support includes levels 1 to 15, a subset of full range of what ZSTD provides.  Lev‐\nels  1-3  are real-time, 4-8 slower with improved compression and 9-15 try even harder though\nthe resulting size may not be significantly improved.\n\nLevel 0 always maps to the default. The compression level does not affect compatibility.\n",
            "subsections": []
        },
        "INCOMPRESSIBLE DATA": {
            "content": "Files with already compressed data or with data that won't compress well  with  the  CPU  and\nmemory  constraints  of  the kernel implementations are using a simple decision logic. If the\nfirst portion of data being compressed is not smaller than the original, the  compression  of\nthe  file  is  disabled -- unless the filesystem is mounted with compress-force. In that case\ncompression will always be attempted on the file only to be later discarded. This is not  op‐\ntimal and subject to optimizations and further development.\n\nIf  a  file  is  identified as incompressible, a flag is set (NOCOMPRESS) and it's sticky. On\nthat file compression won't be performed unless forced. The flag can be also set by chattr +m\n(since e2fsprogs 1.46.2) or by properties with value no or none. Empty value will reset it to\nthe default that's currently applicable on the mounted filesystem.\n\nThere are two ways to detect incompressible data:\n\n• actual compression attempt - data are compressed, if the result is not smaller,  it's  dis‐\ncarded, so this depends on the algorithm and level\n\n• pre-compression  heuristics  -  a quick statistical evaluation on the data is performed and\nbased on the result either compression is performed or skipped, the NOCOMPRESS bit  is  not\nset just by the heuristic, only if the compression algorithm does not make an improvement\n\n$ lsattr file\n---------------------m file\n\nUsing  the forcing compression is not recommended, the heuristics are supposed to decide that\nand compression algorithms internally detect incompressible data too.\n",
            "subsections": []
        },
        "PRE-COMPRESSION HEURISTICS": {
            "content": "The heuristics aim to do a few quick statistical tests on the compressed  data  in  order  to\navoid  probably  costly  compression that would turn out to be inefficient. Compression algo‐\nrithms could have internal detection of incompressible data too but this leads to more  over‐\nhead  as  the  compression  is  done  in another thread and has to write the data anyway. The\nheuristic is read-only and can utilize cached memory.\n\nThe tests performed based on the following: data sampling, long repeated  pattern  detection,\nbyte frequency, Shannon entropy.\n",
            "subsections": []
        },
        "COMPATIBILITY": {
            "content": "Compression  is  done  using the COW mechanism so it's incompatible with nodatacow. Direct IO\nworks on compressed files but will fall back to buffered writes and leads  to  recompression.\nCurrently nodatasum and compression don't work together.\n\nThe  compression  algorithms have been added over time so the version compatibility should be\nalso considered, together with other tools that may access the compressed data like bootload‐\ners.\n",
            "subsections": []
        },
        "SYSFS INTERFACE": {
            "content": "Btrfs has a sysfs interface to provide extra knobs.\n\nThe top level path is /sys/fs/btrfs/, and the main directory layout is the following:\n──────────────────────────────────────────────────────────────────────\nRelative Path                  Description                 Version\n──────────────────────────────────────────────────────────────────────\nfeatures/                      All supported features      3.14+\n──────────────────────────────────────────────────────────────────────\n<UUID>/                        Mounted fs UUID             3.14+\n──────────────────────────────────────────────────────────────────────\n<UUID>/allocation/             Space allocation info       3.14+\n──────────────────────────────────────────────────────────────────────\n<UUID>/features/               Features of the  filesys‐   3.14+\ntem\n──────────────────────────────────────────────────────────────────────\n<UUID>/devices/<DEVID>/        Symlink to each block de‐   5.6+\nvice sysfs\n──────────────────────────────────────────────────────────────────────\n<UUID>/devinfo/<DEVID>/        Btrfs  specific  info for   5.6+\neach device\n──────────────────────────────────────────────────────────────────────\n<UUID>/qgroups/                Global qgroup info          5.9+\n──────────────────────────────────────────────────────────────────────\n<UUID>/qgroups/<LEVEL><ID>/   Info for each qgroup        5.9+\n──────────────────────────────────────────────────────────────────────\n<UUID>/discard/                Discard  stats  and  tun‐   6.1+\nables\n┌──────────────────────────────┬───────────────────────────┬─────────┐\n│                              │                           │         │\nFor  /sys/f│s/btrfs/features/  directory,  │each file means a supported │feature fo│r the current\nkernel.    │                              │                           │         │\n│                              │                           │         │\nFor /sys/fs│/btrfs/<UUID>/features/ directo│ry, each file means  an  ena│bled  feat│ure  for  the\nmounted fil│esystem.                       │                           │         │\n│                              │                           │         │\nThe feature│s shares the same name in secti│on FILESYSTEM FEATURES.     │         │\n│                              │                           │         │\nFiles in /s│ys/fs/btrfs/<UUID>/ directory a│re:                         │         │\n│                              │                           │         │\nbgreclaim│threshold                      │                           │         │\n(RW,│since: 5.19)                  │                           │         │\n│                              │                           │         │\nUsed│ space  percentage of total de│vice space to start auto blo│ck group c│laim.  Mostly\nfor │zoned devices.                 │                           │         │\n│                              │                           │         │\nchecksum   │                              │                           │         │\n(RO,│since: 5.5)                   │                           │         │\n│                              │                           │         │\nThe │checksum used for the mounted f│ilesystem.  This includes bo│th  the  c│hecksum  type\n(see│ section  CHECKSUM  ALGORITHMS│)  and the implemented drive│r (mostly │shows if it's\nhard│ware accelerated).             │                           │         │\n│                              │                           │         │\nclonealign│ment                           │                           │         │\n(RO,│since: 3.16)                  │                           │         │\n│                              │                           │         │\nThe │bytes alignment for clone and d│edupe ioctls.               │         │\n│                              │                           │         │\ncommitstat│s                              │                           │         │\n(RW,│since: 6.0)                   │                           │         │\n│                              │                           │         │\nThe │performance statistics for btrf│s transaction commit.  Mostl│y for debu│g purposes.\n│                              │                           │         │\nWrit│ing into this file will reset t│he maximum commit duration t│o the inpu│t value.\n│                              │                           │         │\nexclusiveo│peration                       │                           │         │\n(RO,│since: 5.10)                  │                           │         │\n│                              │                           │         │\nShow│s the running exclusive operati│on.  Check section FILESYSTE│M EXCLUSIV│E  OPERATIONS\nfor │details.                       │                           │         │\n│                              │                           │         │\ngeneration │                              │                           │         │\n(RO,│since: 5.11)                  │                           │         │\n│                              │                           │         │\nShow│the generation of the mounted │filesystem.                 │         │\n│                              │                           │         │\nlabel  (RW,│since: 3.14)                  │                           │         │\n│                              │                           │         │\nShow│the current label of the mount│ed filesystem.              │         │\n│                              │                           │         │\nmetadatauu│id                             │                           │         │\n(RO,│since: 5.0)                   │                           │         │\n│                              │                           │         │\nShow│s  the  metadata  uuid of the m│ounted filesystem.  Check me│tadatauui│d feature for\nmore│details.                      │                           │         │\n│                              │                           │         │\nnodesize   │                              │                           │         │\n(RO, since: 3.14)\n\nShow the nodesize of the mounted filesystem.\n",
            "subsections": [
                {
                    "name": "quota_override",
                    "content": "(RW, since: 4.13)\n\nShows the current quota override status.  0 means no quota override.   1  means  quota\noverride, quota can ignore the existing limit settings.\n"
                },
                {
                    "name": "read_policy",
                    "content": "(RW, since: 5.11)\n\nShows  the  current balance policy for reads.  Currently only \"pid\" (balance using pid\nvalue) is supported.\n"
                },
                {
                    "name": "sectorsize",
                    "content": "(RO, since: 3.14)\n\nShows the sectorsize of the mounted filesystem.\n\nFiles and directories in /sys/fs/btrfs/<UUID>/allocations directory are:\n"
                },
                {
                    "name": "global_rsv_reserved",
                    "content": "(RO, since: 3.14)\n\nThe used bytes of the global reservation.\n"
                },
                {
                    "name": "global_rsv_size",
                    "content": "(RO, since: 3.14)\n\nThe total size of the global reservation.\n\ndata/, metadata/ and system/ directories\n(RO, since: 5.14)\n\nSpace info accounting for the 3 chunk types.  Mostly for debug purposes.\n\nFiles in /sys/fs/btrfs/<UUID>/allocations/data,metadata,system directory are:\n"
                },
                {
                    "name": "bg_reclaim_threshold",
                    "content": "(RW, since: 5.19)\n\nReclaimable space percentage of block group's  size  (excluding  permanently  unusable\nspace) to reclaim the block group.  Can be used on regular or zoned devices.\n"
                },
                {
                    "name": "chunk_size",
                    "content": "(RW, since: 6.0)\n\nShows  the  chunk size. Can be changed for data and metadata.  Cannot be set for zoned\ndevices.\n\nFiles in /sys/fs/btrfs/<UUID>/devinfo/<DEVID> directory are:\n"
                },
                {
                    "name": "error_stats:",
                    "content": "(RO, since: 5.14)\n\nShows all the history error numbers of the device.\n\nfsid:  (RO, since: 5.17)\n\nShows the fsid which the device belongs to.  It can be different than  the  <UUID>  if\nit's a seed device.\n"
                },
                {
                    "name": "in_fs_metadata",
                    "content": "(RO, since: 5.6)\n\nShows  whether  we  have found the device.  Should always be 1, as if this turns to 0,\nthe <DEVID> directory would get removed automatically.\n"
                },
                {
                    "name": "missing",
                    "content": "(RO, since: 5.6)\n\nShows whether the device is missing.\n"
                },
                {
                    "name": "replace_target",
                    "content": "(RO, since: 5.6)\n\nShows whether the device is the replace target.  If no dev-replace  is  running,  this\nvalue should be 0.\n"
                },
                {
                    "name": "scrub_speed_max",
                    "content": "(RW, since: 5.14)\n\nShows the scrub speed limit for this device. The unit is Bytes/s.  0 means no limit.\n"
                },
                {
                    "name": "writeable",
                    "content": "(RO, since: 5.6)\n\nShow if the device is writeable.\n\nFiles in /sys/fs/btrfs/<UUID>/qgroups/ directory are:\n"
                },
                {
                    "name": "enabled",
                    "content": "(RO, since: 6.1)\n\nShows  if qgroup is enabled.  Also, if qgroup is disabled, the qgroups directory would\nbe removed automatically.\n"
                },
                {
                    "name": "inconsistent",
                    "content": "(RO, since: 6.1)\n\nShows if the qgroup numbers are inconsistent.  If 1, it's recommended to do  a  qgroup\nrescan.\n"
                },
                {
                    "name": "drop_subtree_threshold",
                    "content": "(RW, since: 6.1)\n\nShows the subtree drop threshold to automatically mark qgroup inconsistent.\n\nWhen  dropping  large  subvolumes  with qgroup enabled, there would be a huge load for\nqgroup accounting.  If we have a subtree whose level is larger than or equal  to  this\nvalue,  we  will  not  trigger  qgroup account at all, but mark qgroup inconsistent to\navoid the huge workload.\n\nDefault value is 8, where no subtree drop can trigger qgroup.\n\nLower value can reduce qgroup workload, at the cost of extra qgroup rescan to  re-cal‐\nculate the numbers.\n\nFiles in /sys/fs/btrfs/<UUID>/<LEVEL><ID>/ directory are:\n"
                },
                {
                    "name": "exclusive",
                    "content": "(RO, since: 5.9)\n\nShows the exclusively owned bytes of the qgroup.\n"
                },
                {
                    "name": "limit_flags",
                    "content": "(RO, since: 5.9)\n\nShows the numeric value of the limit flags.  If 0, means no limit implied.\n"
                },
                {
                    "name": "max_exclusive",
                    "content": "(RO, since: 5.9)\n\nShows the limits on exclusively owned bytes.\n"
                },
                {
                    "name": "max_referenced",
                    "content": "(RO, since: 5.9)\n\nShows the limits on referenced bytes.\n"
                },
                {
                    "name": "referenced",
                    "content": "(RO, since: 5.9)\n\nShows the referenced bytes of the qgroup.\n"
                },
                {
                    "name": "rsv_data",
                    "content": "(RO, since: 5.9)\n\nShows the reserved bytes for data.\n"
                },
                {
                    "name": "rsv_meta_pertrans",
                    "content": "(RO, since: 5.9)\n\nShows the reserved bytes for per transaction metadata.\n"
                },
                {
                    "name": "rsv_meta_prealloc",
                    "content": "(RO, since: 5.9)\n\nShows the reserved bytes for preallocated metadata.\n\nFiles in /sys/fs/btrfs/<UUID>/discard/ directory are:\n"
                },
                {
                    "name": "discardable_bytes",
                    "content": "(RO, since: 6.1)\n\nShows amount of bytes that can be discarded in the async discard and nodiscard mode.\n"
                },
                {
                    "name": "discardable_extents",
                    "content": "(RO, since: 6.1)\n\nShows number of extents to be discarded in the async discard and nodiscard mode.\n"
                },
                {
                    "name": "discard_bitmap_bytes",
                    "content": "(RO, since: 6.1)\n\nShows amount of discarded bytes from data tracked as bitmaps.\n"
                },
                {
                    "name": "discard_extent_bytes",
                    "content": "(RO, since: 6.1)\n\nShows amount of discarded extents from data tracked as bitmaps.\n"
                },
                {
                    "name": "discard_bytes_saved",
                    "content": "(RO, since: 6.1)\n\nShows the amount of bytes that were reallocated without being discarded.\n"
                },
                {
                    "name": "kbps_limit",
                    "content": "(RW, since: 6.1)\n\nTunable limit of kilobytes per second issued as discard IO in the async discard mode.\n"
                },
                {
                    "name": "iops_limit",
                    "content": "(RW, since: 6.1)\n\nTunable  limit  of  number  of discard IO operations to be issued in the async discard\nmode.\n"
                },
                {
                    "name": "max_discard_size",
                    "content": "(RW, since: 6.1)\n\nTunable limit for size of one IO discard request.\n"
                }
            ]
        },
        "FILESYSTEM EXCLUSIVE OPERATIONS": {
            "content": "There are several operations that affect the whole filesystem and cannot be run in  parallel.\nAttempt to start one while another is running will fail (see exceptions below).\n\nSince  kernel  5.10  the currently running operation can be obtained from /sys/fs/UUID/exclu‐\nsiveoperation with following values and operations:\n\n• balance\n\n• balance paused (since 5.17)\n\n• device add\n\n• device delete\n\n• device replace\n\n• resize\n\n• swapfile activate\n\n• none\n\nEnqueuing is supported for several btrfs subcommands so they can be started at once and  then\nserialized.\n\nThere's  an  exception  when  a paused balance allows to start a device add operation as they\ndon't really collide and this can be used to add more space for the balance to finish.\n",
            "subsections": []
        },
        "FILESYSTEM LIMITS": {
            "content": "",
            "subsections": [
                {
                    "name": "maximum file name length",
                    "content": "255\n\nThis limit is imposed by Linux VFS, the structures of BTRFS could  store  larger  file\nnames.\n"
                },
                {
                    "name": "maximum symlink target length",
                    "content": "depends on the nodesize value, for 4KiB it's 3949 bytes, for larger nodesize it's 4095\ndue to the system limit PATHMAX\n\nThe  symlink  target may not be a valid path, i.e. the path name components can exceed\nthe limits (NAMEMAX), there's no content validation at symlink(3) creation.\n"
                },
                {
                    "name": "maximum number of inodes",
                    "content": "264 but depends on the available metadata space as the inodes are created dynamically\n\nEach subvolume is an independent namespace of inodes and thus their  numbers,  so  the\nlimit is per subvolume, not for the whole filesystem.\n"
                },
                {
                    "name": "inode numbers",
                    "content": "minimum number: 256 (for subvolumes), regular files and directories: 257, maximum num‐\nber: (264 - 256)\n\nThe  inode numbers that can be assigned to user created files are from the whole 64bit\nspace except first 256 and last 256 in that  range  that  are  reserved  for  internal\nb-tree identifiers.\n"
                },
                {
                    "name": "maximum file length",
                    "content": "inherent limit of BTRFS is 264 (16 EiB) but the practical limit of Linux VFS is 263 (8\nEiB)\n"
                },
                {
                    "name": "maximum number of subvolumes",
                    "content": "the  subvolume ids can go up to 248 but the number of actual subvolumes depends on the\navailable metadata space\n\nThe space consumed by all subvolume metadata includes bookkeeping  of  shared  extents\ncan be large (MiB, GiB). The range is not the full 64bit range because of qgroups that\nuse the upper 16 bits for another purposes.\n"
                },
                {
                    "name": "maximum number of hardlinks of a file in a directory",
                    "content": "65536  when  the extref feature is turned on during mkfs (default), roughly 100 other‐\nwise and depends on file name length that fits into one metadata node\n"
                },
                {
                    "name": "minimum filesystem size",
                    "content": "the minimal size of each device depends on the mixed-bg feature, without that (the de‐\nfault) it's about 109MiB, with mixed-bg it's is 16MiB\n"
                }
            ]
        },
        "BOOTLOADER SUPPORT": {
            "content": "GRUB2 (https://www.gnu.org/software/grub) has the most advanced support of booting from BTRFS\nwith respect to features.\n\nU-Boot (https://www.denx.de/wiki/U-Boot/) has decent support for booting but  not  all  BTRFS\nfeatures are implemented, check the documentation.\n\nIn  general, the first 1MiB on each device is unused with the exception of primary superblock\nthat is on the offset 64KiB and spans 4KiB. The rest can be freely used by bootloaders or for\nother system information. Note that booting from a filesystem on zoned  device  is  not  sup‐\nported.\n",
            "subsections": []
        },
        "FILE ATTRIBUTES": {
            "content": "The  btrfs  filesystem  supports setting file attributes or flags. Note there are old and new\ninterfaces, with confusing names. The following list should clarify that:\n\n• attributes:  chattr(1)  or  lsattr(1)  utilities  (the  ioctls  are   FSIOCGETFLAGS   and\nFSIOCSETFLAGS), due to the ioctl names the attributes are also called flags\n\n• xflags: to distinguish from the previous, it's extended flags, with tunable bits similar to\nthe  attributes  but  extensible  and  new bits will be added in the future (the ioctls are\nFSIOCFSGETXATTR and FSIOCFSSETXATTR but they are not  related  to  extended  attributes\nthat  are also called xattrs), there's no standard tool to change the bits, there's support\nin xfsio(8) as command xfsio -c chattr\n",
            "subsections": [
                {
                    "name": "Attributes",
                    "content": "a      append only, new writes are always written at the end of the file\n\nA      no atime updates\n\nc      compress data, all data written after  this  attribute  is  set  will  be  compressed.\nPlease  note  that compression is also affected by the mount options or the parent di‐\nrectory attributes.\n\nWhen set on a directory, all newly created files will inherit  this  attribute.   This\nattribute cannot be set with 'm' at the same time.\n\nC      no copy-on-write, file data modifications are done in-place\n\nWhen set on a directory, all newly created files will inherit this attribute.\n\nNOTE:\nDue to implementation limitations, this flag can be set/unset only on empty files.\n\nd      no  dump, makes sense with 3rd party tools like dump(8), on BTRFS the attribute can be\nset/unset but no other special handling is done\n\nD      synchronous directory updates, for more details search open(2) for OSYNC and ODSYNC\n\ni      immutable, no file data and metadata changes allowed even to the root user as long  as\nthis attribute is set (obviously the exception is unsetting the attribute)\n\nm      no  compression,  permanently  turn off compression on the given file. Any compression\nmount options will not affect this file. (chattr support added in 1.46.2)\n\nWhen set on a directory, all newly created files will inherit  this  attribute.   This\nattribute cannot be set with c at the same time.\n\nS      synchronous updates, for more details search open(2) for OSYNC and ODSYNC\n\nNo  other attributes are supported.  For the complete list please refer to the chattr(1) man‐\nual page.\n\nXFLAGS\nThere's an overlap of letters assigned to the bits with the attributes, this list  refers  to\nwhat xfsio(8) provides:\n\ni      immutable, same as the attribute\n\na      append only, same as the attribute\n\ns      synchronous updates, same as the attribute S\n\nA      no atime updates, same as the attribute\n\nd      no dump, same as the attribute\n"
                }
            ]
        },
        "ZONED MODE": {
            "content": "Since  version 5.12 btrfs supports so called zoned mode. This is a special on-disk format and\nallocation/write strategy that's friendly to zoned devices.  In short,  a  device  is  parti‐\ntioned into fixed-size zones and each zone can be updated by append-only manner, or reset. As\nbtrfs  has  no  fixed  data structures, except the super blocks, the zoned mode only requires\nblock placement that follows the device constraints. You can learn about the whole  architec‐\nture at https://zonedstorage.io .\n\nThe  devices  are  also called SMR/ZBC/ZNS, in host-managed mode. Note that there are devices\nthat appear as non-zoned but actually are, this is drive-managed and using zoned  mode  won't\nhelp.\n\nThe  zone size depends on the device, typical sizes are 256MiB or 1GiB. In general it must be\na power of two. Emulated zoned devices like nullblk allow to set various zone sizes.\n",
            "subsections": [
                {
                    "name": "Requirements, limitations",
                    "content": "• all devices must have the same zone size\n\n• maximum zone size is 8GiB\n\n• minimum zone size is 4MiB\n\n• mixing zoned and non-zoned devices is possible, the zone writes are emulated, but  this  is\nnamely for testing\n\n• the  super  block  is  handled  in  a  special  way and is at different locations than on a\nnon-zoned filesystem:\n\n• primary: 0B (and the next two zones)\n\n• secondary: 512GiB (and the next two zones)\n\n• tertiary: 4TiB (4096GiB, and the next two zones)\n"
                },
                {
                    "name": "Incompatible features",
                    "content": "The main constraint of the zoned devices is lack of in-place update of the data.  This is in‐\nherently incompatible with some features:\n\n• NODATACOW - overwrite in-place, cannot create such files\n\n• fallocate - preallocating space for in-place first write\n\n• mixed-bg - unordered writes to data and metadata, fixing that means using separate data and\nmetadata block groups\n\n• booting - the zone at offset 0 contains superblock, resetting the zone  would  destroy  the\nbootloader data\n\nInitial support lacks some features but they're planned:\n\n• only single (data, metadata) and DUP (metadata) profile is supported\n\n• fstrim - due to dependency on free space cache v1\n"
                },
                {
                    "name": "Super block",
                    "content": "As  said  above, super block is handled in a special way. In order to be crash safe, at least\none zone in a known location must contain a valid superblock.  This is implemented as a  ring\nbuffer in two consecutive zones, starting from known offsets 0B, 512GiB and 4TiB.\n\nThe  values  are different than on non-zoned devices. Each new super block is appended to the\nend of the zone, once it's filled, the zone is reset and writes continue  to  the  next  one.\nLooking  up the latest super block needs to read offsets of both zones and determine the last\nwritten version.\n\nThe amount of space reserved for super block depends on the zone size. The secondary and ter‐\ntiary copies are at distant offsets as the capacity of the devices is expected to  be  large,\ntens  of  terabytes.  Maximum  zone size supported is 8GiB, which would mean that e.g. offset\n0-16GiB would be reserved just for the super block on a  hypothetical  device  of  that  zone\nsize. This is wasteful but required to guarantee crash safety.\n"
                },
                {
                    "name": "Devices",
                    "content": ""
                },
                {
                    "name": "Real hardware",
                    "content": "The  WD  Ultrastar  series 600 advertises HM-SMR, i.e. the host-managed zoned mode. There are\ntwo more: DA (device managed, no zoned information exported to the system), HA  (host  aware,\ncan be used as regular disk but zoned writes improve performance). There are not many devices\navailable  at  the moment, the information about exact zoned mode is hard to find, check data\nsheets or community sources gathering information from real devices.\n\nNote: zoned mode won't work with DM-SMR disks.\n\n• Ultrastar® DC ZN540 NVMe ZNS SSD (product brief)\n"
                },
                {
                    "name": "Emulated: null_blk",
                    "content": "The driver nullblk provides memory backed device and is suitable for testing. There are some\nquirks setting up the devices. The module must be loaded with nrdevices=0 or  the  numbering\nof  device  nodes  will be offset. The configfs must be mounted at /sys/kernel/config and the\nadministration of the nullblk devices is done in /sys/kernel/config/nullb. The device  nodes\nare  named  like /dev/nullb0 and are numbered sequentially. NOTE: the device name may be dif‐\nferent than the named directory in sysfs!\n\nSetup:\n\nmodprobe configfs\nmodprobe nullblk nrdevices=0\n\nCreate a device mydev, assuming no other previously created devices, size  is  2048MiB,  zone\nsize 256MiB. There are more tunable parameters, this is a minimal example taking defaults:\n\ncd /sys/kernel/config/nullb/\nmkdir mydev\ncd mydev\necho 2048 > size\necho 1 > zoned\necho 1 > memorybacked\necho 256 > zonesize\necho 1 > power\n\nThis  will create a device /dev/nullb0 and the value of file index will match the ending num‐\nber of the device node.\n\nRemove the device:\n\nrmdir /sys/kernel/config/nullb/mydev\n\nThen continue with mkfs.btrfs /dev/nullb0, the zoned mode is auto-detected.\n\nFor  convenience,  there's  a  script  wrapping  the  basic  nullblk  management  operations\nhttps://github.com/kdave/nullb.git, the above commands become:\n\nnullb setup\nnullb create -s 2g -z 256\nmkfs.btrfs /dev/nullb0\n...\nnullb rm nullb0\n"
                },
                {
                    "name": "Emulated: TCMU runner",
                    "content": "TCMU  is a framework to emulate SCSI devices in userspace, providing various backends for the\nstorage, with zoned support as well. A file-backed zoned device can provide more options  for\nlarger     storage     and     zone    size.    Please    follow    the    instructions    at\nhttps://zonedstorage.io/projects/tcmu-runner/ .\n"
                },
                {
                    "name": "Compatibility, incompatibility",
                    "content": "• the feature sets an incompat bit and requires new kernel to access the filesystem (for both\nread and write)\n\n• superblock needs to be handled in a special way, there are still 3 copies but at  different\noffsets (0, 512GiB, 4TiB) and the 2 consecutive zones are a ring buffer of the superblocks,\nfinding  the  latest  one  needs reading it from the write pointer or do a full scan of the\nzones\n\n• mixing zoned and non zoned devices is possible (zones are emulated) but is recommended only\nfor testing\n\n• mixing zoned devices with different zone sizes is not possible\n\n• zone sizes must be power of two, zone sizes of real devices are e.g. 256MiB or 1GiB, larger\nsize is expected, maximum zone size supported by btrfs is 8GiB\n"
                },
                {
                    "name": "Status, stability, reporting bugs",
                    "content": "The zoned mode has been released in 5.12 and there are still  some  rough  edges  and  corner\ncases      one      can     hit     during     testing.     Please     report     bugs     to\nhttps://github.com/naota/linux/issues/ .\n"
                },
                {
                    "name": "References",
                    "content": "• https://zonedstorage.io\n\n• https://zonedstorage.io/projects/libzbc/ -- libzbc is library and set  of  tools  to  di‐\nrectly manipulate devices with ZBC/ZAC support\n\n• https://zonedstorage.io/projects/libzbd/  --  libzbd uses the kernel provided zoned block\ndevice interface based on the ioctl() system calls\n\n• https://hddscan.com/blog/2020/hdd-wd-smr.html -- some details about exact device types\n\n• https://lwn.net/Articles/853308/ -- Btrfs on zoned block devices\n\n• https://www.usenix.org/conference/vault20/presentation/bjorling -- Zone Append: A  New  Way\nof Writing to Zoned Storage\n"
                }
            ]
        },
        "CONTROL DEVICE": {
            "content": "There's a character special device /dev/btrfs-control with major and minor numbers 10 and 234\n(the device can be found under the misc category).\n\n$ ls -l /dev/btrfs-control\ncrw------- 1 root root 10, 234 Jan  1 12:00 /dev/btrfs-control\n\nThe device accepts some ioctl calls that can perform following actions on the filesystem mod‐\nule:\n\n• scan  devices  for  btrfs  filesystem (i.e. to let multi-device filesystems mount automati‐\ncally) and register them with the kernel module\n\n• similar to scan, but also wait until the device scanning process is finished  for  a  given\nfilesystem\n\n• get the supported features (can be also found under /sys/fs/btrfs/features)\n\nThe device is created when btrfs is initialized, either as a module or a built-in functional‐\nity and makes sense only in connection with that. Running e.g. mkfs without the module loaded\nwill not register the device and will probably warn about that.\n\nIn  rare  cases when the module is loaded but the device is not present (most likely acciden‐\ntally deleted), it's possible to recreate it by\n\n# mknod --mode=600 /dev/btrfs-control c 10 234\n\nor (since 5.11) by a convenience command\n\n# btrfs rescue create-control-device\n\nThe control device is not strictly required but the device  scanning  will  not  work  and  a\nworkaround would need to be used to mount a multi-device filesystem.  The mount option device\ncan trigger the device scanning during mount, see also btrfs device scan.\n",
            "subsections": []
        },
        "FILESYSTEM WITH MULTIPLE PROFILES": {
            "content": "It  is  possible  that  a btrfs filesystem contains multiple block group profiles of the same\ntype.  This could happen when a profile conversion using balance filters is interrupted  (see\nbtrfs-balance(8)).   Some  btrfs commands perform a test to detect this kind of condition and\nprint a warning like this:\n\nWARNING: Multiple block group profiles detected, see 'man btrfs(5)'.\nWARNING:   Data: single, raid1\nWARNING:   Metadata: single, raid1\n\nThe corresponding output of btrfs filesystem df might look like:\n\nWARNING: Multiple block group profiles detected, see 'man btrfs(5)'.\nWARNING:   Data: single, raid1\nWARNING:   Metadata: single, raid1\nData, RAID1: total=832.00MiB, used=0.00B\nData, single: total=1.63GiB, used=0.00B\nSystem, single: total=4.00MiB, used=16.00KiB\nMetadata, single: total=8.00MiB, used=112.00KiB\nMetadata, RAID1: total=64.00MiB, used=32.00KiB\nGlobalReserve, single: total=16.25MiB, used=0.00B\n\nThere's more than one line for type Data and Metadata, while  the  profiles  are  single  and\nRAID1.\n\nThis  state  of the filesystem OK but most likely needs the user/administrator to take an ac‐\ntion and finish the interrupted tasks. This cannot be easily  done  automatically,  also  the\nuser knows the expected final profiles.\n\nIn  the  example above, the filesystem started as a single device and single block group pro‐\nfile. Then another device was added, followed by balance with convert=raid1 but for some rea‐\nson hasn't finished. Restarting the balance with convert=raid1 will continue and end up  with\nfilesystem with all block group profiles RAID1.\n",
            "subsections": [
                {
                    "name": "NOTE:",
                    "content": "If  you're  familiar with balance filters, you can use convert=raid1,profiles=single,soft,\nwhich will take only the unconverted single profiles and convert them to raid1.  This  may\nspeed up the conversion as it would not try to rewrite the already convert raid1 profiles.\n\nHaving  just  one  profile is desired as this also clearly defines the profile of newly allo‐\ncated block groups, otherwise this depends on internal allocation policy. When there are mul‐\ntiple profiles present, the order of selection is RAID56, RAID10, RAID1, RAID0 as long as the\ndevice number constraints are satisfied.\n\nCommands that print the warning were chosen so they're brought to  user  attention  when  the\nfilesystem state is being changed in that regard. This is: device add, device delete, balance\ncancel,  balance  pause.  Commands  that report space usage: filesystem df, device usage. The\ncommand filesystem usage provides a line in the overall summary:\n\nMultiple profiles:                 yes (data, metadata)\n"
                }
            ]
        },
        "SEEDING DEVICE": {
            "content": "The COW mechanism and multiple devices under one hood enable an interesting concept, called a\nseeding device: extending a read-only filesystem on a device with another  device  that  cap‐\ntures  all  writes.  For example imagine an immutable golden image of an operating system en‐\nhanced with another device that allows to use the data from the golden image and normal oper‐\nation.  This idea originated on CD-ROMs with base OS and allowing to use them for  live  sys‐\ntems,  but this became obsolete. There are technologies providing similar functionality, like\nunionmount, overlayfs or qcow2 image snapshot.\n\nThe seeding device starts as a normal filesystem, once the contents is ready, btrfstune -S  1\nis  used  to flag it as a seeding device. Mounting such device will not allow any writes, ex‐\ncept adding a new device by btrfs device add.   Then  the  filesystem  can  be  remounted  as\nread-write.\n\nGiven  that the filesystem on the seeding device is always recognized as read-only, it can be\nused to seed multiple filesystems from one device at the same time. The UUID that is normally\nattached to a device is automatically changed to a random UUID on each mount.\n\nOnce the seeding device is mounted, it needs the writable device. After adding it, unmounting\nand mounting with umount /path; mount /dev/writable /path or remounting read-write  with  re‐\nmount -o remount,rw makes the filesystem at /path ready for use.\n",
            "subsections": [
                {
                    "name": "NOTE:",
                    "content": "There  is  a  known bug with using remount to make the mount writeable: remount will leave\nthe filesystem in a state where it is unable to clean deleted snapshots, so it  will  leak\nspace until it is unmounted and mounted properly.\n\nFurthermore,  deleting  the  seeding  device  from  the  filesystem can turn it into a normal\nfilesystem, provided that the writable device can also contain all the data from the  seeding\ndevice.\n\nThe  seeding  device flag can be cleared again by btrfstune -f -S 0, e.g.  allowing to update\nwith newer data but please note that this will invalidate all existing filesystems  that  use\nthis  particular seeding device. This works for some use cases, not for others, and the forc‐\ning flag to the command is mandatory to avoid accidental mistakes.\n\nExample how to create and use one seeding device:\n\n# mkfs.btrfs /dev/sda\n# mount /dev/sda /mnt/mnt1\n... fill mnt1 with data\n# umount /mnt/mnt1\n\n# btrfstune -S 1 /dev/sda\n\n# mount /dev/sda /mnt/mnt1\n# btrfs device add /dev/sdb /mnt/mnt1\n# umount /mnt/mnt1\n# mount /dev/sdb /mnt/mnt1\n... /mnt/mnt1 is now writable\n\nNow /mnt/mnt1 can be used normally. The device /dev/sda can be mounted again with  a  another\nwritable device:\n\n# mount /dev/sda /mnt/mnt2\n# btrfs device add /dev/sdc /mnt/mnt2\n# umount /mnt/mnt2\n# mount /dev/sdc /mnt/mnt2\n... /mnt/mnt2 is now writable\n\nThe  writable  device (file:/dev/sdb) can be decoupled from the seeding device and used inde‐\npendently:\n\n# btrfs device delete /dev/sda /mnt/mnt1\n\nAs the contents originated in the seeding device, it's possible to turn /dev/sdb to a seeding\ndevice again and repeat the whole process.\n\nA few things to note:\n\n• it's recommended to use only single device for the seeding device, it  works  for  multiple\ndevices  but  the  single profile must be used in order to make the seeding device deletion\nwork\n\n• block group profiles single and dup support the use cases above\n\n• the label is copied from the seeding device and can be changed by btrfs filesystem label\n\n• each new mount of the seeding device gets a new random UUID\n\n• umount /path; mount /dev/writable /path can be replaced with mount -o remount,rw /path  but\nit won't reclaim space of deleted subvolumes until the seeding device is mounted read-write\nagain before making it seeding again\n"
                },
                {
                    "name": "Chained seeding devices",
                    "content": "Though  it's not recommended and is rather an obscure and untested use case, chaining seeding\ndevices is possible. In the first example, the writable device /dev/sdb can  be  turned  onto\nanother  seeding device again, depending on the unchanged seeding device /dev/sda. Then using\n/dev/sdb as the primary seeding device it can be extended with another writable  device,  say\n/dev/sdd, and it continues as before as a simple tree structure on devices.\n\n# mkfs.btrfs /dev/sda\n# mount /dev/sda /mnt/mnt1\n... fill mnt1 with data\n# umount /mnt/mnt1\n\n# btrfstune -S 1 /dev/sda\n\n# mount /dev/sda /mnt/mnt1\n# btrfs device add /dev/sdb /mnt/mnt1\n# mount -o remount,rw /mnt/mnt1\n... /mnt/mnt1 is now writable\n# umount /mnt/mnt1\n\n# btrfstune -S 1 /dev/sdb\n\n# mount /dev/sdb /mnt/mnt1\n# btrfs device add /dev/sdc /mnt\n# mount -o remount,rw /mnt/mnt1\n... /mnt/mnt1 is now writable\n# umount /mnt/mnt1\n\nAs a result we have:\n\n• sda is a single seeding device, with its initial contents\n\n• sdb  is  a seeding device but requires sda, the contents are from the time when sdb is made\nseeding, i.e. contents of sda with any later changes\n\n• sdc last writable, can be made a seeding one the same way as was sdb, preserving  its  con‐\ntents and depending on sda and sdb\n\nAs  long  as  the seeding devices are unmodified and available, they can be used to start an‐\nother branch.\n"
                }
            ]
        },
        "RAID56 STATUS AND RECOMMENDED PRACTICES": {
            "content": "The RAID56 feature provides striping and parity over several devices, same as the traditional\nRAID5/6. There are some implementation and design deficiencies that make  it  unreliable  for\nsome  corner  cases  and the feature should not be used in production, only for evaluation or\ntesting.  The power failure safety for metadata with RAID56 is not 100%.\n",
            "subsections": [
                {
                    "name": "Metadata",
                    "content": "Do not use raid5 nor raid6 for metadata. Use raid1 or raid1c3 respectively.\n\nThe substitute profiles provide the same guarantees against loss of 1 or 2  devices,  and  in\nsome respect can be an improvement.  Recovering from one missing device will only need to ac‐\ncess  the  remaining 1st or 2nd copy, that in general may be stored on some other devices due\nto the way RAID1 works on btrfs, unlike on a striped profile (similar to  raid0)  that  would\nneed all devices all the time.\n\nThe  space  allocation pattern and consumption is different (e.g. on N devices): for raid5 as\nan example, a 1GiB chunk is reserved on each device, while with raid1 there's each 1GiB chunk\nstored on 2 devices. The consumption of each 1GiB of used metadata is then N * 1GiB for vs  2\n*  1GiB. Using raid1 is also more convenient for balancing/converting to other profile due to\nlower requirement on the available chunk space.\n"
                },
                {
                    "name": "Missing/incomplete support",
                    "content": "When RAID56 is on the same filesystem with different raid profiles, the  space  reporting  is\ninaccurate,  e.g.  df, btrfs filesystem df or btrfs filesystem usage. When there's only a one\nprofile per block group type (e.g. RAID5 for data) the reporting is accurate.\n\nWhen scrub is started on a RAID56 filesystem, it's started on all devices  that  degrade  the\nperformance.  The workaround is to start it on each device separately. Due to that the device\nstats may not match the actual state and some errors might get reported multiple times.\n\nThe write hole problem. An unclean shutdown could leave a partially written stripe in a state\nwhere the some stripe ranges and the parity are from the old writes and some are new. The in‐\nformation which is which is not tracked. Write journal is not  implemented.  Alternatively  a\nfull  read-modify-write  would  make  sure that a full stripe is always written, avoiding the\nwrite hole completely, but performance in that case turned out to be too bad for use.\n\nThe striping happens on all available devices (at the time the chunks were allocated), so  in\ncase  a new device is added it may not be utilized immediately and would require a rebalance.\nA fixed configured stripe width is not implemented.\n\nSTORAGE MODEL, HARDWARE CONSIDERATIONS"
                },
                {
                    "name": "Storage model",
                    "content": "A storage model is a model that captures key physical aspects of data  structure  in  a  data\nstore. A filesystem is the logical structure organizing data on top of the storage device.\n\nThe  filesystem  assumes  several  features or limitations of the storage device and utilizes\nthem or applies measures to guarantee reliability. BTRFS in particular  is  based  on  a  COW\n(copy  on  write)  mode  of writing, i.e. not updating data in place but rather writing a new\ncopy to a different location and then atomically switching the pointers.\n\nIn an ideal world, the device does what it promises. The filesystem assumes that this may not\nbe true so additional mechanisms are applied to either detect  misbehaving  hardware  or  get\nvalid  data  by  other  means.  The devices may (and do) apply their own detection and repair\nmechanisms but we won't assume any.\n\nThe following assumptions about storage devices are considered (sorted by importance, numbers\nare for further reference):\n\n1. atomicity of reads and writes of blocks/sectors (the smallest  unit  of  data  the  device\npresents to the upper layers)\n\n2. there's  a flush command that instructs the device to forcibly order writes before and af‐\nter the command; alternatively there's a barrier command that facilitates the ordering but\nmay not flush the data\n\n3. data sent to write to a given device offset will be written without further changes to the\ndata and to the offset\n\n4. writes can be reordered by the device, unless explicitly serialized by the flush command\n\n5. reads and writes can be freely reordered and interleaved\n\nThe consistency model of BTRFS builds on these assumptions.  The  logical  data  updates  are\ngrouped,  into  a generation, written on the device, serialized by the flush command and then\nthe super block is written ending the generation.  All logical links among metadata  compris‐\ning a consistent view of the data may not cross the generation boundary.\n"
                },
                {
                    "name": "When things go wrong",
                    "content": ""
                },
                {
                    "name": "No or partial atomicity of block reads/writes (1)",
                    "content": "• Problem:  a  partial  block contents is written (torn write), e.g. due to a power glitch or\nother electronics failure during the read/write\n\n• Detection: checksum mismatch on read\n\n• Repair: use another copy or rebuild from multiple blocks using some encoding scheme\n"
                },
                {
                    "name": "The flush command does not flush (2)",
                    "content": "This is perhaps the most serious problem and impossible to  mitigate  by  filesystem  without\nlimitations  and design restrictions. What could happen in the worst case is that writes from\none generation bleed to another one, while still letting the filesystem consider the  genera‐\ntions  isolated.  Crash  at any point would leave data on the device in an inconsistent state\nwithout any hint what exactly got written, what is missing and leading to stale metadata link\ninformation.\n\nDevices usually honor the flush command, but for performance reasons may do internal caching,\nwhere the flushed data are not yet persistently stored. A power failure could lead to a simi‐\nlar scenario as above, although it's less likely that later writes would  be  written  before\nthe  cached  ones.  This  is  beyond what a filesystem can take into account. Devices or con‐\ntrollers are usually equipped with batteries or capacitors to write the cache  contents  even\nafter power is cut. (Battery backed write cache)\n"
                },
                {
                    "name": "Data get silently changed on write (3)",
                    "content": "Such  thing should not happen frequently, but still can happen spuriously due the complex in‐\nternal workings of devices or physical effects of the storage media itself.\n\n• Problem: while the data are written atomically, the contents get changed\n\n• Detection: checksum mismatch on read\n\n• Repair: use another copy or rebuild from multiple blocks using some encoding scheme\n"
                },
                {
                    "name": "Data get silently written to another offset (3)",
                    "content": "This would be another serious problem as the filesystem has no information when  it  happens.\nFor  that  reason  the measures have to be done ahead of time.  This problem is also commonly\ncalled ghost write.\n\nThe metadata blocks have the checksum embedded in the blocks, so a correct atomic write would\nnot corrupt the checksum. It's likely that after reading such block the data inside would not\nbe consistent with the rest. To rule that out there's embedded block number in  the  metadata\nblock.  It's  the logical block number because this is what the logical structure expects and\nverifies.\n\nThe following is based on information publicly available, user  feedback,  community  discus‐\nsions  or  bug  report analyses. It's not complete and further research is encouraged when in\ndoubt.\n"
                },
                {
                    "name": "Main memory",
                    "content": "The data structures and raw data blocks are temporarily stored in computer memory before they\nget written to the device. It is critical that memory is reliable  because  even  simple  bit\nflips  can  have vast consequences and lead to damaged structures, not only in the filesystem\nbut in the whole operating system.\n\nBased on experience in the community, memory bit flips are more common than one would  think.\nWhen  it  happens,  it's reported by the tree-checker or by a checksum mismatch after reading\nblocks. There are some very obvious instances of bit flips that happen, e.g.  in  an  ordered\nsequence  of keys in metadata blocks. We can easily infer from the other data what values get\ndamaged and how. However, fixing that is not straightforward and would  require  cross-refer‐\nencing data from the entire filesystem to see the scope.\n\nIf  available,  ECC  memory should lower the chances of bit flips, but this type of memory is\nnot available in all cases. A memory test should be performed in case there's a  visible  bit\nflip  pattern,  though  this may not detect a faulty memory module because the actual load of\nthe system could be the factor making the problems appear. In recent years attacks on how the\nmemory modules operate have been demonstrated  (rowhammer)  achieving  specific  bits  to  be\nflipped.   While  these were targeted, this shows that a series of reads or writes can affect\nunrelated parts of memory.\n\nFurther reading:\n\n• https://en.wikipedia.org/wiki/Rowhammer\n\nWhat to do:\n\n• run memtest, note that sometimes memory errors happen only when the system is  under  heavy\nload that the default memtest cannot trigger\n\n• memory  errors may appear as filesystem going read-only due to \"pre write\" check, that ver‐\nify meta data before they get written but fail some basic consistency checks\n"
                },
                {
                    "name": "Direct memory access (DMA)",
                    "content": "Another class of errors is related to DMA (direct memory access) performed by device drivers.\nWhile this could be considered a software error, the data transfers that happen  without  CPU\nassistance  may accidentally corrupt other pages. Storage devices utilize DMA for performance\nreasons, the filesystem structures and data pages are passed back and  forth,  making  errors\npossible in case page life time is not properly tracked.\n\nThere are lots of quirks (device-specific workarounds) in Linux kernel drivers (regarding not\nonly  DMA)  that  are  added when found. The quirks may avoid specific errors or disable some\nfeatures to avoid worse problems.\n\nWhat to do:\n\n• use up-to-date kernel (recent releases or maintained long term support versions)\n\n• as this may be caused by faulty drivers, keep the systems up-to-date\n"
                },
                {
                    "name": "Rotational disks (HDD)",
                    "content": "Rotational HDDs typically fail at the level of individual sectors or  small  clusters.   Read\nfailures  are caught on the levels below the filesystem and are returned to the user as EIO -\nInput/output error. Reading the blocks repeatedly may return the data eventually, but this is\nbetter done by specialized tools and filesystem takes the result of the lower layers. Rewrit‐\ning the sectors may trigger internal remapping but this inevitably leads to data loss.\n\nDisk firmware is technically software but from the filesystem  perspective  is  part  of  the\nhardware.  IO  requests  are  processed,  and caching or various other optimizations are per‐\nformed, which may lead to bugs under high load or unexpected physical  conditions  or  unsup‐\nported use cases.\n\nDisks  are  connected  by cables with two ends, both of which can cause problems when not at‐\ntached properly. Data transfers are protected by checksums and the lower layers try  hard  to\ntransfer  the data correctly or not at all. The errors from badly-connecting cables may mani‐\nfest as large amount of failed read or write requests, or as short error bursts depending  on\nphysical conditions.\n\nWhat to do:\n\n• check smartctl for potential issues\n"
                },
                {
                    "name": "Solid state drives (SSD)",
                    "content": "The mechanism of information storage is different from HDDs and this affects the failure mode\nas  well.  The data are stored in cells grouped in large blocks with limited number of resets\nand other write constraints. The firmware tries to avoid unnecessary resets and performs  op‐\ntimizations  to  maximize  the storage media lifetime. The known techniques are deduplication\n(blocks with same fingerprint/hash are mapped to same physical block), compression or  inter‐\nnal  remapping  and garbage collection of used memory cells. Due to the additional processing\nthere are measures to verity the data e.g. by ECC codes.\n\nThe observations of failing SSDs show that the whole electronic fails at once  or  affects  a\nlot  of  data  (e.g. stored on one chip). Recovering such data may need specialized equipment\nand reading data repeatedly does not help as it's possible with HDDs.\n\nThere are several technologies of the memory cells with different characteristics and  price.\nThe  lifetime  is  directly affected by the type and frequency of data written.  Writing \"too\nmuch\" distinct data (e.g. encrypted) may render the internal  deduplication  ineffective  and\nlead to a lot of rewrites and increased wear of the memory cells.\n\nThere  are several technologies and manufacturers so it's hard to describe them but there are\nsome that exhibit similar behaviour:\n\n• expensive SSD will use more durable memory cells and is optimized for reliability and  high\nload\n\n• cheap  SSD is projected for a lower load (\"desktop user\") and is optimized for cost, it may\nemploy the optimizations and/or extended error reporting partially or not at all\n\nIt's not possible to reliably determine the expected lifetime of an SSD due to lack of infor‐\nmation about how it works or due to lack of reliable stats provided by the device.\n\nMetadata writes tend to be the biggest component of lifetime writes to a  SSD,  so  there  is\nsome  value  in  reducing them. Depending on the device class (high end/low end) the features\nlike DUP block group profiles may affect the reliability in both ways:\n\n• high end are typically more reliable and using single for data and metadata could be  suit‐\nable to reduce device wear\n\n• low end could lack ability to identify errors so an additional redundancy at the filesystem\nlevel (checksums, DUP) could help\n\nOnly users who consume 50 to 100% of the SSD's actual lifetime writes need to be concerned by\nthe write amplification of btrfs DUP metadata. Most users will be far below 50% of the actual\nlifetime,  or  will  write the drive to death and discover how many writes 100% of the actual\nlifetime was. SSD firmware often adds its own write multipliers that can be arbitrary and un‐\npredictable and dependent on application behavior, and these will typically have far  greater\neffect  on SSD lifespan than DUP metadata. It's more or less impossible to predict when a SSD\nwill run out of lifetime writes to within a factor of two, so it's hard to justify  wear  re‐\nduction as a benefit.\n\nFurther reading:\n\n• https://www.snia.org/educational-library/ssd-and-deduplication-end-spinning-disk-2012\n\n• https://www.snia.org/educational-library/realities-solid-state-storage-2013-2013\n\n• https://www.snia.org/educational-library/ssd-performance-primer-2013\n\n• https://www.snia.org/educational-library/how-controllers-maximize-ssd-life-2013\n\nWhat to do:\n\n• run smartctl or self-tests to look for potential issues\n\n• keep the firmware up-to-date\n"
                },
                {
                    "name": "NVM express, non-volatile memory (NVMe)",
                    "content": "NVMe is a type of persistent memory usually connected over a system bus (PCIe) or similar in‐\nterface  and the speeds are an order of magnitude faster than SSD.  It is also a non-rotating\ntype of storage, and is not typically connected by a cable. It's not a SCSI type  device  ei‐\nther but rather a complete specification for logical device interface.\n\nIn  a  way the errors could be compared to a combination of SSD class and regular memory. Er‐\nrors may exhibit as random bit flips or IO failures. There are tools to access  the  internal\nlog (nvme log and nvme-cli) for a more detailed analysis.\n\nThere  are  separate error detection and correction steps performed e.g. on the bus level and\nin most cases never making in to the filesystem  level.  Once  this  happens  it  could  mean\nthere's  some systematic error like overheating or bad physical connection of the device. You\nmay want to run self-tests (using smartctl).\n\n• https://en.wikipedia.org/wiki/NVMExpress\n\n• https://www.smartmontools.org/wiki/NVMeSupport\n"
                },
                {
                    "name": "Drive firmware",
                    "content": "Firmware is technically still software but embedded into the hardware. As  all  software  has\nbugs,  so  does firmware. Storage devices can update the firmware and fix known bugs. In some\ncases the it's possible to avoid certain bugs  by  quirks  (device-specific  workarounds)  in\nLinux kernel.\n\nA  faulty  firmware can cause wide range of corruptions from small and localized to large af‐\nfecting lots of data. Self-repair capabilities may not be sufficient.\n\nWhat to do:\n\n• check for firmware updates in case there are known problems, note  that  updating  firmware\ncan be risky on itself\n\n• use up-to-date kernel (recent releases or maintained long term support versions)\n"
                },
                {
                    "name": "SD flash cards",
                    "content": "There  are  a lot of devices with low power consumption and thus using storage media based on\nlow power consumption too, typically flash memory stored on a chip enclosed in  a  detachable\ncard package. An improperly inserted card may be damaged by electrical spikes when the device\nis  turned on or off. The chips storing data in turn may be damaged permanently. All types of\nflash memory have a limited number of rewrites, so the data are internally translated by  FTL\n(flash translation layer). This is implemented in firmware (technically a software) and prone\nto bugs that manifest as hardware errors.\n\nAdding  redundancy  like using DUP profiles for both data and metadata can help in some cases\nbut a full backup might be the best option once problems appear and replacing the card  could\nbe required as well.\n"
                },
                {
                    "name": "Hardware as the main source of filesystem corruptions",
                    "content": ""
                },
                {
                    "name": "If  you use unreliable hardware and don't know about that, don't blame the filesystem when it",
                    "content": ""
                },
                {
                    "name": "tells you.",
                    "content": ""
                }
            ]
        },
        "SEE ALSO": {
            "content": "acl(5), btrfs(8), chattr(1), fstrim(8), ioctl(2), mkfs.btrfs(8), mount(8), swapon(8)\n\n\n6.6.3                                       Mar 31, 2024                                    BTRFS(5)",
            "subsections": []
        }
    },
    "summary": "btrfs  -  topics  about  the  BTRFS  filesystem (mount options, supported file attributes and other)",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "acl",
            "section": "5",
            "url": "https://www.chedong.com/phpMan.php/man/acl/5/json"
        },
        {
            "name": "btrfs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/btrfs/8/json"
        },
        {
            "name": "chattr",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/chattr/1/json"
        },
        {
            "name": "fstrim",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/fstrim/8/json"
        },
        {
            "name": "ioctl",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/ioctl/2/json"
        },
        {
            "name": "mkfs.btrfs",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/mkfs.btrfs/8/json"
        },
        {
            "name": "mount",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/mount/8/json"
        },
        {
            "name": "swapon",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/swapon/8/json"
        }
    ]
}