...

Source file src/github.com/Microsoft/hcsshim/internal/uvm/memory_update.go

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

     1  //go:build windows
     2  
     3  package uvm
     4  
     5  import (
     6  	"context"
     7  	"fmt"
     8  
     9  	"github.com/Microsoft/hcsshim/internal/hcs/resourcepaths"
    10  	hcsschema "github.com/Microsoft/hcsshim/internal/hcs/schema2"
    11  	"github.com/Microsoft/hcsshim/internal/memory"
    12  )
    13  
    14  const bytesPerPage = 4096
    15  
    16  // UpdateMemory makes a call to the VM's orchestrator to update the VM's size in MB
    17  // Internally, HCS will get the number of pages this corresponds to and attempt to assign
    18  // pages to numa nodes evenly
    19  func (uvm *UtilityVM) UpdateMemory(ctx context.Context, sizeInBytes uint64) error {
    20  	requestedSizeInMB := sizeInBytes / memory.MiB
    21  	actual := uvm.normalizeMemorySize(ctx, requestedSizeInMB)
    22  	req := &hcsschema.ModifySettingRequest{
    23  		ResourcePath: resourcepaths.MemoryResourcePath,
    24  		Settings:     actual,
    25  	}
    26  	return uvm.modify(ctx, req)
    27  }
    28  
    29  // GetAssignedMemoryInBytes returns the amount of assigned memory for the UVM in bytes
    30  func (uvm *UtilityVM) GetAssignedMemoryInBytes(ctx context.Context) (uint64, error) {
    31  	props, err := uvm.hcsSystem.PropertiesV2(ctx, hcsschema.PTMemory)
    32  	if err != nil {
    33  		return 0, err
    34  	}
    35  	if props.Memory == nil {
    36  		return 0, fmt.Errorf("no memory properties returned for system %s", uvm.id)
    37  	}
    38  	if props.Memory.VirtualMachineMemory == nil {
    39  		return 0, fmt.Errorf("no virtual memory properties returned for system %s", uvm.id)
    40  	}
    41  	pages := props.Memory.VirtualMachineMemory.AssignedMemory
    42  	if pages == 0 {
    43  		return 0, fmt.Errorf("assigned memory returned should not be 0 for system %s", uvm.id)
    44  	}
    45  	memInBytes := pages * bytesPerPage
    46  	return memInBytes, nil
    47  }
    48  

View as plain text