On Wed, Mar 27, 2019 at 02:24:16PM +0200, Nikolay Borisov wrote: > Currently unallocated chunks are always trimmed. For example > 2 consecutive trims on large storage would trim freespace twice > irrespective of whether the space was actually allocated or not between > those trims. > > Optimise this behavior by exploiting the newly introduced alloc_state > tree of btrfs_device. A new CHUNK_TRIMMED bit is used to mark > those unallocated chunks which have been trimmed and have not been > allocated afterwards. On chunk allocation the respective underlying devices' > physical space will have its CHUNK_TRIMMED flag cleared. This avoids > submitting discards for space which hasn't been changed since the last > time discard was issued.
This means during one mount, right? Because the state is not recorded on-disk anywhere. This also means that a complete unmount / mount followed by trim will do the discard on the freed blocks again. I don't thik there's anything wrong with that, just that this should be put to the docs.