BTRFS – Disabling COW on a file or directory – NODATACOW
Recommend to set nodatacow – turn cow off – for the files that require fast IO and tend to get very big and get alot of random writes: such VMDK (vm disks) files and the like.
Copy on write: the tendancy to not overwrite old blocks, it will always try to write in new areas. Turning it off will overwrite old blocks.
Turn off COW on file or folder (only works on 0 byte sized files):
# chattr +C file
Turn on COW on file or folder (only works on 0 byte sized files):
# chattr -C file
Turn off COW on directory recursively:
# chattr -R +C file
Turn on COW on directory recursively:
# chattr -R -C file
See if COW is off, on file or folder with lsattr command output will have a big C for a file if its COW is disabled. If its COW is enabled there wont be a C, it would just be left as a dash -.
chattr +C only works on folders, and empty files. New files in folders that have +C will get the +C property (+C meaning nocow or COW is disabled)
# lsattr filename
filename See if COW is off, on directory:
# lsattr -d dirname
See attributes of everything down recursively: # lsattr -R | grep .
NOTE: you can still take snapshots even though COW is off (but how? magic but it works – snapshots just redo a pointer, lets just say a snapshot tells the FS to do COW for that moment, so the old blocks before then do not get overwritten even though COW was off for them), also you can mount a whole subvolume with and without COW with mount option nodatacow.
READ THIS UPDATE: http://ram.kossboss.com/btrfs-nodatacow-reflink-copies-snapshots/
RULE OF THUMB: cow or nocow property on a folder doesn’t do anything to blocks on the filesystem. cow or nocow on a folder just determines if new files (or 0 byte sized files) in that folder will have cow or nocow. cow or nocow can only be applied to new files or 0 byte sized files. so you cant take cow away or give cow to a file that is already existing and if bigger than 0 bytes. (by cow I mean COW enabled, by nocow I mean COW disabled)