简体   繁体   中英

What happens when write request occurs in snapshot copy on write?

I am reading over some operating system concepts and stumbled upon this.

From what I understand, when you take a snapshot,

copy on write will record the current state of the file system (metadata). This will result in a slight halt in the system (almost instantaneous).

If the file system receives a read request on an unmodified file, we are reading the snapshot metadata and it redirects us to the original copy.

What happens when the filesystem receives a write request? Does it update both the original and the copied file system?

This very much depends on what kind of snapshots you are talking about.

If you are talking about the kind of snapshots built in to a copy-on-write filesystem like Btrfs or ZFS, then write requests on snapshots "just work" as a side effect of how the file system works: when new data are written, they are written to a new location, and new metadata are written to reflect this. But both the new data and metadata are written in one snapshot only, not in the other. Once the new data and new metadata are written, the snapshot that was written releases the old copies – but the other snapshot is still using that copy so they aren't actually released. The end result is that these data are no longer shared between the two snapshots. I use the terms "snapshot" and "other snapshot" because in this kind of system, once a snapshot is taken, both the snapshot and the original are on equal footing.

If you are talking about something like LVM snapshots, then the file system is actually completely unaware of what's going on. As far as it's concerned, it's writing to a regular block device. In this case LVM has to manage which underlying blocks are still shared between the snapshot and the snapshot's origin and which ones have diverged. The snapshots stores copies of the blocks that have diverged (either because they were written in the snapshot or in the origin device).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM