implemented first variant with pool spillover
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit
Some checks failed
Rust/sat-rs/pipeline/head There was a failure building this commit
This commit is contained in:
parent
9c310e7a36
commit
369c1c4ecc
@ -368,11 +368,15 @@ mod alloc_mod {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct StaticPoolConfig {
|
pub struct StaticPoolConfig {
|
||||||
cfg: Vec<(NumBlocks, usize)>,
|
cfg: Vec<(NumBlocks, usize)>,
|
||||||
|
spill_to_higher_subpools: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StaticPoolConfig {
|
impl StaticPoolConfig {
|
||||||
pub fn new(cfg: Vec<(NumBlocks, usize)>) -> Self {
|
pub fn new(cfg: Vec<(NumBlocks, usize)>, spill_to_higher_subpools: bool) -> Self {
|
||||||
StaticPoolConfig { cfg }
|
StaticPoolConfig {
|
||||||
|
cfg,
|
||||||
|
spill_to_higher_subpools,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cfg(&self) -> &Vec<(NumBlocks, usize)> {
|
pub fn cfg(&self) -> &Vec<(NumBlocks, usize)> {
|
||||||
@ -456,7 +460,14 @@ mod alloc_mod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reserve(&mut self, data_len: usize) -> Result<StaticPoolAddr, StoreError> {
|
fn reserve(&mut self, data_len: usize) -> Result<StaticPoolAddr, StoreError> {
|
||||||
let subpool_idx = self.find_subpool(data_len, 0)?;
|
let mut subpool_idx = self.find_subpool(data_len, 0)?;
|
||||||
|
|
||||||
|
if self.pool_cfg.spill_to_higher_subpools {
|
||||||
|
while let Err(StoreError::StoreFull(_)) = self.find_empty(subpool_idx) {
|
||||||
|
subpool_idx += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let (slot, size_slot_ref) = self.find_empty(subpool_idx)?;
|
let (slot, size_slot_ref) = self.find_empty(subpool_idx)?;
|
||||||
*size_slot_ref = data_len;
|
*size_slot_ref = data_len;
|
||||||
Ok(StaticPoolAddr {
|
Ok(StaticPoolAddr {
|
||||||
@ -628,22 +639,22 @@ mod tests {
|
|||||||
|
|
||||||
fn basic_small_pool() -> StaticMemoryPool {
|
fn basic_small_pool() -> StaticMemoryPool {
|
||||||
// 4 buckets of 4 bytes, 2 of 8 bytes and 1 of 16 bytes
|
// 4 buckets of 4 bytes, 2 of 8 bytes and 1 of 16 bytes
|
||||||
let pool_cfg = StaticPoolConfig::new(vec![(4, 4), (2, 8), (1, 16)]);
|
let pool_cfg = StaticPoolConfig::new(vec![(4, 4), (2, 8), (1, 16)], false);
|
||||||
StaticMemoryPool::new(pool_cfg)
|
StaticMemoryPool::new(pool_cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cfg() {
|
fn test_cfg() {
|
||||||
// Values where number of buckets is 0 or size is too large should be removed
|
// Values where number of buckets is 0 or size is too large should be removed
|
||||||
let mut pool_cfg = StaticPoolConfig::new(vec![(0, 0), (1, 0), (2, POOL_MAX_SIZE)]);
|
let mut pool_cfg = StaticPoolConfig::new(vec![(0, 0), (1, 0), (2, POOL_MAX_SIZE)], false);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert_eq!(*pool_cfg.cfg(), vec![(1, 0)]);
|
assert_eq!(*pool_cfg.cfg(), vec![(1, 0)]);
|
||||||
// Entries should be ordered according to bucket size
|
// Entries should be ordered according to bucket size
|
||||||
pool_cfg = StaticPoolConfig::new(vec![(16, 6), (32, 3), (8, 12)]);
|
pool_cfg = StaticPoolConfig::new(vec![(16, 6), (32, 3), (8, 12)], false);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert_eq!(*pool_cfg.cfg(), vec![(32, 3), (16, 6), (8, 12)]);
|
assert_eq!(*pool_cfg.cfg(), vec![(32, 3), (16, 6), (8, 12)]);
|
||||||
// Unstable sort is used, so order of entries with same block length should not matter
|
// Unstable sort is used, so order of entries with same block length should not matter
|
||||||
pool_cfg = StaticPoolConfig::new(vec![(12, 12), (14, 16), (10, 12)]);
|
pool_cfg = StaticPoolConfig::new(vec![(12, 12), (14, 16), (10, 12)], false);
|
||||||
pool_cfg.sanitize();
|
pool_cfg.sanitize();
|
||||||
assert!(
|
assert!(
|
||||||
*pool_cfg.cfg() == vec![(12, 12), (10, 12), (14, 16)]
|
*pool_cfg.cfg() == vec![(12, 12), (10, 12), (14, 16)]
|
||||||
|
Loading…
Reference in New Issue
Block a user