2024-01-22 09:35:23 +00:00
|
|
|
//go:build linux
|
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package memlimit
|
|
|
|
|
2025-02-03 10:12:35 +00:00
|
|
|
// FromCgroup retrieves the memory limit from the cgroup.
|
2024-01-22 09:35:23 +00:00
|
|
|
func FromCgroup() (uint64, error) {
|
2025-02-03 10:12:35 +00:00
|
|
|
return fromCgroup(detectCgroupVersion)
|
2024-01-22 09:35:23 +00:00
|
|
|
}
|
|
|
|
|
2025-02-03 10:12:35 +00:00
|
|
|
// FromCgroupV1 retrieves the memory limit from the cgroup v1 controller.
|
|
|
|
// After v1.0.0, this function could be removed and FromCgroup should be used instead.
|
2024-01-22 09:35:23 +00:00
|
|
|
func FromCgroupV1() (uint64, error) {
|
2025-02-03 10:12:35 +00:00
|
|
|
return fromCgroup(func(_ []mountInfo) (bool, bool) {
|
|
|
|
return true, false
|
|
|
|
})
|
2024-01-22 09:35:23 +00:00
|
|
|
}
|
|
|
|
|
2025-02-03 10:12:35 +00:00
|
|
|
// FromCgroupHybrid retrieves the memory limit from the cgroup v2 and v1 controller sequentially,
|
|
|
|
// basically, it is equivalent to FromCgroup.
|
|
|
|
// After v1.0.0, this function could be removed and FromCgroup should be used instead.
|
2024-01-22 09:35:23 +00:00
|
|
|
func FromCgroupHybrid() (uint64, error) {
|
2025-02-03 10:12:35 +00:00
|
|
|
return FromCgroup()
|
2024-01-22 09:35:23 +00:00
|
|
|
}
|
|
|
|
|
2025-02-03 10:12:35 +00:00
|
|
|
// FromCgroupV2 retrieves the memory limit from the cgroup v2 controller.
|
|
|
|
// After v1.0.0, this function could be removed and FromCgroup should be used instead.
|
2024-01-22 09:35:23 +00:00
|
|
|
func FromCgroupV2() (uint64, error) {
|
2025-02-03 10:12:35 +00:00
|
|
|
return fromCgroup(func(_ []mountInfo) (bool, bool) {
|
|
|
|
return false, true
|
|
|
|
})
|
2024-01-22 09:35:23 +00:00
|
|
|
}
|