mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Round hashglobe allocations up to the nearest page size.
MozReview-Commit-ID: 34KFtcwCkBB
This commit is contained in:
parent
98f370130d
commit
ef042899d2
8 changed files with 29 additions and 1 deletions
|
@ -52,3 +52,6 @@ impl fmt::Display for FailedAllocationError {
|
|||
self.reason.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// The size of memory pages on this system. Set when initializing geckolib.
|
||||
pub static SYSTEM_PAGE_SIZE: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
|
||||
|
|
|
@ -777,7 +777,7 @@ impl<K, V> RawTable<K, V> {
|
|||
|
||||
|
||||
// FORK NOTE: Uses alloc shim instead of Heap.alloc
|
||||
let buffer = alloc(size, alignment);
|
||||
let buffer = alloc(round_up_to_page_size(size), alignment);
|
||||
|
||||
if buffer.is_null() {
|
||||
|
||||
|
@ -1201,3 +1201,19 @@ impl<K, V> Drop for RawTable<K, V> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Force all allocations to fill their pages for the duration of the mprotect
|
||||
// experiment.
|
||||
#[inline]
|
||||
fn round_up_to_page_size(size: usize) -> usize {
|
||||
let page_size = ::SYSTEM_PAGE_SIZE.load(::std::sync::atomic::Ordering::Relaxed);
|
||||
debug_assert!(page_size != 0);
|
||||
let mut result = size;
|
||||
let remainder = size % page_size;
|
||||
if remainder != 0 {
|
||||
result += page_size - remainder;
|
||||
}
|
||||
debug_assert!(result % page_size == 0);
|
||||
debug_assert!(result - size < page_size);
|
||||
result
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue