Skip to content

Commit

Permalink
better way to extract resource from engine info
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang0 authored and CMGS committed Jun 6, 2023
1 parent b123642 commit b4db160
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions engine/types/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ type Info struct {
NCPU int
MemTotal int64
StorageTotal int64
Resources map[string][]byte
}
1 change: 1 addition & 0 deletions engine/virt/virt.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (v *Virt) Info(ctx context.Context) (*enginetypes.Info, error) {
NCPU: resp.CPU,
MemTotal: resp.Mem,
StorageTotal: resp.Storage,
Resources: resp.Resources,
}, nil
}

Expand Down
17 changes: 16 additions & 1 deletion resource/plugins/cpumem/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,31 @@ func (p Plugin) AddNode(ctx context.Context, nodename string, resource plugintyp
return nil, err
}

if info != nil {
if info != nil { //nolint
// extrace NodeResource from Resources
var nodeRes cpumemtypes.NodeResource
if b, ok := info.Resources[p.Name()]; ok {
if err := json.Unmarshal(b, &nodeRes); err != nil {
return nil, err
}
// NodeResource has higher priority
info.NCPU = int(nodeRes.CPU)
info.MemTotal = nodeRes.Memory
}
if len(req.CPUMap) == 0 {
req.CPUMap = cpumemtypes.CPUMap{}
for i := 0; i < info.NCPU; i++ {
req.CPUMap[strconv.Itoa(i)] = p.config.Scheduler.ShareBase
}
req.NUMA = nodeRes.NUMA
}

if req.Memory == 0 {
req.Memory = info.MemTotal * rate / 10 // use 80% of real memory
req.NUMAMemory = cpumemtypes.NUMAMemory{}
for k, v := range nodeRes.NUMAMemory {
req.NUMAMemory[k] = v * rate / 10
}
}
}

Expand Down

0 comments on commit b4db160

Please sign in to comment.