Skip to content

Invalid memory limit in container cgroup file #18087

Closed

Description

@nacx

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 expected

The 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 wrong

When 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

  1. phemmer commented on Nov 19, 2015

    @phemmer
    Contributor

    Why is this a problem?
    This is the the value of memory.limit_in_bytes with or without docker when there is no limit in place. (look at cat /sys/fs/cgroup/memory/memory.limit_in_bytes on the host).
    The value 18446744073709551615 is the maximum 64-bit int, so it is a valid limit.

  2. nacx commented on Nov 19, 2015

    @nacx
    Author

    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).

  3. phemmer commented on Nov 19, 2015

    @phemmer
    Contributor

    it is not consistent with what the documentation says.

    What documentation are you referring to?

    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

    I don't follow. Neither the stats api, nor /info have any relation to (and do not display) the cgroup memory.limit_in_bytes parameter. So why is memory.limit_in_bytes being set to the max an issue?

  4. nacx commented on Nov 19, 2015

    @nacx
    Author

    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_bytes file, 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_limit in the memory.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.

    root@thunder04:~# docker run -d redis
    cf7bbe2a26fa095dcac42ca75c8ea633735ba207945b9070ea8444c0ae0fa35f
    
    root@thunder04:~# nc -U /var/run/docker.sock 
    GET /containers/cf7bbe2a26fa/stats?stream=false HTTP/1.1
    
    HTTP/1.1 200 OK
    Content-Type: application/json
    Server: Docker/1.9.0 (linux)
    Date: Thu, 19 Nov 2015 14:33:10 GMT
    Content-Length: 1695
    
    {"read":"2015-11-19T14:33:10.785571441Z","precpu_stats":{"cpu_usage":{"total_usage":199362378,"percpu_usage":[3545487,80691088,60341141,14080771,31770965,2375061,6557865,0],"usage_in_kernelmode":90000000,"usage_in_usermode":110000000},"system_cpu_usage":6843803900000000,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"cpu_stats":{"cpu_usage":{"total_usage":200150282,"percpu_usage":[4333391,80691088,60341141,14080771,31770965,2375061,6557865,0],"usage_in_kernelmode":90000000,"usage_in_usermode":110000000},"system_cpu_usage":6843811890000000,"throttling_data":{"periods":0,"throttled_periods":0,"throttled_time":0}},"memory_stats":{"usage":6946816,"max_usage":6959104,"stats":{"active_anon":6598656,"active_file":0,"cache":12288,"hierarchical_memory_limit":18446744073709551615,"inactive_anon":0,"inactive_file":0,"mapped_file":0,"pgfault":4241,"pgmajfault":0,"pgpgin":1806,"pgpgout":1728,"rss":6586368,"rss_huge":6291456,"total_active_anon":6598656,"total_active_file":0,"total_cache":12288,"total_inactive_anon":0,"total_inactive_file":0,"total_mapped_file":0,"total_pgfault":4241,"total_pgmajfault":0,"total_pgpgin":1806,"total_pgpgout":1728,"total_rss":6586368,"total_rss_huge":6291456,"total_unevictable":0,"total_writeback":0,"unevictable":0,"writeback":0},"failcnt":0,"limit":4132270080},"blkio_stats":{"io_service_bytes_recursive":[],"io_serviced_recursive":[],"io_queue_recursive":[],"io_service_time_recursive":[],"io_wait_time_recursive":[],"io_merged_recursive":[],"io_time_recursive":[],"sectors_recursive":[]},"networks":{"eth0":{"rx_bytes":648,"rx_packets":8,"rx_errors":0,"rx_dropped":0,"tx_bytes":648,"tx_packets":8,"tx_errors":0,"tx_dropped":0}}}
  5. crosbymichael commented on Nov 20, 2015

    @crosbymichael
    Contributor

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions