Determine whether cgroups limit the available memory
Create Dockerfile
for test
FROM ubuntu:16.04
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
rm -rf /var/lib/apt/list/*
CMD ["/bin/bash" ]
Run with memory constraint:
docker run -it -m 521m --name=java8 j8
$ free -h
total used free shared buff/cache available
Mem: 1.9G 161M 950M 153M 868M 1.4G
Swap: 3.8G 0B 3.8G
$ java -XX:+PrintFlagsFinal -version | grep -i heapsize | egrep ' Initial|Max'
openjdk version " 1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
uintx InitialHeapSize := 33554432 {product}
uintx MaxHeapSize := 520093696 {product}
Run with other memory constraint:
docker rm j8
docker run -it -m 1024m --name=java8 j8
$ free -h
total used free shared buff/cache available
Mem: 1.9G 162M 949M 153M 867M 1.4G
Swap: 3.8G 0B 3.8G
$ java -XX:+PrintFlagsFinal -version | grep -i heapsize | egrep ' Initial|Max'
openjdk version " 1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
uintx InitialHeapSize := 33554432 {product}
uintx MaxHeapSize := 520093696 {product}