Skip to content

Commit

Permalink
Unbounded Number of Heap Partitions for 64-Bit (#4556)
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-blaeser authored Jun 26, 2024
1 parent 66cdd22 commit 14ca175
Show file tree
Hide file tree
Showing 18 changed files with 373 additions and 148 deletions.
10 changes: 8 additions & 2 deletions rts/motoko-rts-tests/src/gc/incremental/partitioned_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ unsafe fn iterate_partition(
unsafe fn test_evacuation_plan(heap: &mut PartitionedTestHeap, occupied_partitions: usize) {
println!(" Test evacuation plan...");
unmark_all_objects(heap);
heap.inner.plan_evacuations();
heap.inner.plan_evacuations(&mut heap.memory);
let mut iterator = PartitionedHeapIterator::new(&heap.inner);
while iterator.has_partition() {
let partition = iterator.current_partition(&heap.inner);
Expand Down Expand Up @@ -204,6 +204,11 @@ unsafe fn count_objects_in_partition(

fn test_close_partition(heap: &mut PartitionedTestHeap) {
println!(" Test close partition...");
// Due to Rust borrow check restrictions, preceding `plan_evacuations`
// allocates directly in `heap.memory` without synchronizing the heap
// pointer in `heap`. Therefore, re-align the heap pointer of `heap`
// with `heap.memory`.
heap.allocate_blob(0);
test_close_partition_multi_word(heap);
test_close_partition_single_word(heap);
}
Expand Down Expand Up @@ -290,7 +295,7 @@ unsafe fn test_allocation_sizes(sizes: &[usize], number_of_partitions: usize) {
);
iterate_large_objects(&heap.inner, sizes);
unmark_all_objects(&mut heap);
heap.inner.plan_evacuations();
heap.inner.plan_evacuations(&mut heap.memory);
heap.inner.collect_large_objects();
heap.inner.complete_collection();
heap.inner.start_collection(&mut heap.memory, &mut time);
Expand Down Expand Up @@ -403,6 +408,7 @@ impl PartitionedTestHeap {
let mut memory = TestMemory::new(Bytes(size).to_words());
let heap_base = memory.heap_base();
let inner = unsafe { PartitionedHeap::new(&mut memory, heap_base) };
assert_eq!(inner.base_address(), heap_base);
PartitionedTestHeap { memory, inner }
}

Expand Down
6 changes: 5 additions & 1 deletion rts/motoko-rts-tests/src/gc/incremental/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ pub fn test() {
}

fn sort_test(array: &mut [usize]) {
sort(array, &|left, right| left.cmp(&right));
unsafe {
sort(array.as_mut_ptr(), array.len(), &|left, right| {
left.cmp(&right)
});
}
check_sorted(array);
}

Expand Down
8 changes: 4 additions & 4 deletions rts/motoko-rts/src/gc/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ unsafe fn incremental_gc<M: Memory>(mem: &mut M) {

#[cfg(feature = "ic")]
unsafe fn should_start() -> bool {
use self::partitioned_heap::{MAXIMUM_MEMORY_SIZE, PARTITION_SIZE};
use self::partitioned_heap::PARTITION_SIZE;
use crate::memory::ic;

const CRITICAL_HEAP_LIMIT: Bytes<usize> = Bytes(MAXIMUM_MEMORY_SIZE.0 / 10 * 8); // 80%
const CRITICAL_HEAP_LIMIT: Bytes<usize> = Bytes(ic::MAIN_MEMORY_LIMIT.0 / 10 * 8); // 80%
const CRITICAL_GROWTH_THRESHOLD: f64 = 0.01;
const MEDIUM_HEAP_LIMIT: Bytes<usize> = Bytes(MAXIMUM_MEMORY_SIZE.0 / 2); // 50%
const MEDIUM_HEAP_LIMIT: Bytes<usize> = Bytes(ic::MAIN_MEMORY_LIMIT.0 / 2); // 50%
const MEDIUM_GROWTH_THRESHOLD: f64 = 0.35;
const LOW_GROWTH_THRESHOLD: f64 = 0.65;

Expand Down Expand Up @@ -275,7 +275,7 @@ impl<'a, M: Memory + 'a> IncrementalGC<'a, M> {
debug_assert!(self.mark_completed());
MarkIncrement::<M>::complete_phase(self.state);
self.state.phase = Phase::Evacuate;
EvacuationIncrement::<M>::start_phase(self.state);
EvacuationIncrement::<M>::start_phase(self.mem, self.state);
}

unsafe fn evacuation_completed(&self) -> bool {
Expand Down
Loading

0 comments on commit 14ca175

Please sign in to comment.