Skip to content

Commit

Permalink
free_space_estimate: adjust for compression on btrfs
Browse files Browse the repository at this point in the history
We have a problem with Fedora aarch64 KDE disk images ATM. We
want to make them 16 power-of-ten gigabytes big, so they will fit
on "16GB" SD cards / USB sticks. When we set them to this size,
compose fails because the anaconda free space check fails, saying
"An additional 436 MiB is needed". That check is ultimately backed
by this estimate.

In these images, the main system partition is a btrfs volume,
with compression enabled. If you examine the last successful
image (which was built at size 18 power-of-two GB), thanks to
compression, only ~5GB of space is actually occupied on that
volume. The contents would easily fit if it were slightly smaller.

With this change we adjust the free space estimate by a
compression factor, as well as a metadata factor, if the class
defines one. For the btrfs class we set it to 1.4 when the
compression flag is set. That's a pretty conservative estimate,
we will usually achieve a much better compression ratio with
a typical OS payload (as the numbers above show). AFAICT this
codepath is only actually used by the anaconda size check, so
the change should be fairly safe.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill committed Oct 3, 2024
1 parent 8cbb151 commit aab5dcb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion blivet/formats/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,13 @@ def free_space_estimate(cls, device_size):
:return: estimated free size after format
:rtype: :class:`~.size.Size`
"""
return device_size * cls._metadata_size_factor
estimate = device_size * cls._metadata_size_factor
try:
estimate = estimate * cls._compression_size_factor
except AttributeError:
# class doesn't have compression size factor, this is fine
pass
return estimate

@classmethod
def get_required_size(cls, free_space):
Expand Down Expand Up @@ -1055,6 +1061,12 @@ class BTRFS(FS):
_max_size = Size("16 EiB")
_mkfs_class = fsmkfs.BTRFSMkfs
_metadata_size_factor = 0.80 # btrfs metadata may take 20% of space
if flags.btrfs_compression:
# let's assume we have 40% "more space" with compression,
# this is pretty conservative
_compression_size_factor = 1.40
else:
_compression_size_factor = 1
# FIXME parted needs to be taught about btrfs so that we can set the
# partition table type correctly for btrfs partitions
# parted_system = fileSystemType["btrfs"]
Expand Down

0 comments on commit aab5dcb

Please sign in to comment.