From b271a2c5dd14aaadfadafd8fc0f5f6d61f447e2a Mon Sep 17 00:00:00 2001 From: Kathryn Baldauf Date: Wed, 22 May 2024 13:56:35 -0700 Subject: [PATCH] Change runhcs create-scratch to use physical backed memory by default Signed-off-by: Kathryn Baldauf --- cmd/runhcs/create-scratch.go | 12 +++++++++++- pkg/go-runhcs/runhcs_create-scratch.go | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/runhcs/create-scratch.go b/cmd/runhcs/create-scratch.go index 1d3cba9539..07bdbb2f43 100644 --- a/cmd/runhcs/create-scratch.go +++ b/cmd/runhcs/create-scratch.go @@ -32,6 +32,10 @@ var createScratchCommand = cli.Command{ Name: "cache-path", Usage: "optional: The path to an existing scratch.vhdx to copy instead of create.", }, + cli.BoolFlag{ + Name: "use-virtual-memory", + Usage: "optional: Whether the UVM should be backed with virtual memory.", + }, }, Before: appargs.Validate(), Action: func(context *cli.Context) (err error) { @@ -52,11 +56,17 @@ var createScratchCommand = cli.Command{ // 256MB with boot from vhd supported. opts.MemorySizeInMB = 256 - opts.VPMemDeviceCount = 1 // Default SCSI controller count is 4, we don't need that for this UVM, // bring it back to 1 to avoid any confusion with SCSI controller numbers. opts.SCSIControllerCount = 1 + if context.Bool("use-virtual-memory") { + opts.VPMemDeviceCount = 1 + } else { + opts.AllowOvercommit = false + opts.VPMemDeviceCount = 0 + } + sizeGB := uint32(context.Uint("sizeGB")) if sizeGB == 0 { sizeGB = lcow.DefaultScratchSizeGB diff --git a/pkg/go-runhcs/runhcs_create-scratch.go b/pkg/go-runhcs/runhcs_create-scratch.go index 00c367c752..b8c0bff9d2 100644 --- a/pkg/go-runhcs/runhcs_create-scratch.go +++ b/pkg/go-runhcs/runhcs_create-scratch.go @@ -22,6 +22,9 @@ type CreateScratchOpts struct { // CacheFile is the path to an existing `scratch.vhx` to copy. If // `CacheFile` does not exit the scratch will be created. CacheFile string + // UseVirtualMemory indicates whether the UVM used to create the + // scratch should be backed with virtual memory or not. + UseVirtualMemory bool } func (opt *CreateScratchOpts) args() ([]string, error) { @@ -38,6 +41,9 @@ func (opt *CreateScratchOpts) args() ([]string, error) { } out = append(out, "--cache-path", abs) } + if opt.UseVirtualMemory { + out = append(out, "--use-virtual-memory") + } return out, nil }