Home Explore Blog CI



docker

3rd chunk of `content/manuals/engine/containers/runmetrics.md`
099eaa2368cdcc2b22afe775701007e5036c517ed527dc150000000100000fc4
For each subsystem (memory, CPU, and block I/O), one or
more pseudo-files exist and contain statistics.

#### Memory metrics: `memory.stat`

Memory metrics are found in the `memory` cgroup. The memory
control group adds a little overhead, because it does very fine-grained
accounting of the memory usage on your host. Therefore, many distributions
chose to not enable it by default. Generally, to enable it, all you have
to do is to add some kernel command-line parameters:
`cgroup_enable=memory swapaccount=1`.

The metrics are in the pseudo-file `memory.stat`.
Here is what it looks like:

    cache 11492564992
    rss 1930993664
    mapped_file 306728960
    pgpgin 406632648
    pgpgout 403355412
    swap 0
    pgfault 728281223
    pgmajfault 1724
    inactive_anon 46608384
    active_anon 1884520448
    inactive_file 7003344896
    active_file 4489052160
    unevictable 32768
    hierarchical_memory_limit 9223372036854775807
    hierarchical_memsw_limit 9223372036854775807
    total_cache 11492564992
    total_rss 1930993664
    total_mapped_file 306728960
    total_pgpgin 406632648
    total_pgpgout 403355412
    total_swap 0
    total_pgfault 728281223
    total_pgmajfault 1724
    total_inactive_anon 46608384
    total_active_anon 1884520448
    total_inactive_file 7003344896
    total_active_file 4489052160
    total_unevictable 32768

The first half (without the `total_` prefix) contains statistics relevant
to the processes within the cgroup, excluding sub-cgroups. The second half
(with the `total_` prefix) includes sub-cgroups as well.

Some metrics are "gauges", or values that can increase or decrease. For instance,
`swap` is the amount of swap space used by the members of the cgroup.
Some others are "counters", or values that can only go up, because
they represent occurrences of a specific event. For instance, `pgfault`
indicates the number of page faults since the creation of the cgroup.

`cache`
: The amount of memory used by the processes of this control group that can be
  associated precisely with a block on a block device. When you read from and
  write to files on disk, this amount increases. This is the case if you use
  "conventional" I/O (`open`, `read`, `write` syscalls) as well as mapped files
  (with `mmap`). It also accounts for the memory used by `tmpfs` mounts, though
  the reasons are unclear.

`rss`
: The amount of memory that doesn't correspond to anything on disk: stacks,
  heaps, and anonymous memory maps.

`mapped_file`
: Indicates the amount of memory mapped by the processes in the control group.
  It doesn't give you information about how much memory is used; it rather
  tells you how it's used.

`pgfault`, `pgmajfault`
: Indicate the number of times that a process of the cgroup triggered a "page
  fault" and a "major fault", respectively. A page fault happens when a process
  accesses a part of its virtual memory space which is nonexistent or protected.
  The former can happen if the process is buggy and tries to access an invalid
  address (it is sent a `SIGSEGV` signal, typically killing it with the famous
  `Segmentation fault` message). The latter can happen when the process reads
  from a memory zone which has been swapped out, or which corresponds to a mapped
  file: in that case, the kernel loads the page from disk, and let the CPU
  complete the memory access. It can also happen when the process writes to a
  copy-on-write memory zone: likewise, the kernel preempts the process, duplicate
  the memory page, and resume the write operation on the process's own copy of
  the page. "Major" faults happen when the kernel actually needs to read the data
  from disk. When it just duplicates an existing page, or allocate an empty page,
  it's a regular (or "minor") fault.

`swap`
: The amount of swap currently used by the processes in this cgroup.

`active_anon`, `inactive_anon`
: The amount of anonymous memory that has been identified has respectively
  _active_ and _inactive_ by the kernel. "Anonymous" memory is the memory that is

Title: Detailed Memory Metrics in Cgroups
Summary
This section provides a comprehensive overview of memory metrics available in cgroups via the `memory.stat` pseudo-file. It differentiates between metrics that include sub-cgroups and those that don't, and explains the difference between gauges and counters. Detailed explanations are provided for various metrics such as `cache`, `rss`, `mapped_file`, `pgfault`, `pgmajfault`, `swap`, `active_anon`, and `inactive_anon`, clarifying their meaning and how they relate to memory usage within the cgroup.