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
()
| 470 | // call. |
| 471 | // https://github.com/opencontainers/runc/blob/3a2c0c2565644d8a7e0f1dd594a060b21fa96cf1/libcontainer/cgroups/utils.go#L301 |
| 472 | func 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 | |
| 493 | func getHugePageSizeFromFilenames(fileNames []string) ([]string, error) { |
| 494 | pageSizes := make([]string, 0, len(fileNames)) |
no test coverage detected
searching dependent graphs…