Snapshot exception store
A snapshot exception store is the metadata on a copy-on-write device that maps changed origin chunks to their saved copies in a classic device-mapper snapshot.
A snapshot reads unchanged chunks from its origin and changed chunks from its copy-on-write (COW) device, and the exception records identify that correspondence. The COW device is therefore not a standalone full-volume image. Each on-disk exception is 16 bytes, an old_chunk and a new_chunk stored as little-endian 64-bit values, so one metadata chunk holds as many entries as its size in bytes divided by 16. [1] [2]
In the persistent format the first chunk holds a header with the magic value 0x70416e53, a valid flag, on-disk version 1 and the chunk size in sectors. A metadata chunk follows, then as many data chunks as it can describe, and the pattern repeats. An exception whose new_chunk is 0 ends the table, because chunk 0 is the header. Without a supplied chunk size the code uses 32 sectors, or 16 KiB, unless the logical block size is larger, which gives 1024 exceptions per metadata area. [2]
Persistent stores of type P or PO retain the metadata across reboots, while the transient type N can keep it in kernel memory. The status line ends with sectors_allocated/total_sectors and metadata_sectors, and a merge back into the origin is complete when the allocated figure equals the metadata figure. [1]
Relations
Advantages
- Only chunks changed after creation consume space, so the COW device is often much smaller than the origin. [1]
Limitations
- If the COW device fills up, the snapshot becomes useless, is disabled and returns errors, so free space has to be monitored and extended in advance. [1]
- An invalid snapshot cannot be recovered, and metadata with an on-disk version different from the kernel's is not usable because no compatibility is implemented. [2]
Citations
- Linux device-mapper: snapshot targets and merge completion
- Linux v6.16 drivers/md/dm-snap-persistent.c: on-disk header, exception records and default chunk size
Sources & caveats
- Scope: classic Linux dm-snapshot, not dm-thin, filesystem snapshots or exception handling in a programming language.
- dm-snapshot is the kernel admin guide page, read for table arguments, store types, the full-device behaviour and the status line.
- dm-snap-persistent is the Linux v6.16 source file, read for the disk_header and disk_exception structures, the area layout and the default chunk size.
- The 1024 entries per area follow from 16 KiB divided by the 16-byte record and were not measured on a device.