MCPcopy Create free account
hub / github.com/containerd/cgroups / hugePageSizes

Function hugePageSizes

cgroup2/utils.go:472–491  ·  view source on GitHub ↗

The following idea and implementation is taken pretty much line for line from runc. Because the hugetlb files are well known, and the only variable thrown in the mix is what huge page sizes you have on your host, this lends itself well to doing the work to find the files present once, and then re-us

()

Source from the content-addressed store, hash-verified

470// call.
471// https://github.com/opencontainers/runc/blob/3a2c0c2565644d8a7e0f1dd594a060b21fa96cf1/libcontainer/cgroups/utils.go#L301
472func hugePageSizes() []string {
473 initHPSOnce.Do(func() {
474 dir, err := os.OpenFile("/sys/kernel/mm/hugepages", unix.O_DIRECTORY|unix.O_RDONLY, 0)
475 if err != nil {
476 return
477 }
478 defer dir.Close()
479 files, err := dir.Readdirnames(0)
480 if err != nil {
481 return
482 }
483
484 hPageSizes, err = getHugePageSizeFromFilenames(files)
485 if err != nil {
486 log.L.Warnf("hugePageSizes: %s", err)
487 }
488 })
489
490 return hPageSizes
491}
492
493func getHugePageSizeFromFilenames(fileNames []string) ([]string, error) {
494 pageSizes := make([]string, 0, len(fileNames))

Callers 1

readHugeTlbStatsFunction · 0.70

Calls 1

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…