vendor: github.com/containerd/cgroup/v3 v3.1.2

- hugetlb: correctly parse hugetlb.<size>.events files
- go.mod: github.com/opencontainers/runtime-spec v1.3.0

full diff: https://github.com/containerd/cgroups/compare/v3.1.0...v3.1.2

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-26 18:40:33 +01:00
parent 4b4223a8d4
commit 2c533f9327
6 changed files with 72 additions and 40 deletions

View File

@@ -47,10 +47,11 @@ func (p *pidsController) Create(path string, resources *specs.LinuxResources) er
if err := os.MkdirAll(p.Path(path), defaultDirPerm); err != nil {
return err
}
if resources.Pids != nil && resources.Pids.Limit > 0 {
if resources.Pids != nil && resources.Pids.Limit != nil &&
*resources.Pids.Limit > 0 {
return os.WriteFile(
filepath.Join(p.Path(path), "pids.max"),
[]byte(strconv.FormatInt(resources.Pids.Limit, 10)),
[]byte(strconv.FormatInt(*resources.Pids.Limit, 10)),
defaultFilePerm,
)
}

View File

@@ -85,23 +85,26 @@ func parseRdmaKV(raw string, entry *v1.RdmaEntry) {
var value uint64
var err error
parts := strings.Split(raw, "=")
switch len(parts) {
case 2:
if parts[1] == "max" {
value = math.MaxUint32
} else {
value, err = parseUint(parts[1], 10, 32)
if err != nil {
return
}
}
if parts[0] == "hca_handle" {
entry.HcaHandles = uint32(value)
} else if parts[0] == "hca_object" {
entry.HcaObjects = uint32(value)
k, v, found := strings.Cut(raw, "=")
if !found {
return
}
if v == "max" {
value = math.MaxUint32
} else {
value, err = parseUint(v, 10, 32)
if err != nil {
return
}
}
switch k {
case "hca_handle":
entry.HcaHandles = uint32(value)
case "hca_object":
entry.HcaObjects = uint32(value)
}
}
func toRdmaEntry(strEntries []string) []*v1.RdmaEntry {

View File

@@ -221,9 +221,9 @@ func ToResources(spec *specs.LinuxResources) *Resources {
}
resources.HugeTlb = &hugeTlbUsage
}
if pids := spec.Pids; pids != nil {
if pids := spec.Pids; pids != nil && pids.Limit != nil {
resources.Pids = &Pids{
Max: pids.Limit,
Max: *pids.Limit,
}
}
if i := spec.BlockIO; i != nil {
@@ -293,6 +293,31 @@ func getStatFileContentUint64(filePath string) uint64 {
return res
}
// getKVStatsFileContentUint64 gets uint64 parsed content of key-value cgroup stat file
func getKVStatsFileContentUint64(filePath string, propertyName string) uint64 {
f, err := os.Open(filePath)
if err != nil {
return 0
}
defer f.Close()
s := bufio.NewScanner(f)
for s.Scan() {
name, value, err := parseKV(s.Text())
if name == propertyName {
if err != nil {
log.L.WithError(err).Errorf("unable to parse %q as a uint from Cgroup file %q", propertyName, filePath)
return 0
}
return value
}
}
if err = s.Err(); err != nil {
log.L.WithError(err).Errorf("error reading Cgroup file %q for property %q", filePath, propertyName)
}
return 0
}
func readIoStats(path string) []*stats.IOEntry {
// more details on the io.stat file format: https://www.kernel.org/doc/Documentation/cgroup-v2.txt
var usage []*stats.IOEntry
@@ -362,23 +387,26 @@ func parseRdmaKV(raw string, entry *stats.RdmaEntry) {
var value uint64
var err error
parts := strings.Split(raw, "=")
switch len(parts) {
case 2:
if parts[1] == "max" {
value = math.MaxUint32
} else {
value, err = parseUint(parts[1], 10, 32)
if err != nil {
return
}
}
if parts[0] == "hca_handle" {
entry.HcaHandles = uint32(value)
} else if parts[0] == "hca_object" {
entry.HcaObjects = uint32(value)
k, v, found := strings.Cut(raw, "=")
if !found {
return
}
if v == "max" {
value = math.MaxUint32
} else {
value, err = parseUint(v, 10, 32)
if err != nil {
return
}
}
switch k {
case "hca_handle":
entry.HcaHandles = uint32(value)
case "hca_object":
entry.HcaObjects = uint32(value)
}
}
func toRdmaEntry(strEntries []string) []*stats.RdmaEntry {
@@ -423,7 +451,7 @@ func readHugeTlbStats(path string) []*stats.HugeTlbStat {
Max: getStatFileContentUint64(filepath.Join(path, "hugetlb."+pagesize+".max")),
Current: getStatFileContentUint64(filepath.Join(path, "hugetlb."+pagesize+".current")),
Pagesize: pagesize,
Failcnt: getStatFileContentUint64(filepath.Join(path, "hugetlb."+pagesize+".events")),
Failcnt: getKVStatsFileContentUint64(filepath.Join(path, "hugetlb."+pagesize+".events"), "max"),
}
}
return usage
@@ -447,8 +475,8 @@ func hugePageSizes() []string {
if err != nil {
return
}
defer dir.Close()
files, err := dir.Readdirnames(0)
dir.Close()
if err != nil {
return
}

2
vendor/modules.txt vendored
View File

@@ -353,7 +353,7 @@ github.com/container-storage-interface/spec/lib/go/csi
github.com/containerd/accelerated-container-image/pkg/label
github.com/containerd/accelerated-container-image/pkg/types
github.com/containerd/accelerated-container-image/pkg/utils
# github.com/containerd/cgroups/v3 v3.1.0
# github.com/containerd/cgroups/v3 v3.1.2
## explicit; go 1.22.0
github.com/containerd/cgroups/v3
github.com/containerd/cgroups/v3/cgroup1