Skip to content

Commit

Permalink
build_image: btrfs: minimize allocation
Browse files Browse the repository at this point in the history
Rebalance the /usr btrfs allocation to the maximum possible, in order to
increase the chance of having the btrfs `Free (statfs, df)` similar to
`Free (estimated)`.

Note that /usr is also a zstd compressed btrfs partition, so the output
of `df` free size and the actual free size after a file write for
example, will be very different, because the data in that file write has
a compression rate only definable after the file sync.

Unfortunately, there is no determinism in the btrfs file system case, because even if
you could in theory pre-compress with zstd the file before, and have an
idea about the size to be used, you still cannot really predict also the metadata
size for that file write.

See: flatcar/Flatcar#1473

Signed-off-by: Adrian Vladu <[email protected]>
  • Loading branch information
ader1990 committed Jul 5, 2024
1 parent e4cc483 commit 737e771
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions build_library/disk_util
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ def ReadWriteSubvol(options, partition, disable_rw):
btrfs_mount = tempfile.mkdtemp()
Sudo(['mount', '-t', 'btrfs', loop_dev, btrfs_mount])
try:
Sudo(['btrfs', 'balance', 'start', '-dusage=0', '-musage=0', btrfs_mount])
Sudo(['btrfs', 'property', 'set', '-ts', btrfs_mount, 'ro', 'true' if disable_rw else 'false'])
finally:
Sudo(['umount', btrfs_mount])
Expand Down

0 comments on commit 737e771

Please sign in to comment.