实现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:
yuyi2439
2023-10-08 14:26:17 +08:00
committed by GitHub
parent afc95d5c25
commit 34e6d6c80f
16 changed files with 401 additions and 89 deletions

View File

@ -14,7 +14,7 @@ use crate::libs::lib_ui::screen_manager::scm_disable_put_to_window;
use crate::libs::printk::PrintkWriter;
use crate::libs::spinlock::SpinLock;
use crate::mm::allocator::page_frame::{FrameAllocator, PageFrameCount};
use crate::mm::allocator::page_frame::{FrameAllocator, PageFrameCount, PageFrameUsage};
use crate::mm::mmio_buddy::mmio_init;
use crate::{
arch::MMArch,
@ -512,10 +512,7 @@ pub fn test_buddy() {
pub struct LockedFrameAllocator;
impl FrameAllocator for LockedFrameAllocator {
unsafe fn allocate(
&mut self,
count: crate::mm::allocator::page_frame::PageFrameCount,
) -> Option<(PhysAddr, PageFrameCount)> {
unsafe fn allocate(&mut self, count: PageFrameCount) -> Option<(PhysAddr, PageFrameCount)> {
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock_irqsave() {
return allocator.allocate(count);
} else {
@ -523,19 +520,25 @@ impl FrameAllocator for LockedFrameAllocator {
}
}
unsafe fn free(
&mut self,
address: crate::mm::PhysAddr,
count: crate::mm::allocator::page_frame::PageFrameCount,
) {
unsafe fn free(&mut self, address: crate::mm::PhysAddr, count: PageFrameCount) {
assert!(count.data().is_power_of_two());
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock_irqsave() {
return allocator.free(address, count);
}
}
unsafe fn usage(&self) -> crate::mm::allocator::page_frame::PageFrameUsage {
todo!()
unsafe fn usage(&self) -> PageFrameUsage {
if let Some(ref mut allocator) = *INNER_ALLOCATOR.lock_irqsave() {
return allocator.usage();
} else {
panic!("usage error");
}
}
}
impl LockedFrameAllocator {
pub fn get_usage(&self) -> PageFrameUsage {
unsafe { self.usage() }
}
}