memfd: Reduce some syscalls in the on-demand case (#3757)
* memfd: Reduce some syscalls in the on-demand case This tweaks the internal organization of the `MemFdSlot` to avoid some syscalls in the default case as well as opportunistically in the pooling case. The two cases added here are: * A `MemFdSlot` is now created with a specified initial size. For pooling this is 0 but for the on-demand case this can be non-zero. * When `instantiate` is called with no prior image and the sizes match (as will be the case for on-demand allocation) then `mprotect` is skipped entirely. * In the `clear_and_remain-ready` case the `mprotect` is skipped if the heap wasn't grown at all. This should avoid ever using `mprotect` unnecessarily and makes the ranges we `mprotect` a bit smaller as well. * Review comments * Tweak allow to apply to whole crate
This commit is contained in:
@@ -158,9 +158,8 @@ impl MmapMemory {
|
||||
// If a memfd image was specified, try to create the MemFdSlot on top of our mmap.
|
||||
let memfd = match memfd_image {
|
||||
Some(image) => {
|
||||
let base = unsafe { mmap.as_mut_ptr().offset(pre_guard_bytes as isize) };
|
||||
let len = request_bytes - pre_guard_bytes;
|
||||
let mut memfd_slot = MemFdSlot::create(base as *mut _, len);
|
||||
let base = unsafe { mmap.as_mut_ptr().add(pre_guard_bytes) };
|
||||
let mut memfd_slot = MemFdSlot::create(base.cast(), minimum, alloc_bytes);
|
||||
memfd_slot.instantiate(minimum, Some(image))?;
|
||||
// On drop, we will unmap our mmap'd range that this
|
||||
// memfd_slot was mapped on top of, so there is no
|
||||
|
||||
Reference in New Issue
Block a user