| 1 | ### Understand the alert |
| 2 | |
| 3 | This alert is triggered when the percentage of used Btrfs data space exceeds the configured threshold. Btrfs (B-tree file system) is a modern copy-on-write (CoW) filesystem for Linux which focuses on fault tolerance, repair, and easy administration. This filesystem also provides advanced features like snapshots, checksums, and multi-device spanning. |
| 4 | |
| 5 | ### What does high Btrfs data usage mean? |
| 6 | |
| 7 | High Btrfs data usage indicates that a significant amount of the allocated space for data blocks in the filesystem is being used. This could be a result of many factors, such as large files, numerous smaller files, or multiple snapshots. |
| 8 | |
| 9 | ### Troubleshoot the alert |
| 10 | |
| 11 | Before you attempt any troubleshooting, make sure you have backed up your data to prevent potential data loss or corruption. |
| 12 | |
| 13 | 1. **Add more physical space**: You can add a new disk to the filesystem, depending on your infrastructure and disk RAID configuration. Remember to unmount the drive if it's already mounted, then use the `btrfs device add` command to add the new disk and balance the system. |
| 14 | |
| 15 | 2. **Delete snapshots**: Review the snapshots in your Btrfs filesystem and delete any unnecessary snapshots. Use the `btrfs subvolume list` command to find snapshots and `btrfs subvolume delete` to remove them. |
| 16 | |
| 17 | 3. **Enable compression**: By enabling compression, you can save disk space without deleting files or snapshots. Add the `compress=alg` mount option in your `fstab` configuration file or during the mount procedure, where `alg` is the compression algorithm you want to use (e.g., `zlib`, `lzo`, `zstd`). You can apply compression to existing files using the `btrfs filesystem defragment` command. |
| 18 | |
| 19 | 4. **Enable deduplication**: Implement deduplication to identify and merge blocks of data with common sequences using copy-on-write semantics. You can use third-party tools dedicated to Btrfs deduplication, such as duperemove, bees, and dduper. However, research their stability and reliability before employing them. |
| 20 | |
| 21 | 5. **Perform a balance**: If the data and metadata are unevenly allocated among disks, especially in Btrfs filesystems with multiple disks, you can perform a balance operation to reallocate space between data and metadata. Use the `btrfs balance` command with appropriate usage parameters to start the balance process. |
| 22 | |
| 23 | ### Useful resources |
| 24 | |
| 25 | 1. [Btrfs Wiki](https://btrfs.wiki.kernel.org) |
| 26 | 2. [The Btrfs filesystem on the Arch Linux website](https://wiki.archlinux.org/title/btrfs) |
| 27 | 3. [Ubuntu man pages for Btrfs commands](https://manpages.ubuntu.com/manpages/bionic/man8) |
| 28 | 4. [duperemove](https://github.com/markfasheh/duperemove) |
| 29 | 5. [bees](https://github.com/Zygo/bees) |
| 30 | 6. [dduper](https://github.com/lakshmipathi/dduper) |