@@ -465,6 +465,9 @@ pub type mi_error_fun = Option<unsafe extern "C" fn(code: c_int, arg: *mut c_voi
465
465
/// Runtime options. All options are false by default.
466
466
pub type mi_option_t = c_int ;
467
467
468
+ /// Arena Id
469
+ pub type mi_arena_id_t = c_int ;
470
+
468
471
// Note: mimalloc doc website seems to have the order of show_stats and
469
472
// show_errors reversed as of 1.6.3, however what I have here is correct:
470
473
// https://github.com/microsoft/mimalloc/issues/266#issuecomment-653822341
@@ -941,6 +944,60 @@ extern "C" {
941
944
visitor : mi_block_visit_fun ,
942
945
arg : * mut c_void ,
943
946
) -> bool ;
947
+
948
+ /// Create a heap that only allocates in the specified arena
949
+ pub fn mi_heap_new_in_arena ( arena_id : mi_arena_id_t ) -> * mut mi_heap_t ;
950
+
951
+ /// Reserve OS memory for use by mimalloc. Reserved areas are used
952
+ /// before allocating from the OS again. By reserving a large area upfront,
953
+ /// allocation can be more efficient, and can be better managed on systems
954
+ /// without `mmap`/`VirtualAlloc` (like WASM for example).
955
+ ///
956
+ /// - `size` The size to reserve.
957
+ /// - `commit` Commit the memory upfront.
958
+ /// - `allow_large` Allow large OS pages (2MiB) to be used?
959
+ /// - `exclusive` Only allow allocations if specifically for this arena.
960
+ /// - `arena_id` Pointer who's value will be set to the new arena_id if successful.
961
+ ///
962
+ /// Returns 0 if successful, and an error code otherwise (e.g. `ENOMEM`)
963
+ pub fn mi_reserve_os_memory_ex (
964
+ size : usize ,
965
+ commit : bool ,
966
+ allow_large : bool ,
967
+ exclusive : bool ,
968
+ arena_id : * mut mi_arena_id_t ,
969
+ ) -> c_int ;
970
+
971
+ /// Manage a particular memory area for use by mimalloc.
972
+ /// This is just like `mi_reserve_os_memory_ex` except that the area should already be
973
+ /// allocated in some manner and available for use my mimalloc.
974
+ ///
975
+ /// # Safety
976
+ /// mimalloc will likely segfault when allocating from the arena if the arena `start` & `size`
977
+ /// aren't aligned with mimalloc's `MI_SEGMENT_ALIGN` (e.g. 32MB on x86_64 machines).
978
+ ///
979
+ /// - `start` Start of the memory area
980
+ /// - `size` The size of the memory area. Must be large than `MI_ARENA_BLOCK_SIZE` (e.g. 64MB
981
+ /// on x86_64 machines).
982
+ /// - `commit` Set true if the memory range is already commited.
983
+ /// - `is_large` Set true if the memory range consists of large files, or if the memory should
984
+ /// not be decommitted or protected (like rdma etc.).
985
+ /// - `is_zero` Set true if the memory range consists only of zeros.
986
+ /// - `numa_node` Possible associated numa node or `-1`.
987
+ /// - `exclusive` Only allow allocations if specifically for this arena.
988
+ /// - `arena_id` Pointer who's value will be set to the new arena_id if successful.
989
+ ///
990
+ /// Returns `true` if arena was successfully allocated
991
+ pub fn mi_manage_os_memory_ex (
992
+ start : * const c_void ,
993
+ size : usize ,
994
+ is_committed : bool ,
995
+ is_large : bool ,
996
+ is_zero : bool ,
997
+ numa_node : c_int ,
998
+ exclusive : bool ,
999
+ arena_id : * mut mi_arena_id_t ,
1000
+ ) -> bool ;
944
1001
}
945
1002
946
1003
#[ cfg( test) ]
0 commit comments