Course contentsShow
← Linux
Lesson 730 of 1,8197. Storage Management and Logical VolumesFree lesson

Btrfs block group reclaim

Optimize space utilization by managing chunk rebalancing within the filesystem.

In this lesson, you will learn how to optimize your Btrfs filesystem’s storage efficiency by reclaiming underutilized "chunks" of data space.

Understanding Block Group Fragmentation

In Btrfs, the filesystem divides your storage devices into large segments called "chunks" or "block groups." Over time, as you delete files, snapshots, or subvolumes, these chunks become sparsely populated. You might have several chunks that are only 10% full, but because Btrfs sees them as "allocated," it cannot use that space for new data. This leads to a frustrating scenario: the OS reports that the disk is full, yet you know you have plenty of empty space scattered inside those partially used chunks.

Reclaiming Space with Balance

The primary tool to fix this is the btrfs balance command. Balancing is the process of moving data blocks from one chunk to another to consolidate them. By "compacting" the data into fewer chunks, you free up the remaining partially used chunks, which the filesystem can then return to the general free space pool.

To optimize your space, you use the usage filter. This tells Btrfs to only look for chunks that are below a certain percentage of utilization. For example, to reclaim space from chunks that are less than 20% full, you would run:

sudo btrfs balance start -dusage=20 /mnt/your_mount_point

Why Use Filters?

Running a full balance (without filters) is extremely resource-intensive because it moves every single data block on the filesystem. By using the -dusage (data usage) filter, you target only the "wasted" space.

  • -dusage=5: Targets very empty chunks (less than 5% full).
  • -dusage=20: Targets chunks that are less than 20% full.

It is best practice to start with a low percentage (like 5 or 10) to reclaim space quickly without excessive disk wear. If the filesystem still reports space issues, you can gradually increase the percentage in subsequent runs. This maintenance keeps your volume agile and ensures you aren't paying for "ghost" storage that is allocated but empty.

Key Takeaway: Use btrfs balance start -dusage=X to consolidate sparse data chunks, effectively freeing up underutilized storage space for new files.