12

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.

1 Answer 1

21

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.

3
  • It's unclear to me from the link whether it's the original volume or the snapshot which becomes COW? i.e. if I only take read-only snapshots for backup purposes, does that mean that the original volume will continue honouring nodatacow? Or does that mean that the original volume is not "... NOCOW on the first write after a snapshot", forever?
    – Luciano
    Jul 27, 2018 at 9:03
  • 2
    @Luciano The first write on the original volume after snapshoting must be COWed. But the subsequent writes on the that same volume will honor NOCOW again.
    – so61pi
    May 23, 2019 at 10:07
  • Will COW still happen if all the snapshots of the sub-volume have been removed ? Or if no write happen while the snapshot lives ? Aug 18, 2020 at 18:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .