diff --git a/pkg/gpumgr/process.go b/pkg/gpumgr/process.go index 2b52a52..ab8ad55 100644 --- a/pkg/gpumgr/process.go +++ b/pkg/gpumgr/process.go @@ -5,6 +5,7 @@ import ( "github.com/shirou/gopsutil/v3/process" log "github.com/sirupsen/logrus" "path/filepath" + "regexp" ) type GpuProcess struct { @@ -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 @@ -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-.scope" + // CRIO runtime container cgroup name is "crio-.scope" + // Containerd runtime container cgroup name is just "" + scopeContainerMatch := scopeContainerCgroupRe.FindStringSubmatch(p.ContainerId) + for _, scopeContainerId := range scopeContainerMatch { + p.ContainerId = scopeContainerId + } goto ExitContainerIdSet } }