Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 7 additions & 29 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,26 +303,7 @@ func (h *Host) CreateContainer(ctx context.Context, id string, settings *prot.VM
networkNamespace = fmt.Sprintf("virtual-pod-%s", virtualPodID)
}

// Extract memory limit from sandbox container spec
var memoryLimit *int64
if settings.OCISpecification.Linux != nil &&
settings.OCISpecification.Linux.Resources != nil &&
settings.OCISpecification.Linux.Resources.Memory != nil &&
settings.OCISpecification.Linux.Resources.Memory.Limit != nil {
memoryLimit = settings.OCISpecification.Linux.Resources.Memory.Limit
logrus.WithFields(logrus.Fields{
"containerID": id,
"virtualPodID": virtualPodID,
"memoryLimit": *memoryLimit,
}).Info("Extracted memory limit from sandbox container spec")
} else {
logrus.WithFields(logrus.Fields{
"containerID": id,
"virtualPodID": virtualPodID,
}).Info("No memory limit found in sandbox container spec")
}

if err := h.CreateVirtualPod(ctx, virtualPodID, virtualPodID, networkNamespace, memoryLimit); err != nil {
if err := h.CreateVirtualPod(ctx, virtualPodID, virtualPodID, networkNamespace, settings.OCISpecification); err != nil {
return nil, errors.Wrapf(err, "failed to create virtual pod %s", virtualPodID)
}
}
Expand Down Expand Up @@ -1305,7 +1286,7 @@ func (h *Host) InitializeVirtualPodSupport(virtualPodsCgroup cgroups.Cgroup) {
}

// CreateVirtualPod creates a new virtual pod with its own cgroup and network namespace
func (h *Host) CreateVirtualPod(ctx context.Context, virtualSandboxID, masterSandboxID, networkNamespace string, memoryLimit *int64) error {
func (h *Host) CreateVirtualPod(ctx context.Context, virtualSandboxID, masterSandboxID, networkNamespace string, pSpec *specs.Spec) error {
h.virtualPodsMutex.Lock()
defer h.virtualPodsMutex.Unlock()

Expand All @@ -1327,18 +1308,15 @@ func (h *Host) CreateVirtualPod(ctx context.Context, virtualSandboxID, masterSan
}
cgroupPath := path.Join(parentPath, virtualSandboxID)

// Create the cgroup for this virtual pod with memory limit if provided
// Create the cgroup for this virtual pod with resource limits if provided
resources := &specs.LinuxResources{}
if memoryLimit != nil {
resources.Memory = &specs.LinuxMemory{
Limit: memoryLimit,
}
if pSpec != nil && pSpec.Linux != nil && pSpec.Linux.Resources != nil {
resources = pSpec.Linux.Resources
logrus.WithFields(logrus.Fields{
"virtualSandboxID": virtualSandboxID,
"memoryLimit": *memoryLimit,
}).Info("Creating virtual pod with memory limit")
}).Info("Creating virtual pod with specified resources")
} else {
logrus.WithField("virtualSandboxID", virtualSandboxID).Info("Creating virtual pod without memory limit")
logrus.WithField("virtualSandboxID", virtualSandboxID).Info("Creating pod cgroup with default resources as none were specified")
}

cgroupControl, err := cgroups.New(cgroups.StaticPath(cgroupPath), resources)
Expand Down
13 changes: 13 additions & 0 deletions internal/hcsoci/hcsdoc_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ func createLCOWSpec(ctx context.Context, coi *createOptionsInternal) (*specs.Spe
// Hooks are not supported (they should be run in the host)
spec.Hooks = nil

// Set default CPU period and quota if not set for LCOW containers.
if spec.Linux != nil &&
spec.Linux.Resources != nil &&
spec.Linux.Resources.CPU != nil {

if spec.Linux.Resources.CPU.Period != nil && *spec.Linux.Resources.CPU.Period == 0 {
*spec.Linux.Resources.CPU.Period = 100000 // Default CPU period
}
if spec.Linux.Resources.CPU.Quota != nil && *spec.Linux.Resources.CPU.Quota == 0 {
*spec.Linux.Resources.CPU.Quota = -1 // No CPU limit
}
}

// Clear unsupported features
spec.Linux.CgroupsPath = "" // GCS controls its cgroups hierarchy on its own.
if spec.Linux.Resources != nil {
Expand Down