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

Btrfs and SSD wear leveling

Configure mount options to optimize the interaction between CoW and SSD controllers.

In this lesson, you will learn how to use specific mount options to optimize Btrfs for SSDs, helping the drive’s internal wear-leveling algorithms work more efficiently.

The CoW and SSD Conflict

Because Btrfs is a Copy-on-Write (CoW) filesystem, it never overwrites data in place; it writes new data to a fresh block and updates the metadata to point to the new location. While this is great for data integrity and snapshots, it can confuse an SSD controller. SSDs perform best when they know exactly which blocks are "free" so they can prepare them for future writes through a process called garbage collection.

If Btrfs writes data frequently but doesn't tell the SSD which old blocks are now obsolete, the SSD’s internal wear-leveling controller has to work much harder to keep performance high.

Optimizing with Mount Options

To bridge this gap, Btrfs provides the ssd and discard mount options.

The ssd Option

When you mount a filesystem with ssd, Btrfs enables internal optimizations designed to improve the placement of metadata and data blocks. It makes the allocation patterns "SSD-aware," which reduces the amount of unnecessary write amplification that occurs when the filesystem writes to the drive. In many modern kernels, Btrfs detects SSDs automatically, but explicitly setting it in /etc/fstab ensures it is always active.

The discard Option

This option triggers the TRIM command. When Btrfs deletes a file or frees space, the discard option sends a signal to the SSD controller, explicitly marking those blocks as unused. This allows the drive’s garbage collection to clean up those blocks immediately, ensuring the drive stays fast over time.

To apply these, your /etc/fstab line might look like this:

UUID=your-uuid-here / btrfs defaults,ssd,discard=async 0 0

Note: discard=async is preferred over the older discard option, as it queues the TRIM commands rather than blocking the filesystem during the process.

Key Takeaway: By using the ssd and discard=async mount options, you harmonize Btrfs’s CoW nature with your SSD’s hardware controller, reducing wear and maintaining long-term drive performance.