memory manager: rename state structs and fields

The commit rename state structs and some fields under these structs.

- NodeMap -> NUMANodeMap
- NodeState -> NUMANodeState
- NUMANodeState.Nodes -> NUMANodesState.Cells

Signed-off-by: Artyom Lukianov <alukiano@redhat.com>
This commit is contained in:
Artyom Lukianov 2020-11-04 14:28:04 +02:00
parent aa63e5aed2
commit a015e4163f
8 changed files with 331 additions and 331 deletions

View File

@ -48,8 +48,8 @@ type testMemoryManager struct {
machineInfo cadvisorapi.MachineInfo
assignments state.ContainerMemoryAssignments
expectedAssignments state.ContainerMemoryAssignments
machineState state.NodeMap
expectedMachineState state.NodeMap
machineState state.NUMANodeMap
expectedMachineState state.NUMANodeMap
expectedError error
expectedAllocateError error
expectedAddContainerError error
@ -461,9 +461,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -482,8 +482,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -503,9 +503,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -524,8 +524,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -587,9 +587,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -608,8 +608,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -629,9 +629,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -650,8 +650,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -713,9 +713,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0, 1},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -734,8 +734,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{0, 1},
1: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -755,9 +755,9 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -776,8 +776,8 @@ func TestRemoveStaleState(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -846,9 +846,9 @@ func TestAddContainer(t *testing.T) {
policyName: policyTypeStatic,
machineInfo: machineInfo,
reserved: reserved,
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -867,8 +867,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -888,9 +888,9 @@ func TestAddContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -909,8 +909,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -943,8 +943,8 @@ func TestAddContainer(t *testing.T) {
policyName: policyTypeNone,
machineInfo: machineInfo,
reserved: reserved,
machineState: state.NodeMap{},
expectedMachineState: state.NodeMap{},
machineState: state.NUMANodeMap{},
expectedMachineState: state.NUMANodeMap{},
expectedAllocateError: nil,
expectedAddContainerError: nil,
podAllocate: pod,
@ -957,9 +957,9 @@ func TestAddContainer(t *testing.T) {
policyName: policyTypeMock,
machineInfo: machineInfo,
reserved: reserved,
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -978,8 +978,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -999,9 +999,9 @@ func TestAddContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1020,8 +1020,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1053,9 +1053,9 @@ func TestAddContainer(t *testing.T) {
policyName: policyTypeStatic,
machineInfo: machineInfo,
reserved: reserved,
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1074,8 +1074,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1095,9 +1095,9 @@ func TestAddContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1116,8 +1116,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1148,9 +1148,9 @@ func TestAddContainer(t *testing.T) {
policyName: policyTypeStatic,
machineInfo: machineInfo,
reserved: reserved,
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1169,8 +1169,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1190,9 +1190,9 @@ func TestAddContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0, 1},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1211,8 +1211,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{0, 1},
1: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1255,9 +1255,9 @@ func TestAddContainer(t *testing.T) {
machineInfo: machineInfo,
firstPod: pod,
reserved: reserved,
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1276,8 +1276,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1313,9 +1313,9 @@ func TestAddContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1334,8 +1334,8 @@ func TestAddContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1488,9 +1488,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1509,8 +1509,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1530,9 +1530,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1551,8 +1551,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1624,9 +1624,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0, 1},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1645,8 +1645,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{0, 1},
1: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1666,9 +1666,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0, 1},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1687,8 +1687,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{0, 1},
1: &state.NUMANodeState{
Cells: []int{0, 1},
NumberOfAssignments: 2,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1772,9 +1772,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1793,8 +1793,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1814,9 +1814,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1835,8 +1835,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1920,9 +1920,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1941,8 +1941,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1962,9 +1962,9 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -1983,8 +1983,8 @@ func TestRemoveContainer(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -2193,9 +2193,9 @@ func TestGetTopologyHints(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
Nodes: []int{0},
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
Cells: []int{0},
NumberOfAssignments: 4,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
@ -2214,8 +2214,8 @@ func TestGetTopologyHints(t *testing.T) {
},
},
},
1: &state.NodeState{
Nodes: []int{1},
1: &state.NUMANodeState{
Cells: []int{1},
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {

View File

@ -37,7 +37,7 @@ const policyTypeStatic policyType = "static"
type systemReservedMemory map[int]map[v1.ResourceName]uint64
// SingleNUMAPolicy is implementation of the policy interface for the single NUMA policy
// staticPolicy is implementation of the policy interface for the static policy
type staticPolicy struct {
// machineInfo contains machine memory related information
machineInfo *cadvisorapi.MachineInfo
@ -49,7 +49,7 @@ type staticPolicy struct {
var _ Policy = &staticPolicy{}
// NewPolicyStatic returns new single NUMA policy instance
// NewPolicyStatic returns new static policy instance
func NewPolicyStatic(machineInfo *cadvisorapi.MachineInfo, reserved systemReservedMemory, affinity topologymanager.Store) (Policy, error) {
var totalSystemReserved uint64
for _, node := range reserved {
@ -149,7 +149,7 @@ func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Contai
// Update nodes memory state
for _, nodeID := range maskBits {
machineState[nodeID].NumberOfAssignments++
machineState[nodeID].Nodes = maskBits
machineState[nodeID].Cells = maskBits
// we need to continue to update all affinity mask nodes
if requestedSize == 0 {
@ -202,7 +202,7 @@ func (p *staticPolicy) RemoveContainer(s state.State, podUID string, containerNa
// once we do not have any memory allocations on this node, clear node groups
if machineState[nodeID].NumberOfAssignments == 0 {
machineState[nodeID].Nodes = []int{nodeID}
machineState[nodeID].Cells = []int{nodeID}
}
// we still need to pass over all NUMA node under the affinity mask to update them
@ -390,7 +390,7 @@ func (p *staticPolicy) calculateHints(s state.State, requestedResources map[v1.R
}
sort.Ints(numaNodes)
// Initialize minAffinitySize to include all NUMA Nodes.
// Initialize minAffinitySize to include all NUMA Cells.
minAffinitySize := len(numaNodes)
hints := map[string][]topologymanager.TopologyHint{}
@ -399,7 +399,7 @@ func (p *staticPolicy) calculateHints(s state.State, requestedResources map[v1.R
singleNUMAHint := len(maskBits) == 1
// the node already in group with another node, it can not be used for the single NUMA node allocation
if singleNUMAHint && len(machineState[maskBits[0]].Nodes) > 1 {
if singleNUMAHint && len(machineState[maskBits[0]].Cells) > 1 {
return
}
@ -410,12 +410,12 @@ func (p *staticPolicy) calculateHints(s state.State, requestedResources map[v1.R
// the node already used for the memory allocation
if !singleNUMAHint && machineState[nodeID].NumberOfAssignments > 0 {
// the node used for the single NUMA memory allocation, it can not be used for the multi NUMA node allocation
if len(machineState[nodeID].Nodes) == 1 {
if len(machineState[nodeID].Cells) == 1 {
return
}
// the node already used with different group of nodes, it can not be use with in the current hint
if !areGroupsEqual(machineState[nodeID].Nodes, maskBits) {
if !areGroupsEqual(machineState[nodeID].Cells, maskBits) {
return
}
}
@ -524,7 +524,7 @@ func (p *staticPolicy) validateState(s state.State) error {
}
nodeState.NumberOfAssignments++
nodeState.Nodes = b.NUMAAffinity
nodeState.Cells = b.NUMAAffinity
memoryState, ok := nodeState.MemoryMap[b.Type]
if !ok {
@ -568,7 +568,7 @@ func (p *staticPolicy) validateState(s state.State) error {
return nil
}
func areMachineStatesEqual(ms1, ms2 state.NodeMap) bool {
func areMachineStatesEqual(ms1, ms2 state.NUMANodeMap) bool {
if len(ms1) != len(ms2) {
klog.Errorf("[memorymanager] node states are different len(ms1) != len(ms2): %d != %d", len(ms1), len(ms2))
return false
@ -586,8 +586,8 @@ func areMachineStatesEqual(ms1, ms2 state.NodeMap) bool {
return false
}
if !areGroupsEqual(nodeState1.Nodes, nodeState2.Nodes) {
klog.Errorf("[memorymanager] node states groups are different: %v != %v", nodeState1.Nodes, nodeState2.Nodes)
if !areGroupsEqual(nodeState1.Cells, nodeState2.Cells) {
klog.Errorf("[memorymanager] node states groups are different: %v != %v", nodeState1.Cells, nodeState2.Cells)
return false
}
@ -612,14 +612,14 @@ func areMachineStatesEqual(ms1, ms2 state.NodeMap) bool {
return true
}
func (p *staticPolicy) getDefaultMachineState() state.NodeMap {
defaultMachineState := state.NodeMap{}
func (p *staticPolicy) getDefaultMachineState() state.NUMANodeMap {
defaultMachineState := state.NUMANodeMap{}
nodeHugepages := map[int]uint64{}
for _, node := range p.machineInfo.Topology {
defaultMachineState[node.Id] = &state.NodeState{
defaultMachineState[node.Id] = &state.NUMANodeState{
NumberOfAssignments: 0,
MemoryMap: map[v1.ResourceName]*state.MemoryTable{},
Nodes: []int{node.Id},
Cells: []int{node.Id},
}
// fill memory table with huge pages values
@ -681,7 +681,7 @@ func (p *staticPolicy) getDefaultHint(s state.State, requestedResources map[v1.R
return findBestHint(hints[string(v1.ResourceMemory)]), nil
}
func isAffinitySatisfyRequest(machineState state.NodeMap, mask bitmask.BitMask, requestedResources map[v1.ResourceName]uint64) bool {
func isAffinitySatisfyRequest(machineState state.NUMANodeMap, mask bitmask.BitMask, requestedResources map[v1.ResourceName]uint64) bool {
totalFreeSize := map[v1.ResourceName]uint64{}
for _, nodeID := range mask.GetBits() {
for resourceName := range requestedResources {

View File

@ -119,8 +119,8 @@ type testStaticPolicy struct {
description string
assignments state.ContainerMemoryAssignments
expectedAssignments state.ContainerMemoryAssignments
machineState state.NodeMap
expectedMachineState state.NodeMap
machineState state.NUMANodeMap
expectedMachineState state.NUMANodeMap
systemReserved systemReservedMemory
expectedError error
machineInfo *cadvisorapi.MachineInfo
@ -229,8 +229,8 @@ func TestStaticPolicyStart(t *testing.T) {
{
description: "should fill the state with default values, when the state is empty",
expectedAssignments: state.ContainerMemoryAssignments{},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -248,7 +248,7 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
NumberOfAssignments: 0,
Nodes: []int{0},
Cells: []int{0},
},
},
systemReserved: systemReservedMemory{
@ -274,8 +274,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state does not have all NUMA nodes",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -292,7 +292,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -331,8 +331,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state does not have memory resource",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
hugepages1Gi: {
Allocatable: gb,
@ -342,7 +342,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -370,8 +370,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state has wrong size of total memory",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -381,7 +381,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: 1536 * mb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -409,8 +409,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state has wrong size of system reserved memory",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -420,7 +420,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: 2 * gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -459,8 +459,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -470,7 +470,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: 2 * gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 1,
},
},
@ -498,8 +498,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state has wrong size of hugepages",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -516,7 +516,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -544,8 +544,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
{
description: "should fail when machine state has wrong size of system reserved hugepages",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -562,7 +562,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: 2 * gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -610,8 +610,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -628,7 +628,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: 4 * gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 2,
},
},
@ -667,8 +667,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -685,7 +685,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -729,8 +729,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -747,7 +747,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 2,
},
},
@ -791,8 +791,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -809,7 +809,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 1,
},
},
@ -897,8 +897,8 @@ func TestStaticPolicyStart(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 640 * mb,
@ -915,10 +915,10 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 4,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 640 * mb,
@ -935,12 +935,12 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 4,
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 640 * mb,
@ -957,10 +957,10 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 4,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 640 * mb,
@ -977,7 +977,7 @@ func TestStaticPolicyStart(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 4,
},
},
@ -1053,8 +1053,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
{
description: "should do nothing for non-guaranteed pods",
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1071,11 +1071,11 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1092,7 +1092,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
systemReserved: systemReservedMemory{
@ -1128,8 +1128,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1146,11 +1146,11 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1167,7 +1167,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
systemReserved: systemReservedMemory{
@ -1198,8 +1198,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1216,11 +1216,11 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1237,7 +1237,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 2,
},
},
@ -1267,8 +1267,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1285,7 +1285,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 2,
},
},
@ -1311,8 +1311,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: gb,
@ -1329,10 +1329,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 1,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1349,10 +1349,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{1},
Cells: []int{1},
NumberOfAssignments: 0,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1369,7 +1369,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{2},
Cells: []int{2},
NumberOfAssignments: 0,
},
},
@ -1390,8 +1390,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
{
description: "should fail when NUMA affinity provided under the topology manager hint did not satisfy container requirements and extended hint generation failed",
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1408,10 +1408,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1428,10 +1428,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{1, 2},
Cells: []int{1, 2},
NumberOfAssignments: 1,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1448,7 +1448,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{1, 2},
Cells: []int{1, 2},
NumberOfAssignments: 1,
},
},
@ -1480,8 +1480,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: gb,
@ -1498,10 +1498,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 1,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1518,10 +1518,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{1},
Cells: []int{1},
NumberOfAssignments: 0,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1538,7 +1538,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{2},
Cells: []int{2},
NumberOfAssignments: 0,
},
},
@ -1576,8 +1576,8 @@ func TestStaticPolicyAllocate(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1594,10 +1594,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1614,10 +1614,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{1},
Cells: []int{1},
NumberOfAssignments: 0,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1634,10 +1634,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{2},
Cells: []int{2},
NumberOfAssignments: 0,
},
3: &state.NodeState{
3: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1654,12 +1654,12 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{3},
Cells: []int{3},
NumberOfAssignments: 0,
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1676,10 +1676,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 2,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1696,10 +1696,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 2,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1716,10 +1716,10 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{2},
Cells: []int{2},
NumberOfAssignments: 0,
},
3: &state.NodeState{
3: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1736,7 +1736,7 @@ func TestStaticPolicyAllocate(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{3},
Cells: []int{3},
NumberOfAssignments: 0,
},
},
@ -1794,8 +1794,8 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
{
description: "should do nothing when the container does not exist under the state",
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1812,11 +1812,11 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1833,7 +1833,7 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{},
Cells: []int{},
},
},
systemReserved: systemReservedMemory{
@ -1861,8 +1861,8 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1880,11 +1880,11 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
NumberOfAssignments: 2,
Nodes: []int{0},
Cells: []int{0},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -1901,7 +1901,7 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0},
Cells: []int{0},
NumberOfAssignments: 0,
},
},
@ -1930,8 +1930,8 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
expectedAssignments: state.ContainerMemoryAssignments{},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1949,9 +1949,9 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
NumberOfAssignments: 2,
Nodes: []int{0, 1},
Cells: []int{0, 1},
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1969,11 +1969,11 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
NumberOfAssignments: 2,
Nodes: []int{0, 1},
Cells: []int{0, 1},
},
},
expectedMachineState: state.NodeMap{
0: &state.NodeState{
expectedMachineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -1991,9 +1991,9 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
NumberOfAssignments: 0,
Nodes: []int{0},
Cells: []int{0},
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 512 * mb,
@ -2011,7 +2011,7 @@ func TestStaticPolicyRemoveContainer(t *testing.T) {
},
},
NumberOfAssignments: 0,
Nodes: []int{1},
Cells: []int{1},
},
},
systemReserved: systemReservedMemory{
@ -2123,8 +2123,8 @@ func TestStaticPolicyGetTopologyHints(t *testing.T) {
},
},
},
machineState: state.NodeMap{
0: &state.NodeState{
machineState: state.NUMANodeMap{
0: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -2141,10 +2141,10 @@ func TestStaticPolicyGetTopologyHints(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 2,
},
1: &state.NodeState{
1: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -2161,10 +2161,10 @@ func TestStaticPolicyGetTopologyHints(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{0, 1},
Cells: []int{0, 1},
NumberOfAssignments: 2,
},
2: &state.NodeState{
2: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -2181,10 +2181,10 @@ func TestStaticPolicyGetTopologyHints(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{2},
Cells: []int{2},
NumberOfAssignments: 0,
},
3: &state.NodeState{
3: &state.NUMANodeState{
MemoryMap: map[v1.ResourceName]*state.MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536 * mb,
@ -2201,7 +2201,7 @@ func TestStaticPolicyGetTopologyHints(t *testing.T) {
TotalMemSize: gb,
},
},
Nodes: []int{3},
Cells: []int{3},
NumberOfAssignments: 0,
},
},

View File

@ -28,7 +28,7 @@ var _ checkpointmanager.Checkpoint = &MemoryManagerCheckpoint{}
// MemoryManagerCheckpoint struct is used to store memory/pod assignments in a checkpoint
type MemoryManagerCheckpoint struct {
PolicyName string `json:"policyName"`
MachineState NodeMap `json:"machineState"`
MachineState NUMANodeMap `json:"machineState"`
Entries ContainerMemoryAssignments `json:"entries,omitempty"`
Checksum checksum.Checksum `json:"checksum"`
}
@ -38,7 +38,7 @@ func NewMemoryManagerCheckpoint() *MemoryManagerCheckpoint {
//lint:ignore unexported-type-in-api user-facing error message
return &MemoryManagerCheckpoint{
Entries: ContainerMemoryAssignments{},
MachineState: NodeMap{},
MachineState: NUMANodeMap{},
}
}

View File

@ -29,35 +29,35 @@ type MemoryTable struct {
Free uint64 `json:"free"`
}
// NodeState contains NUMA node related information
type NodeState struct {
// NUMANodeState contains NUMA node related information
type NUMANodeState struct {
// NumberOfAssignments contains a number memory assignments from this node
// When the container requires memory and hugepages it will increase number of assignments by two
NumberOfAssignments int `json:"numberOfAssignments"`
// MemoryTable contains NUMA node memory related information
MemoryMap map[v1.ResourceName]*MemoryTable `json:"memoryMap"`
// Nodes contains the current NUMA node and all other nodes that are in a group with current NUMA node
// Cells contains the current NUMA node and all other nodes that are in a group with current NUMA node
// This parameter indicates if the current node is used for the multiple NUMA node memory allocation
// For example if some container has pinning 0,1,2, NUMA nodes 0,1,2 under the state will have
// this parameter equals to [0, 1, 2]
Nodes []int `json:"nodes"`
Cells []int `json:"cells"`
}
// NodeMap contains memory information for each NUMA node.
type NodeMap map[int]*NodeState
// NUMANodeMap contains memory information for each NUMA node.
type NUMANodeMap map[int]*NUMANodeState
// Clone returns a copy of NodeMap
func (nm NodeMap) Clone() NodeMap {
clone := make(NodeMap)
// Clone returns a copy of NUMANodeMap
func (nm NUMANodeMap) Clone() NUMANodeMap {
clone := make(NUMANodeMap)
for node, s := range nm {
if s == nil {
clone[node] = nil
continue
}
clone[node] = &NodeState{}
clone[node] = &NUMANodeState{}
clone[node].NumberOfAssignments = s.NumberOfAssignments
clone[node].Nodes = append([]int{}, s.Nodes...)
clone[node].Cells = append([]int{}, s.Cells...)
if s.MemoryMap == nil {
continue
@ -103,7 +103,7 @@ func (as ContainerMemoryAssignments) Clone() ContainerMemoryAssignments {
// Reader interface used to read current memory/pod assignment state
type Reader interface {
// GetMachineState returns Memory Map stored in the State
GetMachineState() NodeMap
GetMachineState() NUMANodeMap
// GetMemoryBlocks returns memory assignments of a container
GetMemoryBlocks(podUID string, containerName string) []Block
// GetMemoryAssignments returns ContainerMemoryAssignments
@ -111,8 +111,8 @@ type Reader interface {
}
type writer interface {
// SetMachineState stores NodeMap in State
SetMachineState(memoryMap NodeMap)
// SetMachineState stores NUMANodeMap in State
SetMachineState(memoryMap NUMANodeMap)
// SetMemoryBlocks stores memory assignments of a container
SetMemoryBlocks(podUID string, containerName string, blocks []Block)
// SetMemoryAssignments sets ContainerMemoryAssignments by using the passed parameter

View File

@ -103,7 +103,7 @@ func (sc *stateCheckpoint) storeState() error {
}
// GetMemoryState returns Memory Map stored in the State
func (sc *stateCheckpoint) GetMachineState() NodeMap {
func (sc *stateCheckpoint) GetMachineState() NUMANodeMap {
sc.RLock()
defer sc.RUnlock()
@ -126,8 +126,8 @@ func (sc *stateCheckpoint) GetMemoryAssignments() ContainerMemoryAssignments {
return sc.cache.GetMemoryAssignments()
}
// SetMachineState stores NodeMap in State
func (sc *stateCheckpoint) SetMachineState(memoryMap NodeMap) {
// SetMachineState stores NUMANodeMap in State
func (sc *stateCheckpoint) SetMachineState(memoryMap NUMANodeMap) {
sc.Lock()
defer sc.Unlock()

View File

@ -62,9 +62,9 @@ func TestCheckpointStateRestore(t *testing.T) {
"Restore valid checkpoint",
`{
"policyName":"static",
"machineState":{"0":{"numberOfAssignments":0,"memoryMap":{"memory":{"total":2048,"systemReserved":512,"allocatable":1536,"reserved":512,"free":1024}},"nodes":[]}},
"machineState":{"0":{"numberOfAssignments":0,"memoryMap":{"memory":{"total":2048,"systemReserved":512,"allocatable":1536,"reserved":512,"free":1024}},"cells":[]}},
"entries":{"pod":{"container1":[{"numaAffinity":[0],"type":"memory","size":512}]}},
"checksum": 163710462
"checksum": 4215593881
}`,
containermap.ContainerMap{},
"",
@ -80,8 +80,8 @@ func TestCheckpointStateRestore(t *testing.T) {
},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -99,7 +99,7 @@ func TestCheckpointStateRestore(t *testing.T) {
"Restore checkpoint with invalid checksum",
`{
"policyName":"static",
"machineState":{"0":{"numberOfAssignments":0,"memoryMap":{"memory":{"total":2048,"systemReserved":512,"allocatable":1536,"reserved":512,"free":1024}},"nodes":[]}},
"machineState":{"0":{"numberOfAssignments":0,"memoryMap":{"memory":{"total":2048,"systemReserved":512,"allocatable":1536,"reserved":512,"free":1024}},"cells":[]}},
"entries":{"pod":{"container1":[{"affinity":[0],"type":"memory","size":512}]}},
"checksum": 101010
}`,
@ -164,8 +164,8 @@ func TestCheckpointStateStore(t *testing.T) {
},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -208,7 +208,7 @@ func TestCheckpointStateStore(t *testing.T) {
func TestCheckpointStateHelpers(t *testing.T) {
testCases := []struct {
description string
machineState NodeMap
machineState NUMANodeMap
assignments ContainerMemoryAssignments
}{
{
@ -224,8 +224,8 @@ func TestCheckpointStateHelpers(t *testing.T) {
},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -235,7 +235,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
TotalMemSize: 2048,
},
},
Nodes: []int{},
Cells: []int{},
},
},
},
@ -259,8 +259,8 @@ func TestCheckpointStateHelpers(t *testing.T) {
},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -270,7 +270,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
TotalMemSize: 2048,
},
},
Nodes: []int{},
Cells: []int{},
},
},
},
@ -281,8 +281,8 @@ func TestCheckpointStateHelpers(t *testing.T) {
"container1": {},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -292,7 +292,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
TotalMemSize: 2048,
},
},
Nodes: []int{},
Cells: []int{},
},
},
},
@ -335,7 +335,7 @@ func TestCheckpointStateHelpers(t *testing.T) {
func TestCheckpointStateClear(t *testing.T) {
testCases := []struct {
description string
machineState NodeMap
machineState NUMANodeMap
assignments ContainerMemoryAssignments
}{
{
@ -351,8 +351,8 @@ func TestCheckpointStateClear(t *testing.T) {
},
},
},
machineState: NodeMap{
0: &NodeState{
machineState: NUMANodeMap{
0: &NUMANodeState{
MemoryMap: map[v1.ResourceName]*MemoryTable{
v1.ResourceMemory: {
Allocatable: 1536,
@ -383,7 +383,7 @@ func TestCheckpointStateClear(t *testing.T) {
state.SetMemoryAssignments(tc.assignments)
state.ClearState()
assert.Equal(t, NodeMap{}, state.GetMachineState(), "cleared state with non-empty machine state")
assert.Equal(t, NUMANodeMap{}, state.GetMachineState(), "cleared state with non-empty machine state")
assert.Equal(t, ContainerMemoryAssignments{}, state.GetMemoryAssignments(), "cleared state with non-empty memory assignments")
})
}

View File

@ -25,7 +25,7 @@ import (
type stateMemory struct {
sync.RWMutex
assignments ContainerMemoryAssignments
machineState NodeMap
machineState NUMANodeMap
}
var _ State = &stateMemory{}
@ -35,12 +35,12 @@ func NewMemoryState() State {
klog.Infof("[memorymanager] initializing new in-memory state store")
return &stateMemory{
assignments: ContainerMemoryAssignments{},
machineState: NodeMap{},
machineState: NUMANodeMap{},
}
}
// GetMemoryState returns Memory Map stored in the State
func (s *stateMemory) GetMachineState() NodeMap {
func (s *stateMemory) GetMachineState() NUMANodeMap {
s.RLock()
defer s.RUnlock()
@ -66,8 +66,8 @@ func (s *stateMemory) GetMemoryAssignments() ContainerMemoryAssignments {
return s.assignments.Clone()
}
// SetMachineState stores NodeMap in State
func (s *stateMemory) SetMachineState(nodeMap NodeMap) {
// SetMachineState stores NUMANodeMap in State
func (s *stateMemory) SetMachineState(nodeMap NUMANodeMap) {
s.Lock()
defer s.Unlock()
@ -117,7 +117,7 @@ func (s *stateMemory) ClearState() {
s.Lock()
defer s.Unlock()
s.machineState = NodeMap{}
s.machineState = NUMANodeMap{}
s.assignments = make(ContainerMemoryAssignments)
klog.V(2).Infof("[memorymanager] cleared state")
}