diff --git a/openjdk/openjdk.mk b/openjdk/openjdk.mk index cf4323dc75..499529875f 100644 --- a/openjdk/openjdk.mk +++ b/openjdk/openjdk.mk @@ -20,7 +20,37 @@ ARCH:=$(shell uname -m) ifeq ($(OS),Linux) NPROCS:=$(shell nproc) - MEMORY_SIZE:=$(shell KMEMMB=`awk '/^MemTotal:/{print int($$2/1024)}' /proc/meminfo`; if [ -r /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then CGMEM=`cat /sys/fs/cgroup/memory/memory.limit_in_bytes`; else CGMEM=`expr $${KMEMMB} \* 1024`; fi; CGMEMMB=`expr $${CGMEM} / 1024`; if [ "$${KMEMMB}" -lt "$${CGMEMMB}" ]; then echo "$${KMEMMB}"; else echo "$${CGMEMMB}"; fi) + # This is the MEMORY_SIZE script below, with formatting for readability. + # + # // The number of megabytes of memory this machine has. + # KMEMMB=`awk '/^MemTotal:/{print int($$2/1024)}' /proc/meminfo`; + # + # // If this machine/container uses cgroups to limit the amount of + # // memory available to us, we should use that as out memory size. + # if [[ -r /sys/fs/cgroup/memory.max ]]; then + # // Use this to identify memory maximum (bytes) for cgroup v2. + # CGMEM=`cat /sys/fs/cgroup/memory.max 2>1`; + # else + # // Else use this file for memory maximum (bytes) on cgroup v1. + # CGMEM=`cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>1`; + # fi; + # + # // If those files were empty, or didn't exist, or had non-numbers + # // in them, then use /proc/meminfo (converted to bytes). + # if [[ ! $$(CGMEM) =~ ^[0-9]+$$ ]]; then + # CGMEM=`expr $${KMEMMB} \* 1024 \* 1024`; + # fi; + # + # CGMEMMB=`expr $${CGMEM} / 1024 / 1024`; + # + # // Between memory limits in the cgroup and memory on the machine, + # // use the lower limit. This protects us against situations + # // where the cgroup has a value which is much bigger/smaller than + # // the limits on the machine overall. We've seen both. + # if [ "$${KMEMMB}" -lt "$${CGMEMMB}" ]; then + # echo "$${KMEMMB}"; else echo "$${CGMEMMB}"; + # fi + MEMORY_SIZE:=$(shell KMEMMB=`awk '/^MemTotal:/{print int($$2/1024)}' /proc/meminfo`; if [[ -r /sys/fs/cgroup/memory.max ]]; then CGMEM=`cat /sys/fs/cgroup/memory.max 2>1`; else CGMEM=`cat /sys/fs/cgroup/memory/memory.limit_in_bytes 2>1`; fi; if [[ ! $${CGMEM} =~ ^[0-9]+$$ ]]; then CGMEM=`expr $${KMEMMB} \* 1024 \* 1024`; fi; CGMEMMB=`expr $${CGMEM} / 1024 / 1024`; if [ "$${KMEMMB}" -lt "$${CGMEMMB}" ]; then echo "$${KMEMMB}"; else echo "$${CGMEMMB}"; fi) endif ifeq ($(OS),Darwin) NPROCS:=$(shell sysctl -n hw.ncpu)