Skip to content

Commit

Permalink
Fix address range for pages removal (#132)
Browse files Browse the repository at this point in the history
and also add some extra logging in case there is not a single page that
can be successfully removed

Test Plan
=========

Manual tests
  • Loading branch information
javierhonduco authored Jan 13, 2025
1 parent 0e4574b commit 1bbbd18
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,30 +910,39 @@ impl Profiler {
bpf: &ProfilerSkel,
start_address: u64,
end_address: u64,
executable_id: u64,
executable_id: ExecutableId,
) {
let start_address_high = start_address & HIGH_PC_MASK;
let end_address_high = end_address & HIGH_PC_MASK;
let range = start_address..end_address;
let mut success_count = 0;
let mut failure_count = 0;

for file_offset in
(start_address_high..end_address_high).step_by(UNWIND_INFO_PAGE_SIZE as usize)
{
for file_offset in range.clone().step_by(UNWIND_INFO_PAGE_SIZE as usize) {
let key = page_key_t {
file_offset,
file_offset: file_offset & HIGH_PC_MASK,
executable_id,
};

// TODO: ensure that at least one entry can be removed. Some might fail as
// we prefer to not have to re-read the unwind information and we might attempt
// deleting entries that are not present.
let ret = bpf
.maps
.executable_to_page
.delete(unsafe { plain::as_bytes(&key) });
if ret.is_err() {
error!("failed removing BPF pages");

if ret.is_ok() {
success_count += 1;
} else {
failure_count += 1;
}
}

// Some might fail as we prefer to not have to re-read the unwind information
// and we might attempt deleting entries that are not present.
if success_count == 0 {
let total = success_count + failure_count;
error!(
"failed to remove {} / {} BPF pages (range: {:?}) start_address_high {} end_address_high {}",
failure_count, total, range, start_address, end_address
);
}
}

fn add_bpf_mapping(
Expand Down

0 comments on commit 1bbbd18

Please sign in to comment.