Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transparent huge pages in linux memory observer #1105

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Changed
- logrotate_fs is now behind a feature flag and not enabled in the default
build. It remains enabled in the release artifact.
- On linux, transparent huge page usage is now collected and available
alongside existing `smaps_rollup` and `smaps_by_pathname` data.

## [0.24.0]
## Added
Expand Down
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
Loading