Skip to content

Commit

Permalink
Round hashglobe allocations up to the nearest page size.
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: 34KFtcwCkBB
  • Loading branch information
bholley committed Sep 28, 2017
1 parent 98f3701 commit ef04289
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/hashglobe/src/lib.rs
Expand Up @@ -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;
18 changes: 17 additions & 1 deletion components/hashglobe/src/table.rs
Expand Up @@ -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() {

Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions ports/geckolib/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ gecko_debug = ["style/gecko_debug"]
atomic_refcell = "0.1"
cssparser = "0.21.1"
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
hashglobe = {path = "../../components/hashglobe"}
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
malloc_size_of = {path = "../../components/malloc_size_of"}
Expand Down
4 changes: 4 additions & 0 deletions ports/geckolib/glue.rs
Expand Up @@ -181,6 +181,10 @@ pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {

// Initialize the dummy url data
unsafe { DUMMY_URL_DATA = dummy_url_data; }

// Set the system page size.
let page_size = unsafe { bindings::Gecko_GetSystemPageSize() };
::hashglobe::SYSTEM_PAGE_SIZE.store(page_size, ::std::sync::atomic::Ordering::Relaxed);
}

#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions ports/geckolib/lib.rs
Expand Up @@ -6,6 +6,7 @@

extern crate cssparser;
extern crate env_logger;
extern crate hashglobe;
extern crate libc;
#[macro_use] extern crate log;
extern crate malloc_size_of;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/stylo/Cargo.toml
Expand Up @@ -17,6 +17,7 @@ cssparser = "0.21.1"
env_logger = "0.4"
euclid = "0.15"
geckoservo = {path = "../../../ports/geckolib"}
hashglobe = {path = "../../../components/hashglobe"}
libc = "0.2"
log = {version = "0.3.5", features = ["release_max_level_info"]}
malloc_size_of = {path = "../../../components/malloc_size_of"}
Expand Down
1 change: 1 addition & 0 deletions tests/unit/stylo/lib.rs
Expand Up @@ -6,6 +6,7 @@ extern crate atomic_refcell;
extern crate cssparser;
extern crate env_logger;
extern crate geckoservo;
extern crate hashglobe;
#[macro_use] extern crate log;
extern crate malloc_size_of;
extern crate selectors;
Expand Down

0 comments on commit ef04289

Please sign in to comment.