Add allocator usage information
This commit is contained in:
@@ -8,6 +8,7 @@ use crate::{
|
||||
BumpAllocator,
|
||||
FrameAllocator,
|
||||
FrameCount,
|
||||
FrameUsage,
|
||||
PhysicalAddress,
|
||||
VirtualAddress,
|
||||
};
|
||||
@@ -268,4 +269,19 @@ impl<A: Arch> FrameAllocator for BuddyAllocator<A> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn usage(&self) -> FrameUsage {
|
||||
let mut total = 0;
|
||||
let mut used = 0;
|
||||
for i in 0 .. Self::BUDDY_ENTRIES {
|
||||
let virt = self.table_virt.add(i * mem::size_of::<BuddyEntry<A>>());
|
||||
let entry = A::read::<BuddyEntry<A>>(virt);
|
||||
total += entry.size >> A::PAGE_SHIFT;
|
||||
used += entry.used;
|
||||
}
|
||||
FrameUsage {
|
||||
used: FrameCount::new(used),
|
||||
total: FrameCount::new(total),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use crate::{
|
||||
Arch,
|
||||
FrameAllocator,
|
||||
FrameCount,
|
||||
FrameUsage,
|
||||
MemoryArea,
|
||||
PhysicalAddress,
|
||||
};
|
||||
@@ -56,4 +57,16 @@ impl<A: Arch> FrameAllocator for BumpAllocator<A> {
|
||||
unsafe fn free(&mut self, _address: PhysicalAddress, _count: FrameCount) {
|
||||
unimplemented!("BumpAllocator::free not implemented");
|
||||
}
|
||||
|
||||
unsafe fn usage(&self) -> FrameUsage {
|
||||
let mut total = 0;
|
||||
for area in self.areas.iter() {
|
||||
total += area.size >> A::PAGE_SHIFT;
|
||||
}
|
||||
let used = self.offset >> A::PAGE_SHIFT;
|
||||
FrameUsage {
|
||||
used: FrameCount::new(used),
|
||||
total: FrameCount::new(total),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,25 @@ impl FrameCount {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FrameUsage {
|
||||
used: FrameCount,
|
||||
total: FrameCount,
|
||||
}
|
||||
|
||||
impl FrameUsage {
|
||||
pub fn used(&self) -> FrameCount {
|
||||
self.used
|
||||
}
|
||||
|
||||
pub fn free(&self) -> FrameCount {
|
||||
FrameCount(self.total.0 - self.used.0)
|
||||
}
|
||||
|
||||
pub fn total(&self) -> FrameCount {
|
||||
self.total
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FrameAllocator {
|
||||
unsafe fn allocate(&mut self, count: FrameCount) -> Option<PhysicalAddress>;
|
||||
|
||||
@@ -32,4 +51,6 @@ pub trait FrameAllocator {
|
||||
unsafe fn free_one(&mut self, address: PhysicalAddress) {
|
||||
self.free(address, FrameCount::new(1));
|
||||
}
|
||||
|
||||
unsafe fn usage(&self) -> FrameUsage;
|
||||
}
|
||||
|
||||
@@ -253,6 +253,12 @@ unsafe fn new_tables<A: Arch>(areas: &'static [MemoryArea]) {
|
||||
flush_all.consume(flush);
|
||||
}
|
||||
flush_all.flush();
|
||||
|
||||
let usage = allocator.usage();
|
||||
println!("Allocator usage:");
|
||||
println!(" Used: {}", format_size(usage.used().data() * A::PAGE_SIZE));
|
||||
println!(" Free: {}", format_size(usage.free().data() * A::PAGE_SIZE));
|
||||
println!(" Total: {}", format_size(usage.total().data() * A::PAGE_SIZE));
|
||||
}
|
||||
|
||||
unsafe fn inner<A: Arch>() {
|
||||
|
||||
Reference in New Issue
Block a user