disable delay allocating frame, remove `memory_set_record`

master
WangRunji 6 years ago
parent 2db453556d
commit 52fe93188d

@ -166,22 +166,17 @@ impl MemoryArea {
}
}
None => {
info!("map delayed!");
for page in Page::range_of(self.start_addr, self.end_addr) {
let addr = page.start_address();
//let target = T::alloc_frame().expect("failed to allocate frame");
//self.flags.apply(pt.map(addr, target));
let target = T::alloc_frame().expect("failed to allocate frame");
self.flags.apply(pt.map(addr, target));
// for frame delayed allocation
{
let entry = pt.map(addr,0);
self.flags.apply(entry);
}
let entry = pt.get_entry(addr).expect("fail to get entry");
entry.set_present(false);
entry.update();
// let entry = pt.map(addr,0);
// self.flags.apply(entry);
// let entry = pt.get_entry(addr).expect("fail to get entry");
// entry.set_present(false);
// entry.update();
}
info!("finish map delayed!");
}
};
}

@ -1 +0,0 @@
Subproject commit a37a65fa13a00c5aa0068c3f2b5d55af6a37dd93

@ -1,6 +1,6 @@
use riscv::register::*;
pub use self::context::*;
use crate::memory::{MemorySet, InactivePageTable0, memory_set_record};
use crate::memory::{MemorySet, InactivePageTable0};
use log::*;
#[path = "context.rs"]

