Skip to content

Commit

Permalink
Merge pull request #280 from microsoft/danmihai1/no-pmem
Browse files Browse the repository at this point in the history
reduce the memory usage for the guest image
  • Loading branch information
danmihai1 authored and sprt committed Feb 10, 2025
2 parents b2dc769 + c3689b4 commit 25554f3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/runtime/config/configuration-clh.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ block_device_driver = "virtio-blk"
# set to a non zero value.
#disk_rate_limiter_ops_one_time_burst = 0

# If false and nvdimm is supported, use nvdimm device to plug guest image.
# Otherwise virtio-block device is used.
#
# Default is false
disable_image_nvdimm = true

[agent.@PROJECT_TYPE@]
# If enabled, make the agent display debug-level messages.
# (default: disabled)
Expand Down
1 change: 1 addition & 0 deletions src/runtime/pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,7 @@ func newClhHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
FileBackedMemRootList: h.FileBackedMemRootList,
Debug: h.Debug,
DisableNestingChecks: h.DisableNestingChecks,
DisableImageNvdimm: h.DisableImageNvdimm,
BlockDeviceDriver: blockDriver,
BlockDeviceCacheSet: h.BlockDeviceCacheSet,
BlockDeviceCacheDirect: h.BlockDeviceCacheDirect,
Expand Down
11 changes: 9 additions & 2 deletions src/runtime/virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net
clh.ctx = newCtx
defer span.End()

clh.Logger().
WithField("DisableImageNvdimm", hypervisorConfig.DisableImageNvdimm).
WithField("ConfidentialGuest", hypervisorConfig.ConfidentialGuest).
Info("CreateVM")

if err := clh.setConfig(hypervisorConfig); err != nil {
return err
}
Expand Down Expand Up @@ -578,7 +583,9 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net
// Set initial amount of cpu's for the virtual machine
clh.vmconfig.Cpus = chclient.NewCpusConfig(int32(clh.config.NumVCPUs()), int32(clh.config.DefaultMaxVCPUs))

params, err := GetKernelRootParams(hypervisorConfig.RootfsType, clh.config.ConfidentialGuest, !clh.config.ConfidentialGuest)
disableNvdimm := (clh.config.DisableImageNvdimm || clh.config.ConfidentialGuest)
enableDax := false
params, err := GetKernelRootParams(hypervisorConfig.RootfsType, disableNvdimm, enableDax)
if err != nil {
return err
}
Expand Down Expand Up @@ -621,7 +628,7 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net
}

if assetType == types.ImageAsset {
if clh.config.ConfidentialGuest {
if disableNvdimm {
disk := chclient.NewDiskConfig(assetPath)
disk.SetReadonly(true)

Expand Down
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 @@ -329,9 +327,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 25554f3

Please sign in to comment.