mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-21 12:56:36 +00:00
实现free指令+修复 mountfs的内存泄露问题(#394)
* 实现meminfo文件 * 成功实现free指令,添加了一些string有关函数,并进行一些无影响的小改动 * 解决内存泄露的问题:mountfs inode的wrap方法使用了Arc::into_raw而没有from_raw,导致inode始终无法释放 --------- Co-authored-by: LoGin <longjin@DragonOS.org> Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -65,6 +65,8 @@ impl<A> PageList<A> {
|
||||
pub struct BuddyAllocator<A> {
|
||||
// 存放每个阶的空闲“链表”的头部地址
|
||||
free_area: [PhysAddr; (MAX_ORDER - MIN_ORDER) as usize],
|
||||
/// 总页数
|
||||
total: PageFrameCount,
|
||||
phantom: PhantomData<A>,
|
||||
}
|
||||
|
||||
@ -227,9 +229,9 @@ impl<A: MemoryManagementArch> BuddyAllocator<A> {
|
||||
assert!(remain_bytes == 0);
|
||||
assert!(paddr == initial_bump_offset + pages_to_buddy.data() * A::PAGE_SIZE);
|
||||
|
||||
// Self::print_free_area(free_area);
|
||||
let allocator = Self {
|
||||
free_area,
|
||||
total: pages_to_buddy,
|
||||
phantom: PhantomData,
|
||||
};
|
||||
|
||||
@ -357,7 +359,6 @@ impl<A: MemoryManagementArch> BuddyAllocator<A> {
|
||||
}
|
||||
return None;
|
||||
};
|
||||
|
||||
let result: Option<PhysAddr> = alloc_in_specific_order(order as u8);
|
||||
// kdebug!("result={:?}", result);
|
||||
if result.is_some() {
|
||||
@ -662,7 +663,19 @@ impl<A: MemoryManagementArch> FrameAllocator for BuddyAllocator<A> {
|
||||
}
|
||||
|
||||
unsafe fn usage(&self) -> PageFrameUsage {
|
||||
todo!("BuddyAllocator::usage")
|
||||
let mut free_page_num: usize = 0;
|
||||
for index in 0..(MAX_ORDER - MIN_ORDER) {
|
||||
let mut pagelist: PageList<A> = Self::read_page(self.free_area[index]);
|
||||
loop {
|
||||
free_page_num += pagelist.entry_num << index;
|
||||
if pagelist.next_page.is_null() {
|
||||
break;
|
||||
}
|
||||
pagelist = Self::read_page(pagelist.next_page);
|
||||
}
|
||||
}
|
||||
let free = PageFrameCount::new(free_page_num);
|
||||
PageFrameUsage::new(self.total - free, self.total)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ impl PageFrameUsage {
|
||||
}
|
||||
// @brief 获取空闲的页帧数量
|
||||
pub fn free(&self) -> PageFrameCount {
|
||||
return PageFrameCount(self.total.0 - self.used.0);
|
||||
return self.total - self.used;
|
||||
}
|
||||
// @brief 获取总的页帧数量
|
||||
pub fn total(&self) -> PageFrameCount {
|
||||
|
Reference in New Issue
Block a user