Skip to content

Commit

Permalink
Add support for memory.stat kernel field
Browse files Browse the repository at this point in the history
Summary:
Display `kernel` field from `memory.stat` - kernel memory used by cgroup.
This was added in 5.18: torvalds/linux@a8c49af3be5f0
This field is not present in `memory.numa.stat`

Reviewed By: brianc118

Differential Revision: D51832461

fbshipit-source-id: 98ca0561e05bb626edd3e0f285756191e0cc783c
  • Loading branch information
Andrew Onyshchuk authored and facebook-github-bot committed Dec 5, 2023
1 parent f807f62 commit ba700bd
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions below/cgroupfs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ key_values_format!(CpuStat; cpu.stat; [
key_values_format!(MemoryStat; memory.stat; [
anon,
file,
kernel,
kernel_stack,
slab,
sock,
Expand Down
1 change: 1 addition & 0 deletions below/cgroupfs/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub struct IoStat {
pub struct MemoryStat {
pub anon: Option<u64>,
pub file: Option<u64>,
pub kernel: Option<u64>,
pub kernel_stack: Option<u64>,
pub slab: Option<u64>,
pub sock: Option<u64>,
Expand Down
1 change: 1 addition & 0 deletions below/dump/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ fn test_dump_cgroup_titles() {
"Mem Swap",
"Mem Anon",
"Mem File",
"Kernel",
"Kernel Stack",
"Mem Slab",
"Mem Sock",
Expand Down
3 changes: 3 additions & 0 deletions below/model/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ pub struct CgroupMemoryModel {
pub swap: Option<u64>,
pub anon: Option<u64>,
pub file: Option<u64>,
pub kernel: Option<u64>,
pub kernel_stack: Option<u64>,
pub slab: Option<u64>,
pub sock: Option<u64>,
Expand Down Expand Up @@ -522,6 +523,7 @@ impl std::ops::Add for CgroupMemoryModel {
swap: opt_add(self.swap, other.swap),
anon: opt_add(self.anon, other.anon),
file: opt_add(self.file, other.file),
kernel: opt_add(self.kernel, other.kernel),
kernel_stack: opt_add(self.kernel_stack, other.kernel_stack),
slab: opt_add(self.slab, other.slab),
sock: opt_add(self.sock, other.sock),
Expand Down Expand Up @@ -608,6 +610,7 @@ impl CgroupMemoryModel {
if let Some(stat) = &sample.memory_stat {
model.anon = stat.anon;
model.file = stat.file;
model.kernel = stat.kernel;
model.kernel_stack = stat.kernel_stack;
model.slab = stat.slab;
model.sock = stat.sock;
Expand Down
3 changes: 2 additions & 1 deletion below/model/src/common_field_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
///
/// This list also servers as documentation for available field ids that could
/// be used in other below crates. A test ensures that this list is up-to-date.
pub const COMMON_MODEL_FIELD_IDS: [&str; 373] = [
pub const COMMON_MODEL_FIELD_IDS: [&str; 374] = [
"system.hostname",
"system.kernel_version",
"system.os_release",
Expand Down Expand Up @@ -156,6 +156,7 @@ pub const COMMON_MODEL_FIELD_IDS: [&str; 373] = [
"cgroup.[path:/<cgroup_path>/.]mem.swap",
"cgroup.[path:/<cgroup_path>/.]mem.anon",
"cgroup.[path:/<cgroup_path>/.]mem.file",
"cgroup.[path:/<cgroup_path>/.]mem.kernel",
"cgroup.[path:/<cgroup_path>/.]mem.kernel_stack",
"cgroup.[path:/<cgroup_path>/.]mem.slab",
"cgroup.[path:/<cgroup_path>/.]mem.sock",
Expand Down
2 changes: 2 additions & 0 deletions below/render/src/default_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl HasRenderConfigForDump for model::SingleCgroupModel {
EventsOomKill => Some(counter),
Anon => Some(gauge.unit("bytes")),
File => Some(gauge.unit("bytes")),
Kernel => Some(gauge.unit("bytes")),
KernelStack => Some(gauge.unit("bytes")),
Slab => Some(gauge.unit("bytes")),
Sock => Some(gauge.unit("bytes")),
Expand Down Expand Up @@ -309,6 +310,7 @@ impl HasRenderConfig for model::CgroupMemoryModel {
EventsOomKill => rc.title("Events Kill"),
Anon => rc.title("Anon").format(ReadableSize),
File => rc.title("File").format(ReadableSize),
Kernel => rc.title("Kernel").format(ReadableSize),
KernelStack => rc.title("Kernel Stack").format(ReadableSize),
Slab => rc.title("Slab").format(ReadableSize),
Sock => rc.title("Sock").format(ReadableSize),
Expand Down
2 changes: 2 additions & 0 deletions below/view/src/cgroup_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ pub mod default_tabs {
use model::CgroupMemoryModelFieldId::FileWriteback;
use model::CgroupMemoryModelFieldId::InactiveAnon;
use model::CgroupMemoryModelFieldId::InactiveFile;
use model::CgroupMemoryModelFieldId::Kernel;
use model::CgroupMemoryModelFieldId::KernelStack;
use model::CgroupMemoryModelFieldId::Pgactivate;
use model::CgroupMemoryModelFieldId::Pgdeactivate;
Expand Down Expand Up @@ -352,6 +353,7 @@ pub mod default_tabs {
ViewItem::from_default(Mem(Swap)),
ViewItem::from_default(Mem(Anon)),
ViewItem::from_default(Mem(File)),
ViewItem::from_default(Mem(Kernel)),
ViewItem::from_default(Mem(KernelStack)),
ViewItem::from_default(Mem(Slab)),
ViewItem::from_default(Mem(Sock)),
Expand Down

0 comments on commit ba700bd

Please sign in to comment.