...

Source file src/github.com/Microsoft/hcsshim/internal/hcsoci/resources.go

Documentation: github.com/Microsoft/hcsshim/internal/hcsoci

     1  package hcsoci
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/Microsoft/hcsshim/internal/log"
     7  	"github.com/sirupsen/logrus"
     8  )
     9  
    10  // MountType represents the type of mount being added
    11  type MountType = string
    12  
    13  // MountType const
    14  const (
    15  	// supported internal mount types
    16  	MountTypeBind                  MountType = "bind"
    17  	MountTypePhysicalDisk          MountType = "physical-disk"
    18  	MountTypeVirtualDisk           MountType = "virtual-disk"
    19  	MountTypeExtensibleVirtualDisk MountType = "extensible-virtual-disk"
    20  )
    21  
    22  // NormalizeProcessorCount returns the `Min(requested, logical CPU count)`.
    23  func NormalizeProcessorCount(ctx context.Context, cid string, requestedCount, hostCount int32) int32 {
    24  	if requestedCount > hostCount {
    25  		log.G(ctx).WithFields(logrus.Fields{
    26  			"id":              cid,
    27  			"requested count": requestedCount,
    28  			"assigned count":  hostCount,
    29  		}).Warn("Changing user requested cpu count to current number of processors on the host")
    30  		return hostCount
    31  	} else {
    32  		return requestedCount
    33  	}
    34  }
    35  
    36  // NormalizeMemorySize returns the requested memory size in MB aligned up to an even number
    37  func NormalizeMemorySize(ctx context.Context, cid string, requestedSizeMB uint64) uint64 {
    38  	actualMB := (requestedSizeMB + 1) &^ 1 // align up to an even number
    39  	if requestedSizeMB != actualMB {
    40  		log.G(ctx).WithFields(logrus.Fields{
    41  			"id":          cid,
    42  			"requestedMB": requestedSizeMB,
    43  			"actualMB":    actualMB,
    44  		}).Warn("Changing user requested MemorySizeInMB to align to 2MB")
    45  	}
    46  	return actualMB
    47  }
    48  

View as plain text