@ -3,8 +3,6 @@ use alloc::{boxed::Box, sync::Arc, string::String, collections::VecDeque, vec::V
use core::any::Any;
use core::slice;
use lazy_static::lazy_static;
use crate::memory::{MemorySet, InactivePageTable0, memory_set_record};
use crate::process::context::memory_set_map_swappable;
#[cfg(target_arch = "x86_64")]
use crate::arch::driver::ide;
use crate::sync::Condvar;

@ -48,12 +48,6 @@ pub mod arch;
pub fn kmain() -> ! {
processor().run();
// thread::test::local_key();
// thread::test::unpack();
// sync::test::philosopher_using_mutex();
// sync::test::philosopher_using_monitor();
// sync::mpsc::test::test_all();
}
/// Global heap allocator

@ -30,15 +30,6 @@ pub type FrameAlloc = BitAlloc64K;
lazy_static! {
pub static ref FRAME_ALLOCATOR: SpinNoIrqLock<FrameAlloc> = SpinNoIrqLock::new(FrameAlloc::default());
}
// record the user memory set for pagefault function (swap in/out and frame delayed allocate) temporarily when page fault in new_user() or fork() function
// after the process is set we can use use crate::processor() to get the inactive page table
lazy_static! {
pub static ref MEMORY_SET_RECORD: SpinNoIrqLock<VecDeque<usize>> = SpinNoIrqLock::new(VecDeque::default());
}
pub fn memory_set_record() -> MutexGuard<'static, VecDeque<usize>, SpinNoIrq> {
MEMORY_SET_RECORD.lock()
}
lazy_static! {
static ref ACTIVE_TABLE: SpinNoIrqLock<CowExt<ActivePageTable>> = SpinNoIrqLock::new(unsafe {
@ -115,43 +106,20 @@ pub fn page_fault_handler(addr: usize) -> bool {
//unsafe { ACTIVE_TABLE_SWAP.force_unlock(); }
info!("active page table token in pg fault is {:x?}", ActivePageTable::token());
let mmset_record = memory_set_record();
let id = mmset_record.iter()
.position(|x| unsafe{(*(x.clone() as *mut MemorySet)).get_page_table_mut().token() == ActivePageTable::token()});
/*LAB3 EXERCISE 1: YOUR STUDENT NUMBER
* handle the frame deallocated
*/
match id {
Some(targetid) => {
info!("get id from memroy set recorder.");
let mmset_ptr = mmset_record.get(targetid).expect("fail to get mmset_ptr").clone();
// get current mmset
let current_mmset = unsafe{&mut *(mmset_ptr as *mut MemorySet)};
//check whether the vma is legal
if current_mmset.find_area(addr).is_none(){
return false;
}
let pt = current_mmset.get_page_table_mut();
info!("pt got!");
if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, false, || alloc_frame().expect("fail to alloc frame")){
return true;
}
},
None => {
info!("get pt from processor()");
if process().get_memory_set_mut().find_area(addr).is_none(){
return false;
}
let pt = process().get_memory_set_mut().get_page_table_mut();
info!("pt got");
if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, true, || alloc_frame().expect("fail to alloc frame")){
return true;
}
},
};
info!("get pt from processor()");
if process().memory_set.find_area(addr).is_none(){
return false;
}
let pt = process().memory_set.get_page_table_mut();
info!("pt got");
if active_table_swap().page_fault_handler(pt as *mut InactivePageTable0, addr, true, || alloc_frame().expect("fail to alloc frame")){
return true;
}
//////////////////////////////////////////////////////////////////////////////

@ -1,5 +1,5 @@
use crate::arch::interrupt::{TrapFrame, Context as ArchContext};
use crate::memory::{MemoryArea, MemoryAttr, MemorySet, KernelStack, active_table_swap, alloc_frame, InactivePageTable0, memory_set_record};
use crate::memory::{MemoryArea, MemoryAttr, MemorySet, KernelStack, active_table_swap, alloc_frame, InactivePageTable0};
use xmas_elf::{ElfFile, header, program::{Flags, ProgramHeader, Type}};
use core::fmt::{Debug, Error, Formatter};
use alloc::{boxed::Box, collections::BTreeMap, vec::Vec, sync::Arc, string::String};
@ -66,14 +66,6 @@ impl ContextImpl {
}
/// Make a new user thread from ELF data
/*
* @param:
* data: the ELF data stream
* @brief:
* make a new thread from ELF data
* @retval:
* the new user thread Context
*/
pub fn new_user<'a, Iter>(data: &[u8], args: Iter) -> Box<ContextImpl>
where Iter: Iterator<Item=&'a str>
{
@ -95,12 +87,6 @@ impl ContextImpl {
// Make page table
let mut memory_set = memory_set_from(&elf);
// add the new memory set to the recorder
let mmset_ptr = ((&mut memory_set) as * mut MemorySet) as usize;
memory_set_record().push_back(mmset_ptr);
//let id = memory_set_record().iter()
// .position(|x| unsafe { info!("current memory set record include {:x?}, {:x?}", x, (*(x.clone() as *mut MemorySet)).get_page_table_mut().token()); false });
memory_set.push(MemoryArea::new(ustack_buttom, ustack_top, MemoryAttr::default().user(), "user_stack"));
trace!("{:#x?}", memory_set);
@ -126,14 +112,11 @@ impl ContextImpl {
}
let kstack = KernelStack::new();
{
let mut mmset_record = memory_set_record();
let id = mmset_record.iter()
.position(|x| x.clone() == mmset_ptr).expect("id not exist");
mmset_record.remove(id);
}
let mut ret = Box::new(ContextImpl {
//set the user Memory pages in the memory set swappable
memory_set_map_swappable(&mut memory_set);
Box::new(ContextImpl {
arch: unsafe {
ArchContext::new_user_thread(
entry_addr, ustack_top, kstack.top(), is32, memory_set.token())
@ -142,10 +125,7 @@ impl ContextImpl {
kstack,
files: BTreeMap::default(),
cwd: String::new(),
});
//set the user Memory pages in the memory set swappable
memory_set_map_swappable(ret.get_memory_set_mut());
ret
})
}
/// Fork
@ -154,10 +134,6 @@ impl ContextImpl {
// Clone memory set, make a new page table
let mut memory_set = self.memory_set.clone();
info!("finish mmset clone in fork!");
// add the new memory set to the recorder
info!("fork! new page table token: {:x?}", memory_set.token());
let mmset_ptr = ((&mut memory_set) as * mut MemorySet) as usize;
memory_set_record().push_back(mmset_ptr);
info!("before copy data to temp space");
// Copy data to temp space
@ -180,32 +156,17 @@ impl ContextImpl {
info!("temporary copy data!");
let kstack = KernelStack::new();
// remove the raw pointer for the memory set in memory_set_record
{
let mut mmset_record = memory_set_record();
let id = mmset_record.iter()
.position(|x| x.clone() == mmset_ptr).expect("id not exist");
mmset_record.remove(id);
}
memory_set_map_swappable(&mut memory_set);
info!("FORK() finsihed!");
let mut ret = Box::new(ContextImpl {
Box::new(ContextImpl {
arch: unsafe { ArchContext::new_fork(tf, kstack.top(), memory_set.token()) },
memory_set,
kstack,
files: BTreeMap::default(),
cwd: String::new(),
});
memory_set_map_swappable(ret.get_memory_set_mut());
info!("FORK() finsihed!");
ret
}
pub fn get_memory_set_mut(&mut self) -> &mut MemorySet {
&mut self.memory_set
})
}
}
impl Drop for ContextImpl{

Loading…
Cancel
Save