6

I've got a process running in a Docker container on Linux, with a 2GByte memory limit. (The container is started with docker run --memory=2g.)

Here is what top says about it after it's been running for a while.

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 9016 root      20   0 7342132 4.652g 4.224g S 100.0  7.4  18828:28 blah

Here's the output of docker stats:

CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
d7032e5928b6        100.02%             2.076 GB/2.147 GB   96.68%              345 MB/199.1 MB

Then, after restarting it, top:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 5653 root      20   0 2787800 1.328g 1.030g S 100.0  2.1   0:37.57 blah

docker stats:

CONTAINER           CPU %               MEM USAGE/LIMIT     MEM %               NET I/O
10cefdce241f        99.97%              320.4 MB/2.147 GB   14.92%              36.34 kB/22.48 kB

So that matches up (very roughly) with RES-SHR, which makes some sense to me - but the equivalent calculation for the output from the long-running container doesn't match up in the same way.

What exactly is Docker counting here? Can I match it up somehow with the output from top, or some other tool?

2 Answers 2

0

docker stats include file cache memory as well. It will be freed upon request, but it is counted as used.

0

Docker stats are reporting the usage of memory and CPU within the container's cgroup. This will correlate with the some of the top stats, but not exactly since memory in a process includes shared memory, memory mapped to a filesystem object, etc. The cgroup is going to aggregate the usage of all of the processes within that container. To see the cgroup usage inside the container, you can look at files in /sys/fs/cgroup/memory/:

$ docker run -it --rm --name memtest -m 2g busybox /bin/sh
/ # cat /sys/fs/cgroup/memory/memory.usage_in_bytes
1519616
/ # cat /sys/fs/cgroup/memory/memory.limit_in_bytes
2147483648

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .