From 32975ce2970fee62b6d5884889b64f8953e9c11d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 2 Oct 2020 09:47:14 +0200 Subject: [slx-dmsetup] Add overprovisioning formula for CoW volume --- modules.d/slx-dmsetup/scripts/dmsetup-slx-device | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device index f890cd44..ff25e167 100755 --- a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device +++ b/modules.d/slx-dmsetup/scripts/dmsetup-slx-device @@ -566,18 +566,22 @@ if [ -n "$thin_snapshot" ] || [ -n "$thin_volume" ]; then # create thin-snapshot, use first one read -r name crypt min max ignore <<< "$thin_snapshot" # min/max was used for the pool data device, ignore it here! - # NOTE: the filesystem will most likely malfunction if the size of the - # thin-snapshot is smaller than what it was upon creation. - # As such, the size of the thin-snapshot can only be $scratch_device_sz - # if it is larger than $read_only_device_sz, otherwise we should only - # use $read_only_device_sz. While live-shrinking the filesystem might be - # an option, it is not supported throughout all fileystems (xfs can't). - if (( scratch_device_sz >= read_only_device_sz )); then - thin_snapshot_sz="$scratch_device_sz" - else - thin_snapshot_sz="$read_only_device_sz" - fi - # For later on-demand growing + # Calculate how much of the CoW space we reserve for changes in the base + # system. Usually all the files in the base system should be static, but + # if someone decided to run apt dist-upgrade, this would change a lot of + # existing blocks, which is bad. + # Use MIN( readonly_size / 2, scratch_size / 10 ) + # until we come up with anything better. + # Given an RO image of 10GB, this gives us: + # 40GB scratch -> 46GB, so initially 36GB free space + # 5GB scratch -> 14.5GB, initially 4.5GB free space + declare -r max_reserved_sz="$(( scratch_device_sz / 10 ))" + reserved_sz="$(( read_only_device_sz / 2 ))" + (( reserved_sz > max_reserved_sz )) && reserved_sz="$max_reserved_sz" + thin_snapshot_sz="$(( scratch_device_sz + read_only_device_sz - reserved_sz ))" + # For later on-demand growing, overprovision by free space we found on + # clean NTFS volumes. This requires a user-space helper to listen for + # dm events in stage4, which should in turn add that free space to the pool-data if (( root_ntfs_extra > 0 )); then thin_snapshot_sz="$(( thin_snapshot_sz + root_ntfs_extra ))" fi -- cgit v1.2.3-55-g7522