BTRFS – Taking Snapshots of a Volume Mounted with nodatacow

btrfsfilesystemssnapshot

I plan to create two subvolumes on a BTRFS-formatted spinning disk. I plan to mount one of those subvolumes with nodatacow so that I can efficiently store virtual machine images and database files there.

Is there any problem using snapper to enable snapshots of the subvolume mounted with nodatacow?

What should I be aware of when taking snapshots of volumes that don't use COW?

All I have found so far is a sentence in the BTRFS FAQ:

Can copy-on-write be turned off for data blocks?

Yes, there are several ways how to do that.

Disable it by mounting with nodatacow. This implies nodatasum as well.
COW may still happen if a snapshot is taken.

Best Answer

Regarding the nodatacow option, Ohad Rodeh's paper titled BTRFS: The Linux B-tree Filesystem states:

It cancels copy-on-write for data blocks, unless there is a snapshot.

There is no problem with creating a snapshot of a subvolume mounted with nodatacow. But since cow is required to create a snapshot, when you create one on a subvolume with nodatacow it will essentially ignore nodatacow; acting as it normally would.

That does however bring up an interesting question: Is the nodatacow ignored permanently? Does creating a snapshot of a subvolume with COW disabled, reenable COW until it's manually disabled again?

Luckily, no. From the btrfs mailing list...

On a NOCOW file the first write to a fileblock (4096 bytes) after a snapshot must still be COW, because the snapshot locks the old version in place, and now the fileblock has changed, so it MUST be written elsewhere despite the NOCOW in ordered to keep the snapshot as it was. However, the file does retain the NOCOW attribute and additional writes to the same fileblock will be in-place... until the next snapshot of course.

Related Question