docs: update stats API description for cgroups v2 compatibility

Update the memory stats documentation to clarify differences between
cgroups v1 and v2:

- Add cgroups v2 formula for calculating used_memory using inactive_file
  instead of cache field which is not available in v2
- Update memory_stats.stats description to explain that field names
  differ between v1 (cache, rss, mapped_file) and v2 (file, anon, inactive_file)

Fixes #43810

Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
majiayu000
2025-12-26 17:28:52 +08:00
parent 3bd2edb375
commit 917d66d833

View File

@@ -6247,7 +6247,11 @@ definitions:
example: 0 example: 0
stats: stats:
description: | description: |
All the stats exported via memory.stat. when using cgroups v2. All the stats exported via memory.stat.
The fields in this object differ between cgroups v1 and v2.
On cgroups v1, fields such as `cache`, `rss`, `mapped_file` are available.
On cgroups v2, fields such as `file`, `anon`, `inactive_file` are available.
This field is Linux-specific and omitted for Windows containers. This field is Linux-specific and omitted for Windows containers.
type: "object" type: "object"
@@ -8515,7 +8519,8 @@ paths:
To calculate the values shown by the `stats` command of the docker cli tool To calculate the values shown by the `stats` command of the docker cli tool
the following formulas can be used: the following formulas can be used:
* used_memory = `memory_stats.usage - memory_stats.stats.cache` * used_memory = `memory_stats.usage - memory_stats.stats.cache` (cgroups v1)
* used_memory = `memory_stats.usage - memory_stats.stats.inactive_file` (cgroups v2)
* available_memory = `memory_stats.limit` * available_memory = `memory_stats.limit`
* Memory usage % = `(used_memory / available_memory) * 100.0` * Memory usage % = `(used_memory / available_memory) * 100.0`
* cpu_delta = `cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage` * cpu_delta = `cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage`