19.5 Compressing and Defragmenting a Btrfs File System

You can compress a btrfs file system to increase its effective capacity, and you can defragment it to increase I/O performance.

To enable compression of a btrfs file system, specify one of the following mount options:

Mount Option

Description

compress=lzo

Use LZO compression.

compress=zlib

Use zlib compression.

LZO offers a better compression ratio, while zlib offers faster compression.

You can also compress a btrfs file system at the same time that you defragment it.

To defragment a btrfs file system, use the following command:

# btrfs filesystem defragment filesystem_name

To defragment a btrfs file system and compress it at the same time:

# btrfs filesystem defragment -c filesystem_name

You can also defragment, and optionally compress, individual file system objects, such as directories and files, within a btrfs file system.

# btrfs filesystem defragment [-c] file_name ...  
Note

You can set up automatic defragmentation by specifying the autodefrag option when you mount the file system. However, automatic defragmentation is not recommended for large databases or for images of virtual machines.

Defragmenting a file or a subvolume that has a copy-on-write copy results breaks the link between the file and its copy. For example, if you defragment a subvolume that has a snapshot, the disk usage by the subvolume and its snapshot will increase because the snapshot is no longer a copy-on-write image of the subvolume.