use Math.sqrt(memory) to set container occupied memory according to system memory size, instead of setting fixed size, more reasonable.
Signed-off-by: Liu Yinsi liuyinsi@163.com --- container/defconfig.rb | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/container/defconfig.rb b/container/defconfig.rb index 05c56db..ef3ab96 100755 --- a/container/defconfig.rb +++ b/container/defconfig.rb @@ -35,3 +35,11 @@ def docker_rm(container)
system "docker stop #{container} && docker rm -f #{container}" end + + +def set_available_memory + memory = `awk '($1 == "MemTotal:"){print $2/1048576}' /proc/meminfo`.to_i + + # set container available memory size, minimum size is 1g, maximum size is 30g, take the middle value according to the system memory size. + [1, 30, Math.sqrt(memory)].sort[1].to_i +end