btrfs and the discard mount option on an ssd

6,416

Copy-on-write means that allocated blocks are not overwritten – instead, when a data block in a file changes, a new block is allocated with the new data and the file is updated to refer to the new block instead of the original one. When the old block is no longer referenced by any part of the file system, it is freed. Copy-on-write does not mean that no blocks are ever freed.

The discard option just tells Btrfs to report free blocks to the underlying device. Btrfs already keeps track of which blocks are free, and reporting this information to the underlying device won't affect copy-on-write behaviour.

Share:
6,416

Related videos on Youtube

witchbutter
Author by

witchbutter

Updated on September 18, 2022

Comments

  • witchbutter
    witchbutter over 1 year

    I can't seem to find an answer to this so I thought I would ask here:

    In /etc/fstab and when using the mount command in ext4 you would add the option discard to activate TRIM on an SSD. Similarly the discard option activates TRIM on btrfs volumes as confirmed at btrfs.wiki.kernel.org. Btrfs is supposed to enable copy on write by nature and if this is the case does the discard option effectively disable copy on write?

    I'm imagining TRIM erasing all of the blocks that would have contained previous versions of files. If copy on write still functions doesn't that reduce the performance of an SSD long term, if eventually none of the blocks are zeroed out?