Skip to content

Commit

Permalink
image: 2Mb default image size alignment
Browse files Browse the repository at this point in the history
Change the default image size alignment from 128Mb to 2Mb. The guest
image size is 48Mb smaller after this change.

A custom size aligment can be specified using the new variable
IMAGE_SIZE_ALIGNMENT.

Using a smaller guest image size is currently significant on AKS-Kata
hosts, because the entire image gets copied into guest MAP_PRIVATE
pages when using cloud-hypervisor's "--pmem discard_writes=on".

Signed-off-by: Dan Mihai <[email protected]>
  • Loading branch information
danmihai1 committed Dec 27, 2024
1 parent 609a121 commit dae5080
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tools/osbuilder/image-builder/image_builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set -o pipefail

DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc}
MEASURED_ROOTFS=${MEASURED_ROOTFS:-no}
IMAGE_SIZE_ALIGNMENT_MB=${IMAGE_SIZE_ALIGNMENT_MB:-2}

#For cross build
CROSS_BUILD=${CROSS_BUILD:-false}
Expand Down Expand Up @@ -75,9 +76,6 @@ AGENT_INIT=${AGENT_INIT:-no}
SELINUX=${SELINUX:-no}
SELINUXFS="/sys/fs/selinux"

# Align image to 128M
readonly mem_boundary_mb=128

# shellcheck source=../scripts/lib.sh
source "${lib_file}"

Expand Down Expand Up @@ -327,9 +325,9 @@ calculate_img_size() {
img_size="$((img_size + root_free_space_mb))"
fi

remaining="$((img_size % mem_boundary_mb))"
remaining="$((img_size % ${IMAGE_SIZE_ALIGNMENT_MB}))"
if [ "${remaining}" != "0" ]; then
img_size=$((img_size + mem_boundary_mb - remaining))
img_size=$((img_size + ${IMAGE_SIZE_ALIGNMENT_MB} - remaining))
fi

echo "${img_size}"
Expand Down

0 comments on commit dae5080

Please sign in to comment.