openzfs / openzfs-docs

OpenZFS Documentation
https://openzfs.github.io/openzfs-docs/
132 stars 190 forks source link

What snapshot defer_destroy actualy does? #480

Closed Harvie closed 8 months ago

Harvie commented 8 months ago

Hello, i've found that i can do zfs destroy -d ... which in some cases cause "deffered destroy" by setting defer_destroy=on flag on that snapshot. So far it's documented. But in the docs i am not able to find who acctualy initiates the destroy once the pre-conditions are met.

What if i use zfs set defer_destroy=on tank@mysnapshot? will it get destroyed? when? is the destruction retried by kernel during scrub? or is it just retried by userspace utility next time i'll call zfs destroy?

I have system with thousands of snapshots and removal of these is rather slow and blocking operation. I would like to somehow mark them for destroy and let the kernel module remove them on background during idle moments without blocking the pool, making system unresponsive. But i am not able to figure the inner workings from the docs to see if this might be a viable option.

Thanks in advance for clarification.

gmelikov commented 8 months ago

https://openzfs.github.io/openzfs-docs/man/v2.1/8/zfs-destroy.8.html

The given snapshots are destroyed immediately if and only if the zfs destroy command without the -d option would have destroyed it. Such immediate destruction would occur, for example, if the snapshot had no clones and the user-initiated reference count were zero.

If a snapshot does not qualify for immediate destruction, it is marked for deferred deletion. In this state, it exists as a usable, visible snapshot until both of the preconditions listed above are met, at which point it is destroyed.

It should be initiated by removal of last clones or holds.

The property could not be set by zfs set:

# zfs set defer_destroy=on rpool/test@s
cannot set property for 'rpool/test@s': this property can not be modified for snapshots

On topic, ZFS already has async destroy, and usual zfs destroy without -d does it asynchonously (if you have com.delphix:async_destroy feature flag enabled). If this activity affects you somehow (it should not affect you drastically) - you can just destroy snapshots while system is idle by yourself.

You may use discussions section for question next time https://github.com/openzfs/zfs/discussions , I'll close this ticket but feel free to write if you have some questions in discussions section.

Harvie commented 8 months ago

Thank you, that async_destroy flag seems worth a try. Update: in fact it's already on by default, but zfs destroy command can still take 45 minutes to finish, while blocking pool access. even simple stuff like zfs list -t snapshot is blocked till the command finishes.