Get accuracy memory and cpu limits inside container
Opened this issue · 0 comments
0xyjk commented
Context
- current implementation for get memory limits:
zkevm-prover/src/utils/utils.cpp
Line 61 in 94f5662
- current implementation for get cpu limits:
zkevm-prover/src/utils/utils.cpp
Line 425 in 94f5662
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()