@@ -5,10 +5,12 @@ use std::{
55 ptr:: NonNull ,
66} ;
77
8- use crate :: Allocator ;
8+ use crate :: {
9+ Allocator ,
10+ fixed_size_constants:: { BUFFER_ALIGN , BUFFER_SIZE } ,
11+ } ;
912
1013const TWO_GIB : usize = 1 << 31 ;
11- const FOUR_GIB : usize = 1 << 32 ;
1214
1315// What we ideally want is an allocation 2 GiB in size, aligned on 4 GiB.
1416// But system allocator on Mac OS refuses allocations with 4 GiB alignment.
@@ -25,10 +27,8 @@ const FOUR_GIB: usize = 1 << 32;
2527// Could just use that built-in workaround, rather than implementing our own, or allocate a 6 GiB chunk
2628// with alignment 16, to skip Rust's built-in workaround.
2729// Note: Rust's workaround will likely commit a whole page of memory, just to store the real pointer.
28- const ALLOC_SIZE : usize = FOUR_GIB ;
30+ const ALLOC_SIZE : usize = BUFFER_SIZE + TWO_GIB ;
2931const ALLOC_ALIGN : usize = TWO_GIB ;
30- const CHUNK_SIZE : usize = TWO_GIB ;
31- pub const CHUNK_ALIGN : usize = FOUR_GIB ;
3232
3333const ALLOC_LAYOUT : Layout = match Layout :: from_size_align ( ALLOC_SIZE , ALLOC_ALIGN ) {
3434 Ok ( layout) => layout,
@@ -71,12 +71,12 @@ impl FixedSizeAllocator {
7171 alloc_ptr. add ( offset)
7272 } ;
7373
74- debug_assert ! ( chunk_ptr. as_ptr( ) as usize % CHUNK_ALIGN == 0 ) ;
74+ debug_assert ! ( chunk_ptr. as_ptr( ) as usize % BUFFER_ALIGN == 0 ) ;
7575
76- // SAFETY: Memory region starting at `chunk_ptr` with `CHUNK_SIZE ` bytes is within
76+ // SAFETY: Memory region starting at `chunk_ptr` with `BUFFER_SIZE ` bytes is within
7777 // the allocation we just made.
7878 // `chunk_ptr` has high alignment (4 GiB). `size` is large and a high power of 2 (2 GiB).
79- let allocator = unsafe { Allocator :: from_raw_parts ( chunk_ptr, CHUNK_SIZE ) } ;
79+ let allocator = unsafe { Allocator :: from_raw_parts ( chunk_ptr, BUFFER_SIZE ) } ;
8080
8181 // Store pointer to original allocation, so it can be used to deallocate in `drop`
8282 Self { allocator : ManuallyDrop :: new ( allocator) , alloc_ptr }
0 commit comments