Repository navigation
Description
Description of problem:
When running containers without memory limits, the memory cgroup file that stores the memory limit has an invalid value. See the following steps to reproduce for details:
$ docker run -d redis
08bd1b1ef7667906112e5bafe6fe8125ee6fd983ce2f411aa5e55d215db03835
$ docker inspect -f '{{.HostConfig.Memory}}' 08bd1b1ef766
0 # This is expectedThe redis container has no memory constraints, so it should be able to use all host memory. However, the memory cgroup for the container shows an invalid value, far bigger than the actual total memory in the host.
$ grep Mem /proc/meminfo
MemTotal: 4035420 kB # Total host memory. Expected to match the cgroup limit
MemFree: 297544 kB
$ cat /sys/fs/cgroup/memory/docker/08bd1b1ef7667906112e5bafe6fe8125ee6fd983ce2f411aa5e55d215db03835/memory.limit_in_bytes
18446744073709551615 # This is 17179869183 GB memory, which is obviously wrongWhen running containers with memory constraints, the memory limit cgroup file has the right value.
docker version:
Client:
Version: 1.9.0
API version: 1.21
Go version: go1.4.2
Git commit: 76d6bc9
Built: Tue Nov 3 17:43:42 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.0
API version: 1.21
Go version: go1.4.2
Git commit: 76d6bc9
Built: Tue Nov 3 17:43:42 UTC 2015
OS/Arch: linux/amd64
docker info:
Containers: 3
Images: 65
Server Version: 1.9.0
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 71
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-67-generic
Operating System: Ubuntu 14.04.3 LTS
CPUs: 8
Total Memory: 3.848 GiB
Name: thunder04
ID: IXHS:LGA5:GUVS:3MFH:7FQ3:CKCL:GB5C:6JGU:YKDO:YOCN:B6KI:2MLX
WARNING: No swap limit support
uname -a:
Linux thunder04 3.13.0-67-generic #110-Ubuntu SMP Fri Oct 23 13:24:41 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Environment details (AWS, VirtualBox, physical, etc.):
Physical host. Detailed hardware information available here.
Activity
phemmer commentedon Nov 19, 2015
Why is this a problem?
This is the the value of
memory.limit_in_byteswith or without docker when there is no limit in place. (look atcat /sys/fs/cgroup/memory/memory.limit_in_byteson the host).The value 18446744073709551615 is the maximum 64-bit int, so it is a valid limit.
nacx commentedon Nov 19, 2015
Thanks for the quick response. I understand your point, but IMO it is not consistent with what the documentation says. The container will indirectly be restricted to the max available memory in the host, but just because the limit is set to an upper bound.
This is also inconvenient in monitoring systems and tools that exploit the container stats through the remote api. Tracing the memory limits and consumption for a container using the stats api would report inconsistent values when compared to the values obtained using the "/info" endpoint to get the host limits (there is no host stats api).
phemmer commentedon Nov 19, 2015
What documentation are you referring to?
I don't follow. Neither the stats api, nor
/infohave any relation to (and do not display) the cgroupmemory.limit_in_bytesparameter. So why ismemory.limit_in_bytesbeing set to the max an issue?nacx commentedon Nov 19, 2015
I found this issue when these value caused an overflow in the monitoring system I'm developing. While digging into it to find the source of the issue, I eventually found the value in the
memory.limit_in_bytesfile, so I opened the issue.I'm using only the Docker remote api, and looking into it with more detail I see now that the value that caused the overflow is the
hierarchical_memory_limitin thememory.stats(see the output below). So the Docker stats api is returning the right value for the memory limit. Apologies if my previous comment caused confusion but was made based on the path I followed to find the root cause of my issue.This said, I don't know if Docker is the one who writes the stats and memory limits files, but the advice seems to be to not read directly those values as the real limits that are being applied. When it comes to build some graphics and report stats, it is safer to fallback to the host info when the container's HostConfig.Memory is 0, as the one reported in the stats and limits file can be different than the actual host physical limits.
I understand this might not be a bug of Docker itself (given it doesn't really manage those cgroup files), but it is still quite inconvenient.
crosbymichael commentedon Nov 20, 2015
@nacx the kernel writes that value. It can be the max or it will inherit the limit from the cgroup before it in a hierarchy so reporting it is correct. Your monitoring tool will just have to be smarter to account for this type of thing. Everything else is correct on the docker and kernel side.