mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 16:25:40 +00:00
Make allocator limit available for the runtime (#9393)
* make allocator limit available * better inner doc * move const * fmt Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
committed by
GitHub
parent
9c173724fa
commit
23e8088c1c
@@ -68,6 +68,7 @@
|
|||||||
//! sizes.
|
//! sizes.
|
||||||
|
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
pub use sp_core::MAX_POSSIBLE_ALLOCATION;
|
||||||
use sp_wasm_interface::{Pointer, WordSize};
|
use sp_wasm_interface::{Pointer, WordSize};
|
||||||
use std::{
|
use std::{
|
||||||
convert::{TryFrom, TryInto},
|
convert::{TryFrom, TryInto},
|
||||||
@@ -95,15 +96,13 @@ const LOG_TARGET: &'static str = "wasm-heap";
|
|||||||
// The minimum possible allocation size is chosen to be 8 bytes because in that case we would have
|
// The minimum possible allocation size is chosen to be 8 bytes because in that case we would have
|
||||||
// easier time to provide the guaranteed alignment of 8.
|
// easier time to provide the guaranteed alignment of 8.
|
||||||
//
|
//
|
||||||
// The maximum possible allocation size was chosen rather arbitrary. 32 MiB should be enough for
|
// The maximum possible allocation size is set in the primitives to 32MiB.
|
||||||
// everybody.
|
|
||||||
//
|
//
|
||||||
// N_ORDERS - represents the number of orders supported.
|
// N_ORDERS - represents the number of orders supported.
|
||||||
//
|
//
|
||||||
// This number corresponds to the number of powers between the minimum possible allocation and
|
// This number corresponds to the number of powers between the minimum possible allocation and
|
||||||
// maximum possible allocation, or: 2^3...2^25 (both ends inclusive, hence 23).
|
// maximum possible allocation, or: 2^3...2^25 (both ends inclusive, hence 23).
|
||||||
const N_ORDERS: usize = 23;
|
const N_ORDERS: usize = 23;
|
||||||
const MAX_POSSIBLE_ALLOCATION: u32 = 33554432; // 2^25 bytes, 32 MiB
|
|
||||||
const MIN_POSSIBLE_ALLOCATION: u32 = 8; // 2^3 bytes, 8 bytes
|
const MIN_POSSIBLE_ALLOCATION: u32 = 8; // 2^3 bytes, 8 bytes
|
||||||
|
|
||||||
/// The exponent for the power of two sized block adjusted to the minimum size.
|
/// The exponent for the power of two sized block adjusted to the minimum size.
|
||||||
@@ -922,4 +921,13 @@ mod tests {
|
|||||||
assert!(heap.poisoned);
|
assert!(heap.poisoned);
|
||||||
assert!(heap.deallocate(mem.as_mut(), alloc_ptr).is_err());
|
assert!(heap.deallocate(mem.as_mut(), alloc_ptr).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_n_orders() {
|
||||||
|
// Test that N_ORDERS is consistent with min and max possible allocation.
|
||||||
|
assert_eq!(
|
||||||
|
MIN_POSSIBLE_ALLOCATION * 2u32.pow(N_ORDERS as u32 - 1),
|
||||||
|
MAX_POSSIBLE_ALLOCATION
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -455,3 +455,8 @@ macro_rules! impl_maybe_marker {
|
|||||||
)+
|
)+
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The maximum number of bytes that can be allocated at one time.
|
||||||
|
// The maximum possible allocation size was chosen rather arbitrary, 32 MiB should be enough for
|
||||||
|
// everybody.
|
||||||
|
pub const MAX_POSSIBLE_ALLOCATION: u32 = 33554432; // 2^25 bytes, 32 MiB
|
||||||
|
|||||||
Reference in New Issue
Block a user