| 1 | ### Understand the alert |
| 2 | |
| 3 | The `btrfs_metadata` alert calculates the percentage of used Btrfs metadata space for a Btrfs filesystem. If you receive this alert, it indicates that your Btrfs filesystem's metadata space is being utilized at a high rate. |
| 4 | |
| 5 | ### Troubleshoot the alert |
| 6 | |
| 7 | **Warning: Data is valuable. Before performing any actions, make sure to take necessary backup steps. Netdata is not responsible for any loss or corruption of data, database, or software.** |
| 8 | |
| 9 | 1. **Add more physical space** |
| 10 | |
| 11 | - Determine which disk you want to add and in which path: |
| 12 | ``` |
| 13 | root@netdata~ # btrfs device add -f /dev/<new_disk> <path> |
| 14 | ``` |
| 15 | |
| 16 | - If you get an error that the drive is already mounted, you might have to unmount: |
| 17 | ``` |
| 18 | root@netdata~ # btrfs device add -f /dev/<new_disk> <path> |
| 19 | ``` |
| 20 | |
| 21 | - Check the newly added disk: |
| 22 | ``` |
| 23 | root@netdata~ # btrfs filesystem show |
| 24 | ``` |
| 25 | |
| 26 | - Balance the system to make use of the new drive: |
| 27 | ``` |
| 28 | root@netdata~ # btrfs filesystem balance <path> |
| 29 | ``` |
| 30 | |
| 31 | 2. **Delete snapshots** |
| 32 | |
| 33 | - List the snapshots for a specific path: |
| 34 | ``` |
| 35 | root@netdata~ # sudo btrfs subvolume list -s <path> |
| 36 | ``` |
| 37 | |
| 38 | - Delete an unnecessary snapshot: |
| 39 | ``` |
| 40 | root@netdata~ # btrfs subvolume delete <path>/@some_dir-snapshot-test |
| 41 | ``` |
| 42 | |
| 43 | 3. **Enable a compression mechanism** |
| 44 | |
| 45 | Apply compression to existing files by modifying the `fstab` configuration file (or during the `mount` procedure) with the `compress=alg` option. Replace `alg` with `zlib`, `lzo`, `zstd`, or `no` (for no compression). For example, to re-compress the `/mount/point` path with `zstd` compression: |
| 46 | |
| 47 | ``` |
| 48 | root@netdata # btrfs filesystem defragment -r -v -czstd /mount/point |
| 49 | ``` |
| 50 | |
| 51 | 4. **Enable a deduplication mechanism** |
| 52 | |
| 53 | Deduplication tools like duperemove, bees, and dduper can help identify blocks of data sharing common sequences and combine extents via copy-on-write semantics. Ensure you check the status of these 3rd party tools before using them. |
| 54 | |
| 55 | - [duperemove](https://github.com/markfasheh/duperemove) |
| 56 | - [bees](https://github.com/Zygo/bees) |
| 57 | - [dduper](https://github.com/lakshmipathi/dduper) |
| 58 | |
| 59 | 5. **Perform a balance** |
| 60 | |
| 61 | Balance data/metadata/system-data in empty or near-empty chunks for Btrfs filesystems with multiple disks, allowing space to be reassigned: |
| 62 | |
| 63 | ``` |
| 64 | root@netdata # btrfs balance start -musage=50 -dusage=10 -susage=5 /mount/point |
| 65 | ``` |
| 66 | |
| 67 | ### Useful resources |
| 68 | |
| 69 | 1. [The Btrfs filesystem on Arch Linux website](https://wiki.archlinux.org/title/btrfs) |
| 70 | 2. [The Btrfs filesystem on kernel.org website](https://btrfs.wiki.kernel.org) |