3

I don't think an informative answer exists on u&l or otherwise, which mentions why COW filesystems are a leg-up over any of the three modes of journaling. How does the former provide both superior safety and performance while the latter provides one at the cost of the other?

computronium
  • 778
  • 6
  • 15

1 Answers1

4

From https://lwn.net/Articles/576276/

When data is overwritten in an ext4 filesystem, the new data is written on top of the existing data on the storage device, destroying the old copy. Btrfs, instead, will move overwritten blocks elsewhere in the filesystem and write the new data there, leaving the older copy of the data in place.

The COW mode of operation brings some significant advantages. Since old data is not overwritten, recovery from crashes and power failures should be more straightforward; if a transaction has not completed, the previous state of the data (and metadata) will be where it always was. So, among other things, a COW filesystem does not need to implement a separate journal to provide crash resistance.

Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64
  • Additional important features allowed by CoW is ability to do atomic changes (the filesystem is always either perfectly in previous state or perfectly in new state but not in any intermediate state no matter when power is lost or OS crashes) and sharing underlying storage space to reduce space needs. The latter is pretty poorly supported in existing software but you can already make copies of huge directory trees with `cp -a --reflink=always` which uses around the same amount of storage to `cp -al` without any of the con-sides. – Mikko Rantalainen Jun 29 '23 at 08:49
  • Note that `reflink` feature is also supported by XFS so it's possible to implement it without CoW filesystem, but CoW makes implementing it really easy. – Mikko Rantalainen Jun 29 '23 at 08:50