Skip to content

Commit

Permalink
Parsess the additional field 'AnonHugePages' which shows how much mem…
Browse files Browse the repository at this point in the history
…ory is used by transparent huge pages and reports it both for smaps_rollup and smaps_by_pathname
  • Loading branch information
scottopell committed Nov 11, 2024
1 parent 8284122 commit 73f004a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lading/src/observer/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ impl Sampler {
gauge!("smaps.pss.by_pathname", &labels).set(measures.pss as f64);
gauge!("smaps.size.by_pathname", &labels).set(measures.size as f64);
gauge!("smaps.swap.by_pathname", &labels).set(measures.swap as f64);
gauge!("smaps.anon_huge_pages.by_pathname", &labels)
.set(measures.anon_huge_pages as f64);
}

let measures = memory_regions.aggregate();
Expand Down Expand Up @@ -397,6 +399,9 @@ impl Sampler {
if let Some(v) = rollup.pss_shmem {
gauge!("smaps_rollup.pss_shmem", &labels).set(v as f64);
}
if let Some(v) = rollup.anon_huge_pages {
gauge!("smaps_rollup.anon_huge_pages", &labels).set(v as f64);
}
});
}

Expand Down
23 changes: 21 additions & 2 deletions lading/src/observer/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub(crate) struct Rollup {
pub(crate) pss_anon: Option<u64>,
pub(crate) pss_file: Option<u64>,
pub(crate) pss_shmem: Option<u64>,
pub(crate) anon_huge_pages: Option<u64>,
}

impl Rollup {
Expand Down Expand Up @@ -73,6 +74,7 @@ impl Rollup {
let mut pss_anon = None;
let mut pss_file = None;
let mut pss_shmem = None;
let mut anon_huge_pages = None;

for line in lines {
let mut chars = line.char_indices().peekable();
Expand Down Expand Up @@ -117,6 +119,9 @@ impl Rollup {
"Pss_Shmem:" => {
pss_shmem = Some(value_in_kibibytes()?);
}
"AnonHugePages" => {
anon_huge_pages = Some(value_in_kibibytes()?);
}
_ => {}
}
}
Expand All @@ -134,6 +139,7 @@ impl Rollup {
pss_anon,
pss_file,
pss_shmem,
anon_huge_pages,
})
}
}
Expand All @@ -159,6 +165,7 @@ pub(crate) struct Region {
pub(crate) pss: u64,
pub(crate) swap: u64,
pub(crate) rss: u64,
pub(crate) anon_huge_pages: u64,
pub(crate) pss_dirty: Option<u64>, // only present in 6.0+
}
// Best docs ref I have:
Expand Down Expand Up @@ -237,6 +244,7 @@ impl Region {
let mut rss: Option<u64> = None;
let mut swap: Option<u64> = None;
let mut pss_dirty: Option<u64> = None;
let mut anon_huge_pages: Option<u64> = None;

for line in lines {
let mut chars = line.char_indices().peekable();
Expand Down Expand Up @@ -278,11 +286,16 @@ impl Region {
"Pss_Dirty:" => {
pss_dirty = Some(value_in_kibibytes()?);
}
"AnonHugePages:" => {
anon_huge_pages = Some(value_in_kibibytes()?);
}
_ => {}
}
}

let (Some(size), Some(pss), Some(rss), Some(swap)) = (size, pss, rss, swap) else {
let (Some(size), Some(pss), Some(rss), Some(swap), Some(anon_huge_pages)) =
(size, pss, rss, swap, anon_huge_pages)
else {
return Err(Error::Parsing(format!(
"Could not parse all value fields from region: '{contents}'"
)));
Expand All @@ -301,6 +314,7 @@ impl Region {
swap,
rss,
pss_dirty,
anon_huge_pages,
})
}
}
Expand All @@ -311,6 +325,7 @@ pub(crate) struct AggrMeasure {
pub(crate) pss: u64,
pub(crate) swap: u64,
pub(crate) rss: u64,
pub(crate) anon_huge_pages: u64,
}

impl Regions {
Expand All @@ -327,6 +342,7 @@ impl Regions {
aggr.pss = aggr.pss.saturating_add(region.pss);
aggr.swap = aggr.swap.saturating_add(aggr.swap);
aggr.rss = aggr.rss.saturating_add(region.rss);
aggr.anon_huge_pages = aggr.anon_huge_pages.saturating_add(region.anon_huge_pages);
}

aggr
Expand All @@ -343,11 +359,13 @@ impl Regions {
pss: 0,
swap: 0,
rss: 0,
anon_huge_pages: 0,
});
entry.size += region.size;
entry.pss += region.pss;
entry.swap += region.swap;
entry.rss += region.rss;
entry.anon_huge_pages += region.anon_huge_pages;
}

map.into_iter().collect()
Expand Down Expand Up @@ -441,7 +459,7 @@ Private_Dirty: 0 kB
Referenced: 8 kB
Anonymous: 0 kB
LazyFree: 0 kB
AnonHugePages: 0 kB
AnonHugePages: 12 kB
ShmemPmdMapped: 0 kB
FilePmdMapped: 0 kB
Shared_Hugetlb: 0 kB
Expand Down Expand Up @@ -484,6 +502,7 @@ VmFlags: rd ex mr mw me de sd";
assert_eq!(region_two.pss, 2 * BYTES_PER_KIBIBYTE);
assert_eq!(region_two.swap, 0 * BYTES_PER_KIBIBYTE);
assert_eq!(region_two.rss, 8 * BYTES_PER_KIBIBYTE);
assert_eq!(region_two.anon_huge_pages, 12 * BYTES_PER_KIBIBYTE);
assert_eq!(region_two.pss_dirty, Some(0));
}

Expand Down

0 comments on commit 73f004a

Please sign in to comment.