From 917d66d83357d38d2c3f3b24738f82fd93a4ac04 Mon Sep 17 00:00:00 2001 From: majiayu000 <1835304752@qq.com> Date: Fri, 26 Dec 2025 17:28:52 +0800 Subject: [PATCH] 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> --- api/swagger.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 610dc778d8..f2a0cb6cde 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -6247,7 +6247,11 @@ definitions: example: 0 stats: 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. type: "object" @@ -8515,7 +8519,8 @@ paths: To calculate the values shown by the `stats` command of the docker cli tool 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` * Memory usage % = `(used_memory / available_memory) * 100.0` * cpu_delta = `cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage`