Skip to content

Commit

Permalink
runtime: Set memory config shared=false when shared_fs=None in CLH
Browse files Browse the repository at this point in the history
This commit sets memory config `shared` to false in cloud hypervisor when creating
vm with shared_fs=None && hugePages = false.

Currently in runtime/virtcontainers/clh.go,the memory config shared is by default set to true.
As per the CLH memory document,
(a) shared=true is needed in case like when using virtio_fs since virtiofs daemon runs as separate process than clh.
(b) for shared_fs=none + hugespages=false, shared=false can be set to use private anonymous memory for guest (with no file backing).
(c) Another memory config thp (use transparent huge pages) is always enabled by default.
As per documentation, (b) + (c) can be used in combination.
However, with the current CLH implementation, the above combination cannot be used since shared=true is always set.

Signed-off-by: Sumedh Alok Sharma <[email protected]>
  • Loading branch information
Sumynwa committed Dec 11, 2024
1 parent 1f4360c commit 9224163
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/runtime/virtcontainers/clh.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,14 @@ func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Net

// Create the VM memory config via the constructor to ensure default values are properly assigned
clh.vmconfig.Memory = chclient.NewMemoryConfig(int64((utils.MemUnit(clh.config.MemorySize) * utils.MiB).ToBytes()))
// shared memory should be enabled if using vhost-user(kata uses virtiofsd)
clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(true)
// Memory config shared is to be enabled when using vhost_user backends,
// ex. virtio-fs or when using HugePages.
// If such features are disabled, turn off shared memory config.
if clh.config.SharedFS == config.NoSharedFS && !clh.config.HugePages {
clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(false)
} else {
clh.vmconfig.Memory.Shared = func(b bool) *bool { return &b }(true)
}
// Enable hugepages if needed
clh.vmconfig.Memory.Hugepages = func(b bool) *bool { return &b }(clh.config.HugePages)
if !clh.config.ConfidentialGuest && igvmPath == "" {
Expand Down

0 comments on commit 9224163

Please sign in to comment.