I have a 1TB zpool and a 700GB volume with one clean snapshot, such as:
zpool1
zpool1/volume1
zpool1/volume1@snap1
After writing 500GB data into volume, its written property has growth to 500GB as well.
Then I tried to rollback to the snapshot and I got error with "out of space".
Does zpool need extra space to rollback snapshot with big written value? Or can anyone explain why it fails?
After searching of zfs source code(dsl_dataset.c), I found the last part of dsl_dataset_rollback_check() may explain this limit:
* When we do the clone swap, we will temporarily use more space
* due to the refreservation (the head will no longer have any
* unique space, so the entire amount of the refreservation will need
* to be free). We will immediately destroy the clone, freeing
* this space, but the freeing happens over many txg's.
*
unused_refres_delta = (int64_t)MIN(ds->ds_reserved,
dsl_dataset_phys(ds)->ds_unique_bytes);
if (unused_refres_delta > 0 &&
unused_refres_delta >
dsl_dir_space_available(ds->ds_dir, NULL, 0, TRUE)) {
dsl_dataset_rele(ds, FTAG);
return (SET_ERROR(ENOSPC));
}
So that the volume's "avail" must be lager than "refreserv" to perform rollback. Only for thin-volume can pass this check.