mirror of
https://github.com/AmbiML/sparrow-kata-full.git
synced 2025-08-19 13:46:54 +00:00
MemoryManager: sort untyped slabs by available space
Change-Id: I3ee5a717c506f8a969dd7e3465ad612863835b7a GitOrigin-RevId: 4f75f4a24d6a4a72dd4fcf3879bae342eee0ce7d
This commit is contained in:
parent
daa3bb819c
commit
326ec0d6c9
@ -51,19 +51,19 @@ const UNTYPED_SLAB_CAPACITY: usize = 64; // # slabs kept inline
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct UntypedSlab {
|
struct UntypedSlab {
|
||||||
pub size_bits: usize, // NB: only used to sort
|
pub size_bits: usize, // NB: only used to sort
|
||||||
|
pub free_bytes: usize, // Available space in slab
|
||||||
pub _base_paddr: seL4_Word, // Physical address of slab start
|
pub _base_paddr: seL4_Word, // Physical address of slab start
|
||||||
pub _last_paddr: seL4_Word, // Physical address of slab end
|
pub _last_paddr: seL4_Word, // Physical address of slab end
|
||||||
pub cptr: seL4_CPtr, // seL4 untyped object
|
pub cptr: seL4_CPtr, // seL4 untyped object
|
||||||
pub _next_paddr: seL4_Word, // Physical address of next available chunk
|
|
||||||
}
|
}
|
||||||
impl UntypedSlab {
|
impl UntypedSlab {
|
||||||
fn new(ut: &seL4_UntypedDesc, cptr: seL4_CPtr) -> Self {
|
fn new(ut: &seL4_UntypedDesc, free_bytes: usize, cptr: seL4_CPtr) -> Self {
|
||||||
UntypedSlab {
|
UntypedSlab {
|
||||||
size_bits: ut.size_bits(),
|
size_bits: ut.size_bits(),
|
||||||
|
free_bytes,
|
||||||
_base_paddr: ut.paddr,
|
_base_paddr: ut.paddr,
|
||||||
_last_paddr: ut.paddr + (1 << ut.size_bits()),
|
_last_paddr: ut.paddr + (1 << ut.size_bits()),
|
||||||
cptr,
|
cptr,
|
||||||
_next_paddr: ut.paddr,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn _size(&self) -> usize { l2tob(self.size_bits) }
|
fn _size(&self) -> usize { l2tob(self.size_bits) }
|
||||||
@ -123,30 +123,31 @@ impl MemoryManager {
|
|||||||
for (ut_index, ut) in untypeds.iter().enumerate() {
|
for (ut_index, ut) in untypeds.iter().enumerate() {
|
||||||
#[cfg(feature = "CONFIG_NOISY_UNTYPEDS")]
|
#[cfg(feature = "CONFIG_NOISY_UNTYPEDS")]
|
||||||
log::info!("slot {} {:?}", slots.start + ut_index, ut);
|
log::info!("slot {} {:?}", slots.start + ut_index, ut);
|
||||||
|
let slab_size = l2tob(ut.size_bits());
|
||||||
if ut.is_device() {
|
if ut.is_device() {
|
||||||
m._device_untypeds
|
m._device_untypeds
|
||||||
.push(UntypedSlab::new(ut, slots.start + ut_index));
|
.push(UntypedSlab::new(ut, slab_size, slots.start + ut_index));
|
||||||
} else {
|
} else {
|
||||||
if ut.is_tainted() {
|
if ut.is_tainted() {
|
||||||
revoke_cap(slots.start + ut_index).expect("revoke untyped");
|
revoke_cap(slots.start + ut_index).expect("revoke untyped");
|
||||||
}
|
}
|
||||||
m.untypeds
|
|
||||||
.push(UntypedSlab::new(ut, slots.start + ut_index));
|
|
||||||
// NB: must get current state of ut as it will reflect resources
|
// NB: must get current state of ut as it will reflect resources
|
||||||
// allocated before we run.
|
// allocated before we run.
|
||||||
let info = untyped_describe(slots.start + ut_index);
|
let info = untyped_describe(slots.start + ut_index);
|
||||||
assert_eq!(info.sizeBits, ut.size_bits());
|
assert_eq!(info.sizeBits, ut.size_bits());
|
||||||
let size = l2tob(info.sizeBits);
|
|
||||||
// We only have the remainder available for allocations.
|
// We only have the remainder available for allocations.
|
||||||
|
m.untypeds
|
||||||
|
.push(UntypedSlab::new(ut, info.remainingBytes, slots.start + ut_index));
|
||||||
m.total_bytes += info.remainingBytes;
|
m.total_bytes += info.remainingBytes;
|
||||||
|
|
||||||
// Use overhead to track memory allocated out of our control.
|
// Use overhead to track memory allocated out of our control.
|
||||||
m.overhead_bytes += size - info.remainingBytes;
|
m.overhead_bytes += slab_size - info.remainingBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sort non-device slabs by descending size.
|
// Sort non-device slabs by descending amount of free space.
|
||||||
// TODO(sleffler): assumes slabs are empty, maybe sort by available space
|
|
||||||
m.untypeds
|
m.untypeds
|
||||||
.sort_unstable_by(|a, b| b.size_bits().cmp(&a.size_bits()));
|
.sort_unstable_by(|a, b| b.free_bytes.cmp(&a.free_bytes));
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user