Add page handler for swap in/out in riscv32's pagefault

master
lcy1996 6 years ago
parent 0a7ec18701
commit 0a81014007

@ -4,7 +4,8 @@
//! Used to test page table operation
use super::Swapper;
use alloc::btree_map::BTreeMap;
//use alloc::btree_map::BTreeMap;
use alloc::collections::BTreeMap;
use core::mem::uninitialized;
const PAGE_SIZE: usize = 4096;

@ -13,10 +13,11 @@ use core::ops::{Deref, DerefMut};
//pub use self::fifo::FifoSwapManager;
pub use self::enhanced_clock::EnhancedClockSwapManager;
mod fifo;
pub mod fifo;
mod enhanced_clock;
#[cfg(test)]
mod mock_swapper;
pub mod mock_swapper;
//#[cfg(test)]
//mod mock_swapper;
/// Manage all swappable pages, decide which to swap out
pub trait SwapManager {
@ -76,7 +77,7 @@ pub trait Swapper {
}
/// Wrapper for page table, supporting swap functions
struct SwapExt<T: PageTable, M: SwapManager, S: Swapper> {
pub struct SwapExt<T: PageTable, M: SwapManager, S: Swapper> {
page_table: T,
swap_manager: M,
swapper: S,

@ -73,7 +73,7 @@ pub extern fn rust_trap(tf: &mut TrapFrame) {
Trap::Exception(E::IllegalInstruction) => illegal_inst(tf),
Trap::Exception(E::UserEnvCall) => syscall(tf),
Trap::Exception(E::LoadPageFault) => page_fault(tf),
Trap::Exception(E::StoreFault) => page_fault(tf),
Trap::Exception(E::StorePageFault) => page_fault(tf),
Trap::Exception(E::InstructionPageFault) => page_fault(tf),
_ => ::trap::error(tf),
}

@ -6,6 +6,7 @@ use super::HEAP_ALLOCATOR;
use ucore_memory::{*, paging::PageTable};
use ucore_memory::cow::CowExt;
pub use ucore_memory::memory_set::{MemoryArea, MemoryAttr, MemorySet as MemorySet_, Stack};
use ucore_memory::swap::*;
pub type MemorySet = MemorySet_<InactivePageTable0>;
@ -52,6 +53,16 @@ pub fn active_table() -> MutexGuard<'static, CowExt<ActivePageTable>> {
ACTIVE_TABLE.lock()
}
// Page table for swpa in and out
lazy_static!{
static ref ACTIVE_TABLE_SWAP: Mutex<SwapExt<ActivePageTable, fifo::FifoSwapManager, mock_swapper::MockSwapper>> =
Mutex::new(unsafe{SwapExt::new(ActivePageTable::new(), fifo::FifoSwapManager::default(), mock_swapper::MockSwapper::default())});
}
pub fn active_table_swap() -> MutexGuard<'static, SwapExt<ActivePageTable, fifo::FifoSwapManager, mock_swapper::MockSwapper>>{
ACTIVE_TABLE_SWAP.lock()
}
/*
* @param:
* addr: the virtual address of the page fault
@ -63,7 +74,15 @@ pub fn active_table() -> MutexGuard<'static, CowExt<ActivePageTable>> {
pub fn page_fault_handler(addr: usize) -> bool {
// Handle copy on write
unsafe { ACTIVE_TABLE.force_unlock(); }
active_table().page_fault_handler(addr, || alloc_frame().unwrap())
if active_table().page_fault_handler(addr, || alloc_frame().unwrap()){
return true;
}
// handle the swap in/out
unsafe { ACTIVE_TABLE_SWAP.force_unlock(); }
if active_table_swap().page_fault_handler(addr, || alloc_frame()){
return true;
}
false
}
pub fn init_heap() {

Loading…
Cancel
Save