Fix bug in swap in/out. Address ailign to 4K.

master
lcy1996 6 years ago
parent 6652f8daf6
commit c5499a62c5

@ -13,12 +13,12 @@ impl SwapManager for FifoSwapManager {
fn tick(&mut self) {} fn tick(&mut self) {}
fn push(&mut self, frame: Frame) { fn push(&mut self, frame: Frame) {
debug!("SwapManager push token: {:x?} vaddr: {:x?}", frame.get_token(), frame.get_virtaddr()); info!("SwapManager push token: {:x?} vaddr: {:x?}", frame.get_token(), frame.get_virtaddr());
self.deque.push_back(frame); self.deque.push_back(frame);
} }
fn remove(&mut self, token: usize, addr: VirtAddr) { fn remove(&mut self, token: usize, addr: VirtAddr) {
debug!("SwapManager remove token: {:x?} vaddr: {:x?}", token, addr); info!("SwapManager remove token: {:x?} vaddr: {:x?}", token, addr);
let id = self.deque.iter() let id = self.deque.iter()
.position(|ref x| x.get_virtaddr() == addr && x.get_token() == token) .position(|ref x| x.get_virtaddr() == addr && x.get_token() == token)
.expect("address not found"); .expect("address not found");

@ -113,7 +113,7 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
let Self {ref mut page_table, ref mut swap_manager, ref mut swapper} = self; let Self {ref mut page_table, ref mut swap_manager, ref mut swapper} = self;
let targetpt = &mut *(pt); let targetpt = &mut *(pt);
let pttoken = { let pttoken = {
debug!("the target page table token is {:x?}", targetpt.token()); info!("SET_SWAPPABLE: the target page table token is {:x?}, addr is {:x?}", targetpt.token(), addr);
targetpt.token() targetpt.token()
}; };
targetpt.with(||{ targetpt.with(||{
@ -139,14 +139,14 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
** @param alloc_frame: the function to alloc a free physical frame for once ** @param alloc_frame: the function to alloc a free physical frame for once
*/ */
pub unsafe fn remove_from_swappable<T2: InactivePageTable>(&mut self, pt: *mut T2, addr: VirtAddr, alloc_frame: impl FnOnce() -> PhysAddr){ pub unsafe fn remove_from_swappable<T2: InactivePageTable>(&mut self, pt: *mut T2, addr: VirtAddr, alloc_frame: impl FnOnce() -> PhysAddr){
trace!("come into remove_from swappable"); info!("come into remove_from swappable");
let Self {ref mut page_table, ref mut swap_manager, ref mut swapper} = self; let Self {ref mut page_table, ref mut swap_manager, ref mut swapper} = self;
let targetpt = &mut *(pt); let targetpt = &mut *(pt);
let pttoken = { let pttoken = {
debug!("the target page table token is {:x?}", targetpt.token()); debug!("the target page table token is {:x?}", targetpt.token());
targetpt.token() targetpt.token()
}; };
debug!("try to change pagetable"); info!("try to change pagetable");
targetpt.with(||{ targetpt.with(||{
let token = { let token = {
let entry = page_table.get_entry(addr); let entry = page_table.get_entry(addr);
@ -301,7 +301,7 @@ impl<T: PageTable, M: SwapManager, S: Swapper> SwapExt<T, M, S> {
} }
if(swapin){ if(swapin){
unsafe { unsafe {
self.set_swappable(pt, addr); self.set_swappable(pt, addr & 0xfffff000);
} }
} }
//area.get_flags().apply(new_entry); this instruction may be used when hide attr is used //area.get_flags().apply(new_entry); this instruction may be used when hide attr is used

@ -225,7 +225,7 @@ impl ProcessManager {
self.wakeup(*waiter); self.wakeup(*waiter);
} }
//proc.context = None; proc.context = None;
} }
} }
fn new_vec_default<T: Default>(size: usize) -> Vec<T> { fn new_vec_default<T: Default>(size: usize) -> Vec<T> {

@ -1 +1 @@
Subproject commit f358204af01f2374ab6ed6ea059f724cd5f2fe6f Subproject commit a37a65fa13a00c5aa0068c3f2b5d55af6a37dd93

@ -130,7 +130,7 @@ impl ContextImpl {
let mut memory_set = self.memory_set.clone(); let mut memory_set = self.memory_set.clone();
info!("finish mmset clone in fork!"); info!("finish mmset clone in fork!");
// add the new memory set to the recorder // add the new memory set to the recorder
debug!("fork! new page table token: {:x?}", memory_set.token()); info!("fork! new page table token: {:x?}", memory_set.token());
let mmset_ptr = ((&mut memory_set) as * mut MemorySet) as usize; let mmset_ptr = ((&mut memory_set) as * mut MemorySet) as usize;
memory_set_record().push_back(mmset_ptr); memory_set_record().push_back(mmset_ptr);
@ -179,6 +179,7 @@ impl ContextImpl {
impl Drop for ContextImpl{ impl Drop for ContextImpl{
fn drop(&mut self){ fn drop(&mut self){
info!("come in to drop for ContextImpl");
// remove the new memory set to the recorder (deprecated in the latest version) // remove the new memory set to the recorder (deprecated in the latest version)
/* /*
let id = memory_set_record().iter() let id = memory_set_record().iter()
@ -251,6 +252,7 @@ fn memory_attr_from(elf_flags: Flags) -> MemoryAttr {
* map the memory area in the memory_set swappalbe, specially for the user process * map the memory area in the memory_set swappalbe, specially for the user process
*/ */
pub fn memory_set_map_swappable(memory_set: &mut MemorySet){ pub fn memory_set_map_swappable(memory_set: &mut MemorySet){
info!("COME INTO memory set map swappable!");
let pt = unsafe { let pt = unsafe {
memory_set.get_page_table_mut() as *mut InactivePageTable0 memory_set.get_page_table_mut() as *mut InactivePageTable0
}; };

Loading…
Cancel
Save