0xPolygonHermez/zkevm-prover

Get accuracy memory and cpu limits inside container

Opened this issue · 0 comments

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