Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/gpumgr/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/shirou/gopsutil/v3/process"
log "github.com/sirupsen/logrus"
"path/filepath"
"regexp"
)

type GpuProcess struct {
Expand All @@ -17,6 +18,8 @@ type GpuProcess struct {
ContainerId string
}

var scopeContainerCgroupRe = regexp.MustCompile(`[^-]+-(.+)\.scope`)

func (p *GpuProcess) SetProcessCmdline() {
if pr, err := process.NewProcess(int32(p.Pid)); err == nil {
var e error
Expand Down Expand Up @@ -66,6 +69,13 @@ func (p *GpuProcess) SetProcessContainerId() {
for _, c := range g.Controllers {
if c == "memory" {
p.ContainerId = filepath.Base(g.Path)
// Docker-based runtime container cgroup name is "docker-<ContainerId>.scope"
// CRIO runtime container cgroup name is "crio-<ContainerId>.scope"
// Containerd runtime container cgroup name is just "<ContainerId>"
scopeContainerMatch := scopeContainerCgroupRe.FindStringSubmatch(p.ContainerId)
for _, scopeContainerId := range scopeContainerMatch {
p.ContainerId = scopeContainerId
}
goto ExitContainerIdSet
}
}
Expand Down