Skip to content

Commit

Permalink
Optimization: only mprotect the *new* bit of heap, not all of it.
Browse files Browse the repository at this point in the history
(This was not a correctness bug, but is an obvious performance bug...)
  • Loading branch information
cfallin committed Feb 1, 2022
1 parent 982df2f commit ccfa245
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/runtime/src/memfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ impl MemFdSlot {
}

pub(crate) fn set_heap_limit(&mut self, size_bytes: usize) -> Result<()> {
assert!(size_bytes > self.cur_size);
assert!(
size_bytes > self.cur_size,
"size_bytes = {} cur_size = {}",
size_bytes,
self.cur_size
);
// mprotect the relevant region.
let start = self.base + self.cur_size;
let len = size_bytes - self.cur_size;
Expand All @@ -327,6 +332,7 @@ impl MemFdSlot {
rustix::io::MprotectFlags::READ | rustix::io::MprotectFlags::WRITE,
)?;
}
self.cur_size = size_bytes;

Ok(())
}
Expand Down Expand Up @@ -355,6 +361,7 @@ impl MemFdSlot {
== maybe_image.as_ref().unwrap().fd.as_file().as_raw_fd())
{
self.dirty = true;
self.cur_size = initial_size_bytes;
return Ok(());
}

Expand Down Expand Up @@ -405,6 +412,7 @@ impl MemFdSlot {

// mprotect above `initial_size_bytes`.
self.initial_size = initial_size_bytes;
self.cur_size = initial_size_bytes;
self.protect_past_initial_size()
.map_err(|e| InstantiationError::Resource(e.into()))?;

Expand Down

0 comments on commit ccfa245

Please sign in to comment.