Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-11-03 09:43:06 +0300
committerQuang-Minh Nguyen <qmnguyen@gitlab.com>2023-11-03 09:43:06 +0300
commitfb0f641b6555bed50bec956cba90f14e4720a6af (patch)
tree0e0a214158553142e2a237cc90fcbbf4a2b4e4fd
parent9bf28d2089501b82b40e2b9f6ad21cf80751f15f (diff)
cgroup: Collect some more stats from `memory.stat` file
This commit adds some more essential fields collected from `memory.stat` file. There are two differences between Cgroup V1 and V2: - `rss` in V1 is named `anon` in V2. - `cache` in V1 is named `file` in V2. The names in V2 reflect the meanings of underlying metrics better. Thus, the reported stats use V2's names.
-rw-r--r--internal/cgroups/cgroups.go12
-rw-r--r--internal/cgroups/v1_linux.go6
-rw-r--r--internal/cgroups/v1_linux_test.go12
-rw-r--r--internal/cgroups/v2_linux.go6
-rw-r--r--internal/cgroups/v2_linux_test.go12
5 files changed, 48 insertions, 0 deletions
diff --git a/internal/cgroups/cgroups.go b/internal/cgroups/cgroups.go
index 9a8b96492..8cf8df116 100644
--- a/internal/cgroups/cgroups.go
+++ b/internal/cgroups/cgroups.go
@@ -34,6 +34,18 @@ type CgroupStats struct {
// UnderOOM is the current OOM status of a cgroup. This information is available for Cgroup V1 only. It's read
// from the `memory.oom_control` file.
UnderOOM bool
+ // Anon reflects the `rss` (V1) or `anon` (V2) of `memory.stat` file. That's amount of memory used in anonymous mappings
+ Anon uint64
+ // ActiveAnon reflects the `active_file` of `memory.stat` file, anonymous and swap cache memory on active LRU list.
+ ActiveAnon uint64
+ // InactiveAnon reflects the `inactive_anon` of `memory.stat` file, anonymous and swap cache memory on inactive LRU list.
+ InactiveAnon uint64
+ // File reflects the `cache` (V1) or `file` (V2) of `memory.stat` file, bytes of page cache memory.
+ File uint64
+ // ActiveFile reflects the `active_file` of `memory.stat` file, bytes of file-backed memory that cannot be reclaimed.
+ ActiveFile uint64
+ // InactiveFile reflects the `inactive_file` of `memory.stat` file, bytes of file-backed memory on inactive LRU list.
+ InactiveFile uint64
}
// Stats stores statistics of all cgroups managed by a manager
diff --git a/internal/cgroups/v1_linux.go b/internal/cgroups/v1_linux.go
index 92f2b6031..8783f2156 100644
--- a/internal/cgroups/v1_linux.go
+++ b/internal/cgroups/v1_linux.go
@@ -205,6 +205,12 @@ func (cvh *cgroupV1Handler) stats() (Stats, error) {
MemoryLimit: metrics.Memory.Usage.Limit,
OOMKills: metrics.MemoryOomControl.OomKill,
UnderOOM: metrics.MemoryOomControl.UnderOom != 0,
+ Anon: metrics.Memory.RSS,
+ ActiveAnon: metrics.Memory.ActiveAnon,
+ InactiveAnon: metrics.Memory.InactiveAnon,
+ File: metrics.Memory.Cache,
+ ActiveFile: metrics.Memory.ActiveFile,
+ InactiveFile: metrics.Memory.InactiveFile,
},
}, nil
}
diff --git a/internal/cgroups/v1_linux_test.go b/internal/cgroups/v1_linux_test.go
index cb28d40c0..dcb4358b8 100644
--- a/internal/cgroups/v1_linux_test.go
+++ b/internal/cgroups/v1_linux_test.go
@@ -574,6 +574,12 @@ oom_kill 3`},
{"cpu.stat", `nr_periods 10
nr_throttled 50
throttled_time 1000000`}, // 0.001 seconds
+ {"memory.stat", `cache 235000000
+rss 234000000
+inactive_anon 200000000
+active_anon 34000000
+inactive_file 100000000
+active_file 135000000`},
},
expectedStats: Stats{
ParentStats: CgroupStats{
@@ -583,6 +589,12 @@ throttled_time 1000000`}, // 0.001 seconds
MemoryLimit: 2000000000,
OOMKills: 3,
UnderOOM: true,
+ Anon: 234000000,
+ ActiveAnon: 34000000,
+ InactiveAnon: 200000000,
+ File: 235000000,
+ ActiveFile: 135000000,
+ InactiveFile: 100000000,
},
},
},
diff --git a/internal/cgroups/v2_linux.go b/internal/cgroups/v2_linux.go
index 969c94e1f..cd2884de6 100644
--- a/internal/cgroups/v2_linux.go
+++ b/internal/cgroups/v2_linux.go
@@ -199,6 +199,12 @@ func (cvh *cgroupV2Handler) stats() (Stats, error) {
CPUThrottledDuration: float64(metrics.CPU.ThrottledUsec) / float64(time.Second),
MemoryUsage: metrics.Memory.Usage,
MemoryLimit: metrics.Memory.UsageLimit,
+ Anon: metrics.Memory.Anon,
+ ActiveAnon: metrics.Memory.ActiveAnon,
+ InactiveAnon: metrics.Memory.InactiveAnon,
+ File: metrics.Memory.File,
+ ActiveFile: metrics.Memory.ActiveFile,
+ InactiveFile: metrics.Memory.InactiveFile,
},
}
if metrics.MemoryEvents != nil {
diff --git a/internal/cgroups/v2_linux_test.go b/internal/cgroups/v2_linux_test.go
index 67b5bc2dc..a0042083d 100644
--- a/internal/cgroups/v2_linux_test.go
+++ b/internal/cgroups/v2_linux_test.go
@@ -546,6 +546,12 @@ oom_kill 5`},
{"cpu.stat", `nr_periods 10
nr_throttled 50
throttled_usec 1000000`}, // 0.001 seconds
+ {"memory.stat", `anon 234000000
+file 235000000
+inactive_anon 200000000
+active_anon 34000000
+inactive_file 100000000
+active_file 135000000`},
},
expectedStats: Stats{
ParentStats: CgroupStats{
@@ -554,6 +560,12 @@ throttled_usec 1000000`}, // 0.001 seconds
MemoryUsage: 1234000000,
MemoryLimit: 2000000000,
OOMKills: 5,
+ Anon: 234000000,
+ ActiveAnon: 34000000,
+ InactiveAnon: 200000000,
+ File: 235000000,
+ ActiveFile: 135000000,
+ InactiveFile: 100000000,
},
},
},