Skip to content

Get accuracy memory and cpu limits inside container #817

@0xyjk

Description

@0xyjk

Context

Problems

if program running in a docker container with cgroup limits, the way to get CPU/Memory limits is not accuracy which potentially will cause OOM

Solution

Get Memory Limit

try get memory limit from /sys/fs/cgroup/memory/memory.limit_in_bytes, if the value is 0 or large than /proc/meminfo, fallback to use the mem info inside /proc/meminfo

Get CPU Limit

try to caculate CPU Core number from /sys/fs/cgroup/cpu/cpu.cfs_quota_us Div /sys/fs/cgroup/cpu/cpu.cfs_period_us, if it's not a valid number, then fallback to omp_get_num_procs()

Refs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions