@@ -134,6 +134,7 @@ func (p *policy) Start() error {
134
134
p .checkColdstartOff ()
135
135
136
136
p .root .Dump ("<post-start>" )
137
+ p .checkAllocations (" <post-start>" )
137
138
138
139
return nil
139
140
}
@@ -148,19 +149,82 @@ func (p *policy) Sync(add []cache.Container, del []cache.Container) error {
148
149
p .AllocateResources (c )
149
150
}
150
151
152
+ p .checkAllocations (" <post-sync>" )
153
+
151
154
return nil
152
155
}
153
156
157
+ func (p * policy ) checkAllocations (format string , args ... interface {}) {
158
+ var (
159
+ prefix = fmt .Sprintf (format , args ... )
160
+ cpuExcl = 0
161
+ cpuPart = 0
162
+ mem = uint64 (0 )
163
+ ctr = map [string ]Grant {}
164
+ dup = map [string ][]Grant {}
165
+ )
166
+
167
+ getMemorySize := func (g Grant ) uint64 {
168
+ var (
169
+ limit = g .MemLimit ()
170
+ total = uint64 (0 )
171
+ )
172
+ for _ , memType := range []memoryType {memoryDRAM , memoryPMEM , memoryHBM } {
173
+ total += limit [memType ]
174
+ }
175
+ return total
176
+ }
177
+
178
+ for _ , g := range p .allocations .grants {
179
+ log .Debug ("%s %s (%s)" , prefix , g , g .GetContainer ().GetID ())
180
+ full := g .ExclusiveCPUs ().Size ()
181
+ part := g .CPUPortion ()
182
+ cpuExcl += full
183
+ cpuPart += part
184
+
185
+ mem += getMemorySize (g )
186
+
187
+ _ , ok := p .cache .LookupContainer (g .GetContainer ().GetID ())
188
+ if ! ok {
189
+ log .Error ("%s %s STALE container among allocations, not found in cache" , prefix , g )
190
+ }
191
+
192
+ key := g .GetContainer ().PrettyName ()
193
+ old , ok := ctr [key ]
194
+ if ok {
195
+ if len (dup [key ]) == 0 {
196
+ dup [key ] = []Grant {old , g }
197
+ } else {
198
+ dup [key ] = append (dup [key ], g )
199
+ }
200
+ } else {
201
+ ctr [key ] = g
202
+ }
203
+ }
204
+
205
+ for key , grants := range dup {
206
+ log .Error ("%s DUPLICATE allocation entries for container %s" , prefix , key )
207
+ for _ , g := range grants {
208
+ log .Error ("%s %s (%s)" , prefix , g , g .GetContainer ().GetID ())
209
+ }
210
+ }
211
+
212
+ log .Info ("%s total CPU granted: %dm (%d exclusive + %dm shared), total memory granted: %s" ,
213
+ prefix , 1000 * cpuExcl + cpuPart , cpuExcl , cpuPart , prettyMem (mem ))
214
+
215
+ }
216
+
154
217
// AllocateResources is a resource allocation request for this policy.
155
218
func (p * policy ) AllocateResources (container cache.Container ) error {
156
- log .Debug ("allocating resources for %s..." , container .PrettyName ())
219
+ log .Debug ("allocating resources for %s (%s) ..." , container .PrettyName (), container . GetID ())
157
220
158
221
err := p .allocateResources (container , "" )
159
222
if err != nil {
160
223
return err
161
224
}
162
225
163
226
p .root .Dump ("<post-alloc>" )
227
+ p .checkAllocations (" <post-alloc %s>" , container .PrettyName ())
164
228
165
229
return nil
166
230
}
@@ -179,13 +243,14 @@ func (p *policy) allocateResources(container cache.Container, poolHint string) e
179
243
180
244
// ReleaseResources is a resource release request for this policy.
181
245
func (p * policy ) ReleaseResources (container cache.Container ) error {
182
- log .Debug ("releasing resources of %s..." , container .PrettyName ())
246
+ log .Debug ("releasing resources for %s (%s) ..." , container .PrettyName (), container . GetID ())
183
247
184
248
if grant , found := p .releasePool (container ); found {
185
249
p .updateSharedAllocations (& grant )
186
250
}
187
251
188
252
p .root .Dump ("<post-release>" )
253
+ p .checkAllocations (" <post-release %s>" , container .PrettyName ())
189
254
190
255
return nil
191
256
}
@@ -208,6 +273,7 @@ func (p *policy) UpdateResources(container cache.Container) error {
208
273
}
209
274
210
275
p .root .Dump ("<post-update>" )
276
+ p .checkAllocations (" <post-update %s>" , container .PrettyName ())
211
277
212
278
return nil
213
279
}
@@ -394,7 +460,7 @@ func (p *policy) reallocateResources(containers []cache.Container, pools map[str
394
460
p .releasePool (c )
395
461
}
396
462
for _ , c := range containers {
397
- log .Debug ("reallocating resources for %s..." , c .PrettyName ())
463
+ log .Debug ("reallocating resources for %s (%s) ..." , c .PrettyName (), c . GetID ())
398
464
399
465
grant , err := p .allocatePool (c , pools [c .GetID ()])
400
466
if err != nil {
@@ -410,8 +476,6 @@ func (p *policy) reallocateResources(containers []cache.Container, pools map[str
410
476
411
477
p .updateSharedAllocations (nil )
412
478
413
- p .root .Dump ("<post-realloc>" )
414
-
415
479
return nil
416
480
}
417
481
@@ -452,6 +516,7 @@ func (p *policy) Reconfigure(newCfg interface{}) error {
452
516
}
453
517
454
518
p .root .Dump ("<post-config>" )
519
+ p .checkAllocations (" <post-config>" )
455
520
456
521
return nil
457
522
}
0 commit comments