Skip to content

Commit

Permalink
use zswap and zswapped from memory.stat
Browse files Browse the repository at this point in the history
Summary: Previous diff added zswap and zswapped from memory.stat. This diff adds them to the cgroup memory model and view. With zswap from memory.stat, we no longer need to read memory.zswap.current. We can rearrange the fields to represent the order of memory.stat file. Also fix some lints.

Reviewed By: antonis-m

Differential Revision: D49345443

fbshipit-source-id: 47b1f12827872f9c2ab2d82f0cde6024d90ee419
  • Loading branch information
lnyng authored and facebook-github-bot committed Sep 18, 2023
1 parent 2e04aa1 commit d773f7d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 33 deletions.
3 changes: 2 additions & 1 deletion below/dump/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,14 @@ fn test_dump_cgroup_titles() {
"Throttled Pct",
"Mem Total",
"Mem Swap",
"Mem Zswap",
"Mem Anon",
"Mem File",
"Kernel Stack",
"Mem Slab",
"Mem Sock",
"Mem Shmem",
"Mem Zswap",
"Mem Zswapped",
"File Mapped",
"File Dirty",
"File WB",
Expand Down
55 changes: 31 additions & 24 deletions below/model/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,14 @@ impl std::ops::Add<&CgroupIoModel> for CgroupIoModel {
pub struct CgroupMemoryModel {
pub total: Option<u64>,
pub swap: Option<u64>,
pub zswap: Option<u64>,
pub anon: Option<u64>,
pub file: Option<u64>,
pub kernel_stack: Option<u64>,
pub slab: Option<u64>,
pub sock: Option<u64>,
pub shmem: Option<u64>,
pub zswap: Option<u64>,
pub zswapped: Option<u64>,
pub file_mapped: Option<u64>,
pub file_dirty: Option<u64>,
pub file_writeback: Option<u64>,
Expand Down Expand Up @@ -519,13 +520,14 @@ impl std::ops::Add for CgroupMemoryModel {
Self {
total: opt_add(self.total, other.total),
swap: opt_add(self.swap, other.swap),
zswap: opt_add(self.zswap, other.zswap),
anon: opt_add(self.anon, other.anon),
file: opt_add(self.file, other.file),
kernel_stack: opt_add(self.kernel_stack, other.kernel_stack),
slab: opt_add(self.slab, other.slab),
sock: opt_add(self.sock, other.sock),
shmem: opt_add(self.shmem, other.shmem),
zswap: opt_add(self.zswap, other.zswap),
zswapped: opt_add(self.zswapped, other.zswapped),
file_mapped: opt_add(self.file_mapped, other.file_mapped),
file_dirty: opt_add(self.file_dirty, other.file_dirty),
file_writeback: opt_add(self.file_writeback, other.file_writeback),
Expand Down Expand Up @@ -597,30 +599,35 @@ impl CgroupMemoryModel {
..Default::default()
};
if let Some(events) = &sample.memory_events {
model.events_low = events.low.map(|v| v as u64);
model.events_high = events.high.map(|v| v as u64);
model.events_max = events.max.map(|v| v as u64);
model.events_oom = events.oom.map(|v| v as u64);
model.events_oom_kill = events.oom_kill.map(|v| v as u64);
model.events_low = events.low;
model.events_high = events.high;
model.events_max = events.max;
model.events_oom = events.oom;
model.events_oom_kill = events.oom_kill;
}
if let Some(stat) = &sample.memory_stat {
model.anon = stat.anon.map(|v| v as u64);
model.file = stat.file.map(|v| v as u64);
model.kernel_stack = stat.kernel_stack.map(|v| v as u64);
model.slab = stat.slab.map(|v| v as u64);
model.sock = stat.sock.map(|v| v as u64);
model.shmem = stat.shmem.map(|v| v as u64);
model.file_mapped = stat.file_mapped.map(|v| v as u64);
model.file_dirty = stat.file_dirty.map(|v| v as u64);
model.file_writeback = stat.file_writeback.map(|v| v as u64);
model.anon_thp = stat.anon_thp.map(|v| v as u64);
model.inactive_anon = stat.inactive_anon.map(|v| v as u64);
model.active_anon = stat.active_anon.map(|v| v as u64);
model.inactive_file = stat.inactive_file.map(|v| v as u64);
model.active_file = stat.active_file.map(|v| v as u64);
model.unevictable = stat.unevictable.map(|v| v as u64);
model.slab_reclaimable = stat.slab_reclaimable.map(|v| v as u64);
model.slab_unreclaimable = stat.slab_unreclaimable.map(|v| v as u64);
model.anon = stat.anon;
model.file = stat.file;
model.kernel_stack = stat.kernel_stack;
model.slab = stat.slab;
model.sock = stat.sock;
model.shmem = stat.shmem;
// May be set by sample.memory_zswap_current
if model.zswap.is_none() {
model.zswap = stat.zswap;
}
model.zswapped = stat.zswapped;
model.file_mapped = stat.file_mapped;
model.file_dirty = stat.file_dirty;
model.file_writeback = stat.file_writeback;
model.anon_thp = stat.anon_thp;
model.inactive_anon = stat.inactive_anon;
model.active_anon = stat.active_anon;
model.inactive_file = stat.inactive_file;
model.active_file = stat.active_file;
model.unevictable = stat.unevictable;
model.slab_reclaimable = stat.slab_reclaimable;
model.slab_unreclaimable = stat.slab_unreclaimable;

if let Some((
CgroupSample {
Expand Down
4 changes: 2 additions & 2 deletions below/model/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fn collect_cgroup_sample(
};
Ok(CgroupSample {
cpu_stat: wrap(reader.read_cpu_stat())?.map(Into::into),
io_stat: io_stat.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
io_stat,
memory_current: wrap(reader.read_memory_current().map(|v| v as i64))?,
memory_stat: wrap(reader.read_memory_stat())?.map(Into::into),
pressure: pressure_wrap(reader.read_pressure())?.map(Into::into),
Expand Down Expand Up @@ -382,7 +382,7 @@ fn collect_cgroup_sample(
})
.transpose()?,
memory_swap_current: wrap(reader.read_memory_swap_current().map(|v| v as i64))?,
memory_zswap_current: wrap(reader.read_memory_zswap_current().map(|v| v as i64))?,
memory_zswap_current: None, // Use the one from memory.stat
memory_min: wrap(reader.read_memory_min())?,
memory_low: wrap(reader.read_memory_low())?,
memory_high: wrap(reader.read_memory_high())?,
Expand Down
5 changes: 3 additions & 2 deletions 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; 361] = [
pub const COMMON_MODEL_FIELD_IDS: [&str; 362] = [
"system.hostname",
"system.kernel_version",
"system.os_release",
Expand Down Expand Up @@ -154,13 +154,14 @@ pub const COMMON_MODEL_FIELD_IDS: [&str; 361] = [
"cgroup.[path:/<cgroup_path>/.]cpu.throttled_pct",
"cgroup.[path:/<cgroup_path>/.]mem.total",
"cgroup.[path:/<cgroup_path>/.]mem.swap",
"cgroup.[path:/<cgroup_path>/.]mem.zswap",
"cgroup.[path:/<cgroup_path>/.]mem.anon",
"cgroup.[path:/<cgroup_path>/.]mem.file",
"cgroup.[path:/<cgroup_path>/.]mem.kernel_stack",
"cgroup.[path:/<cgroup_path>/.]mem.slab",
"cgroup.[path:/<cgroup_path>/.]mem.sock",
"cgroup.[path:/<cgroup_path>/.]mem.shmem",
"cgroup.[path:/<cgroup_path>/.]mem.zswap",
"cgroup.[path:/<cgroup_path>/.]mem.zswapped",
"cgroup.[path:/<cgroup_path>/.]mem.file_mapped",
"cgroup.[path:/<cgroup_path>/.]mem.file_dirty",
"cgroup.[path:/<cgroup_path>/.]mem.file_writeback",
Expand Down
10 changes: 10 additions & 0 deletions below/model/src/sample_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ pub const SAMPLE_MODEL_JSON: &str = r#"
"slab": 300000000,
"sock": 10000000,
"shmem": 2000000,
"zswap": 100,
"zswapped": 1000000,
"file_mapped": 200000000,
"file_dirty": 3000000,
"file_writeback": 60000000,
Expand Down Expand Up @@ -314,6 +316,8 @@ pub const SAMPLE_MODEL_JSON: &str = r#"
"slab": 5000000,
"sock": 0,
"shmem": 30000,
"zswap": 20,
"zswapped": 20000,
"file_mapped": 7000000,
"file_dirty": 0,
"file_writeback": 800000,
Expand Down Expand Up @@ -399,6 +403,8 @@ pub const SAMPLE_MODEL_JSON: &str = r#"
"slab": 3000000,
"sock": 0,
"shmem": 0,
"zswap": 0,
"zswapped": 0,
"file_mapped": 0,
"file_dirty": 0,
"file_writeback": 0,
Expand Down Expand Up @@ -492,6 +498,8 @@ pub const SAMPLE_MODEL_JSON: &str = r#"
"slab": 3000000,
"sock": 400000,
"shmem": 1000000,
"zswap": 500,
"zswapped": 500000,
"file_mapped": 50000000,
"file_dirty": 1000000,
"file_writeback": 9000000,
Expand Down Expand Up @@ -582,6 +590,8 @@ pub const SAMPLE_MODEL_JSON: &str = r#"
"slab": 200000,
"sock": 0,
"shmem": 0,
"zswap": 50,
"zswapped": 50000,
"file_mapped": 200000,
"file_dirty": 0,
"file_writeback": 0,
Expand Down
10 changes: 7 additions & 3 deletions below/render/src/default_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl HasRenderConfigForDump for model::SingleCgroupModel {
use model::CgroupMemoryModelFieldId::WorkingsetRestoreAnon;
use model::CgroupMemoryModelFieldId::WorkingsetRestoreFile;
use model::CgroupMemoryModelFieldId::Zswap;
use model::CgroupMemoryModelFieldId::Zswapped;
use model::CgroupPressureModelFieldId::MemoryFullPct;
use model::CgroupPressureModelFieldId::MemorySomePct;
use model::SingleCgroupModelFieldId::Cpu;
Expand All @@ -114,12 +115,13 @@ impl HasRenderConfigForDump for model::SingleCgroupModel {
Io(CostIndelayPct) => rc.title("Cost Indelay"),
Mem(Total) => rc.title("Mem Total"),
Mem(Swap) => rc.title("Mem Swap"),
Mem(Zswap) => rc.title("Mem Zswap"),
Mem(Anon) => rc.title("Mem Anon"),
Mem(File) => rc.title("Mem File"),
Mem(Slab) => rc.title("Mem Slab"),
Mem(Sock) => rc.title("Mem Sock"),
Mem(Shmem) => rc.title("Mem Shmem"),
Mem(Zswap) => rc.title("Mem Zswap"),
Mem(Zswapped) => rc.title("Mem Zswapped"),
Mem(Pgfault) => rc.title("Pgfault"),
Mem(Pgmajfault) => rc.title("Pgmajfault"),
Mem(WorkingsetRefaultAnon) => rc.title("Workingset Refault Anon"),
Expand Down Expand Up @@ -189,7 +191,6 @@ impl HasRenderConfigForDump for model::SingleCgroupModel {
Mem(field_id) => match field_id {
Total => Some(counter.unit("bytes")),
Swap => Some(counter.unit("bytes")),
Zswap => Some(counter.unit("bytes")),
// Not sure what to do about min/low/high/max values b/c they're neither
// counters nor gauges. So leave out for now.
EventsLow => None,
Expand All @@ -203,6 +204,8 @@ impl HasRenderConfigForDump for model::SingleCgroupModel {
Slab => Some(gauge.unit("bytes")),
Sock => Some(gauge.unit("bytes")),
Shmem => Some(gauge.unit("bytes")),
Zswap => Some(counter.unit("bytes")),
Zswapped => Some(gauge.unit("bytes")),
FileMapped => Some(gauge.unit("bytes")),
FileDirty => Some(gauge.unit("bytes")),
FileWriteback => Some(gauge.unit("bytes")),
Expand Down Expand Up @@ -299,7 +302,6 @@ impl HasRenderConfig for model::CgroupMemoryModel {
match field_id {
Total => rc.title("Mem").format(ReadableSize),
Swap => rc.title("Mem Swap").format(ReadableSize),
Zswap => rc.title("Mem Zswap").format(ReadableSize),
EventsLow => rc.title("Events Low"),
EventsHigh => rc.title("Events High"),
EventsMax => rc.title("Events Max"),
Expand All @@ -311,6 +313,8 @@ impl HasRenderConfig for model::CgroupMemoryModel {
Slab => rc.title("Slab").format(ReadableSize),
Sock => rc.title("Sock").format(ReadableSize),
Shmem => rc.title("Shmem").format(ReadableSize),
Zswap => rc.title("Zswap").format(ReadableSize),
Zswapped => rc.title("Zswapped").format(ReadableSize),
FileMapped => rc.title("File Mapped").format(ReadableSize),
FileDirty => rc.title("File Dirty").format(ReadableSize),
FileWriteback => rc.title("File WB").format(ReadableSize),
Expand Down
4 changes: 3 additions & 1 deletion below/view/src/cgroup_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ pub mod default_tabs {
use model::CgroupMemoryModelFieldId::WorkingsetRestoreAnon;
use model::CgroupMemoryModelFieldId::WorkingsetRestoreFile;
use model::CgroupMemoryModelFieldId::Zswap;
use model::CgroupMemoryModelFieldId::Zswapped;
use model::CgroupPressureModelFieldId::CpuFullPct;
use model::CgroupPressureModelFieldId::CpuSomePct;
use model::CgroupPressureModelFieldId::IoFullPct;
Expand Down Expand Up @@ -349,13 +350,14 @@ pub mod default_tabs {
CgroupTab::new(vec![
ViewItem::from_default(Mem(Total)),
ViewItem::from_default(Mem(Swap)),
ViewItem::from_default(Mem(Zswap)),
ViewItem::from_default(Mem(Anon)),
ViewItem::from_default(Mem(File)),
ViewItem::from_default(Mem(KernelStack)),
ViewItem::from_default(Mem(Slab)),
ViewItem::from_default(Mem(Sock)),
ViewItem::from_default(Mem(Shmem)),
ViewItem::from_default(Mem(Zswap)),
ViewItem::from_default(Mem(Zswapped)),
ViewItem::from_default(Mem(FileMapped)),
ViewItem::from_default(Mem(FileDirty)),
ViewItem::from_default(Mem(FileWriteback)),
Expand Down

0 comments on commit d773f7d

Please sign in to comment.