Btrfs is an open-source, general-purpose file system for Linux. The name derives from the use of B-trees to store internal file system structures. Different names are used for the file system, including “Butter F S” and “B-tree F S.” Development of Btrfs began at Oracle in 2007, and now a number of companies (including Red Hat, Fujitsu, Intel, SUSE, and many others) are contributing to the development effort. Btrfs is included in the mainline Linux kernel.
copy-on-write data and metadata
– Btrfs provides extent-based file storage with a maximum file size of 50 TB and a maximum file system size of 50 TB.
– All data and metadata is copy-on-write. This means that blocks of data are not changed on disk. Btrfs just copies the blocks and then writes out the copies to a different location.
– Not updating the original location eliminates the risk of a partial update or data corruption during a power failure.
– The copy-on-write nature of Btrfs also facilitates file system features such as replication, migration, backup, and restoration of data.
– Btrfs allows you to create both readable and writable snapshots.
– A snapshot is a copy of an entire Btrfs subvolume taken at a given point in time.
– The snapshots appear as normal directories and you can access the snapshot as you would any other directory.
– Writable snapshots allow you to roll back a file system to a previous state. You can take a snapshot, perform a system upgrade, and reboot into the snapshot if the upgrade causes problems. All snapshots are writable by default but you also have the option to create read-only snapshots.
– Read-only snapshots are useful for a backup and then can be deleted when the backup completes.
Built-in RAID support
– Btrfs also has built-in RAID support for RAID-0, RAID-1, and RAID-10 levels.
– Btrfs’s RAID is not a multi-disk RAID like the software RAID devices created by using the mdadm command. It is not block RAID either because it does not mirror block devices.
– Btrfs’s RAID just ensures that for every block, there are “x” amount of copies. For RAID-1, for example, Btrfs just stores two copies of everything on two different devices.
– Btrfs maintains CRCs for all metadata and data so everything is checksummed to preserve the integrity of data against corruption. With a RAID-1 or RAID-10 configuration, if checksum fails on the first read, data is pulled off from another copy.
online resizing and defragmentation
– Btrfs has online resizing and defragmentation.
– You can add or remove devices while the file systems remain online.
– When a device is removed, the extents stored on it are redistributed to the other devices in the file system.
– You can also replace devices while Btrfs is online. Btrfs rebalances the extents across the new disk and then you can drop the old disk from a Btrfs array.
– Btrfs has transparent compression and currently supports two compression methods: zlib and LZO (the default).
– LZO offers a better compression ratio, whereas zlib offers faster compression.
– Btrfs can determine whether the blocks can be compressed and, therefore, compresses only when possible.
– You enable compression and specify the compression method by using a mount option. For example, to enable LZO or zlib compression:
# mount –o compress=lzo|zlib [device] [mount_point]
– You can also force Btrfs to always compress data:
# mount -o compress-force [device] [mount_point]
Btrfs’s performance improves with use of ssd
– Btrfs automatically detects solid state drives (SSD) and turns off all optimizations for rotational media.
– For example, on spinning disks, it is important to store related data close together to reduce seeking. This requires CPU cycles to get good data locality on spinning disks, which is not as important with SSD.
– TRIM support is also an optimization for SSD. It tells the SSD which blocks are no longer needed and are available to be written over.
Efficient storage for small files
– Btrfs provides efficient storage for small files.
– All Linux file systems address storage in block sizes, for example 4 KB. With other file systems, a file that is smaller than 4 KB wastes the leftover space.
– Btrfs stores these smaller files directly into the metadata, thereby providing a significant performance advantage over other file systems when creating and reading small files.