Skip to content

Commit 3ec3bc5

Browse files
committed
[CONTINT-4562] Fix clippy errors
1 parent b553c89 commit 3ec3bc5

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

lading/src/observer/linux/wss.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use process_descendents::ProcessDescendentsIterator;
99
mod pfnset;
1010
use pfnset::PfnSet;
1111

12+
// From https://github.com/torvalds/linux/blob/c62f4b82d57155f35befb5c8bbae176614b87623/arch/x86/include/asm/page_64_types.h#L42
1213
const PAGE_OFFSET: u64 = 0xffff_8800_0000_0000;
1314

1415
#[derive(thiserror::Error, Debug)]
@@ -24,13 +25,22 @@ pub enum Error {
2425
#[derive(Debug)]
2526
pub(crate) struct Sampler {
2627
parent_pid: i32,
28+
page_idle_bitmap: std::fs::File,
2729
}
2830

2931
impl Sampler {
3032
pub(crate) fn new(parent_pid: i32) -> Result<Self, Error> {
31-
Ok(Self { parent_pid })
33+
Ok(Self {
34+
parent_pid,
35+
// See https://www.kernel.org/doc/html/latest/admin-guide/mm/idle_page_tracking.html
36+
page_idle_bitmap: std::fs::OpenOptions::new()
37+
.read(true)
38+
.write(true)
39+
.open("/sys/kernel/mm/page_idle/bitmap")?,
40+
})
3241
}
3342

43+
#[allow(clippy::unused_async)]
3444
pub(crate) async fn poll(&mut self) -> Result<(), Error> {
3545
let page_size = page_size::get();
3646
let mut pfn_set = PfnSet::new();
@@ -47,7 +57,9 @@ impl Sampler {
4757
continue; // page idle tracking is user mem only
4858
}
4959
debug!("Memory region: {:#x} — {:#x}", begin, end);
60+
#[allow(clippy::cast_possible_truncation)]
5061
let begin = begin as usize / page_size;
62+
#[allow(clippy::cast_possible_truncation)]
5163
let end = end as usize / page_size;
5264
for page in pagemap.get_range_info(begin..end)? {
5365
if let PageInfo::MemoryPage(memory_page_flags) = page {
@@ -61,23 +73,17 @@ impl Sampler {
6173

6274
let mut nb_pages = 0;
6375

64-
// See https://www.kernel.org/doc/html/latest/admin-guide/mm/idle_page_tracking.html
65-
let mut page_idle_bitmap = std::fs::OpenOptions::new()
66-
.read(true)
67-
.write(true)
68-
.open("/sys/kernel/mm/page_idle/bitmap")?;
69-
7076
for (pfn_block, pfn_bitset) in pfn_set {
71-
page_idle_bitmap.seek(SeekFrom::Start(pfn_block * 8))?;
77+
self.page_idle_bitmap.seek(SeekFrom::Start(pfn_block * 8))?;
7278

7379
let mut buffer = [0; 8];
74-
page_idle_bitmap.read_exact(&mut buffer)?;
80+
self.page_idle_bitmap.read_exact(&mut buffer)?;
7581
let bitset = u64::from_ne_bytes(buffer);
7682

7783
nb_pages += (!bitset & pfn_bitset).count_ones() as usize;
7884

79-
page_idle_bitmap.seek(SeekFrom::Start(pfn_block * 8))?;
80-
page_idle_bitmap.write_all(&pfn_bitset.to_ne_bytes())?;
85+
self.page_idle_bitmap.seek(SeekFrom::Start(pfn_block * 8))?;
86+
self.page_idle_bitmap.write_all(&pfn_bitset.to_ne_bytes())?;
8187
}
8288

8389
gauge!("total_wss_bytes").set((nb_pages * page_size) as f64);

lading/src/observer/linux/wss/process_descendents.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ impl ProcessDescendentsIterator {
88
pub(super) fn new(parent_pid: i32) -> Self {
99
Self {
1010
stack: vec![
11-
Process::new(parent_pid).expect(format!("process {parent_pid} not found").as_str()),
11+
Process::new(parent_pid)
12+
.unwrap_or_else(|e| panic!("process {parent_pid} not found: {e}")),
1213
],
1314
}
1415
}
@@ -18,21 +19,20 @@ impl Iterator for ProcessDescendentsIterator {
1819
type Item = Process;
1920

2021
fn next(&mut self) -> Option<Self::Item> {
21-
while let Some(process) = self.stack.pop() {
22-
if let Ok(tasks) = process.tasks() {
23-
for task in tasks.flatten() {
24-
if let Ok(children) = task.children() {
25-
for child in children {
26-
if let Ok(c) = Process::new(child as i32) {
27-
self.stack.push(c);
28-
}
22+
let process = self.stack.pop()?;
23+
if let Ok(tasks) = process.tasks() {
24+
for task in tasks.flatten() {
25+
if let Ok(children) = task.children() {
26+
for child in children {
27+
#[allow(clippy::cast_possible_wrap)]
28+
if let Ok(c) = Process::new(child as i32) {
29+
self.stack.push(c);
2930
}
3031
}
3132
}
3233
}
33-
return Some(process);
3434
}
35-
None
35+
Some(process)
3636
}
3737
}
3838

0 commit comments

Comments
 (0)