...
1
16
17 package state
18
19 import (
20 v1 "k8s.io/api/core/v1"
21 )
22
23
24 type MemoryTable struct {
25 TotalMemSize uint64 `json:"total"`
26 SystemReserved uint64 `json:"systemReserved"`
27 Allocatable uint64 `json:"allocatable"`
28 Reserved uint64 `json:"reserved"`
29 Free uint64 `json:"free"`
30 }
31
32
33 type NUMANodeState struct {
34
35
36 NumberOfAssignments int `json:"numberOfAssignments"`
37
38 MemoryMap map[v1.ResourceName]*MemoryTable `json:"memoryMap"`
39
40
41
42
43 Cells []int `json:"cells"`
44 }
45
46
47 type NUMANodeMap map[int]*NUMANodeState
48
49
50 func (nm NUMANodeMap) Clone() NUMANodeMap {
51 clone := make(NUMANodeMap)
52 for node, s := range nm {
53 if s == nil {
54 clone[node] = nil
55 continue
56 }
57
58 clone[node] = &NUMANodeState{}
59 clone[node].NumberOfAssignments = s.NumberOfAssignments
60 clone[node].Cells = append([]int{}, s.Cells...)
61
62 if s.MemoryMap == nil {
63 continue
64 }
65
66 clone[node].MemoryMap = map[v1.ResourceName]*MemoryTable{}
67 for memoryType, memoryTable := range s.MemoryMap {
68 clone[node].MemoryMap[memoryType] = &MemoryTable{
69 Allocatable: memoryTable.Allocatable,
70 Free: memoryTable.Free,
71 Reserved: memoryTable.Reserved,
72 SystemReserved: memoryTable.SystemReserved,
73 TotalMemSize: memoryTable.TotalMemSize,
74 }
75 }
76 }
77 return clone
78 }
79
80
81 type Block struct {
82
83 NUMAAffinity []int `json:"numaAffinity"`
84 Type v1.ResourceName `json:"type"`
85 Size uint64 `json:"size"`
86 }
87
88
89 type ContainerMemoryAssignments map[string]map[string][]Block
90
91
92 func (as ContainerMemoryAssignments) Clone() ContainerMemoryAssignments {
93 clone := make(ContainerMemoryAssignments)
94 for pod := range as {
95 clone[pod] = make(map[string][]Block)
96 for container, blocks := range as[pod] {
97 clone[pod][container] = append([]Block{}, blocks...)
98 }
99 }
100 return clone
101 }
102
103
104 type Reader interface {
105
106 GetMachineState() NUMANodeMap
107
108 GetMemoryBlocks(podUID string, containerName string) []Block
109
110 GetMemoryAssignments() ContainerMemoryAssignments
111 }
112
113 type writer interface {
114
115 SetMachineState(memoryMap NUMANodeMap)
116
117 SetMemoryBlocks(podUID string, containerName string, blocks []Block)
118
119 SetMemoryAssignments(assignments ContainerMemoryAssignments)
120
121 Delete(podUID string, containerName string)
122
123 ClearState()
124 }
125
126
127 type State interface {
128 Reader
129 writer
130 }
131
View as plain text