add some more tracking to the loader

this will give us some more pages to swap out beyond the initial
set of free pages.
This commit is contained in:
bunnie 2024-05-12 22:29:50 +08:00
parent a519bb2fa5
commit 8606d0ae83
2 changed files with 37 additions and 2 deletions

View file

@ -184,6 +184,28 @@ impl BootConfig {
panic!("Tried to change region {:08x} that isn't in defined memory!", addr);
}
#[cfg(feature = "swap")]
pub fn change_owner_tracking(&mut self, pid: XousPid, addr: usize, vaddr: usize) {
// First, check to see if the region is in RAM,
if addr >= self.sram_start as usize && addr < self.sram_start as usize + self.sram_size {
self.runtime_page_tracker[(addr - self.sram_start as usize) / PAGE_SIZE]
.update(pid, vaddr as u32);
return;
}
// The region isn't in RAM, so check the other memory regions.
let mut xpt_offset = 0;
for region in self.regions.iter() {
let rstart = region.start as usize;
let rlen = region.length as usize;
if addr >= rstart && addr < rstart + rlen {
self.extra_page_tracker[xpt_offset + (addr - rstart) / PAGE_SIZE] = XousPid::from(pid);
return;
}
xpt_offset += rlen / PAGE_SIZE;
}
panic!("Tried to change region {:08x} that isn't in defined memory!", addr);
}
/// Map the given page to the specified process table. If necessary,
/// allocate a new page.
///
@ -196,7 +218,10 @@ impl BootConfig {
}
assert!(!(phys == 0 && flags & FLG_VALID != 0), "cannot map zero page");
if flags & FLG_VALID != 0 {
#[cfg(not(feature = "swap"))]
self.change_owner(owner, phys);
#[cfg(feature = "swap")]
self.change_owner_tracking(owner, phys, virt);
}
match WORD_SIZE {
4 => self.map_page_32(root, phys, virt, flags, owner),

View file

@ -5,6 +5,7 @@ use aes_gcm_siv::Tag;
use crate::XousPid;
use crate::PAGE_SIZE;
use crate::SWAPPER_PID;
/// Virtual address fields:
/// 31 22 21 12 11 0
@ -113,13 +114,22 @@ pub const SWAP_FLG_WIRED: u32 = 0x1_00;
#[derive(Copy, Clone)]
pub struct SwapAlloc {
timestamp: u32,
_timestamp: u32,
/// virtual_page_number[19:0] | flags[3:0] | pid[7:0]
vpn: u32,
}
impl SwapAlloc {
pub fn from(pid: u8) -> SwapAlloc { SwapAlloc { timestamp: 0, vpn: pid as u32 | SWAP_FLG_WIRED } }
/// Allocations in the loader all start out as "wired", with no virtual address for tracking.
pub fn from(pid: u8) -> SwapAlloc { SwapAlloc { _timestamp: 0, vpn: pid as u32 | SWAP_FLG_WIRED } }
/// As the page tables are laid in, we can update the tracker with the virtual address. If
/// the page it belongs to the kernel or swapper, mark it as unswappable (WIRED)
pub fn update(&mut self, pid: u8, vaddr: u32) {
self.vpn = pid as u32
| vaddr & !0xFFFu32
| if (pid == 1) || (pid == SWAPPER_PID) { SWAP_FLG_WIRED } else { 0 };
}
/// This is a slight abuse of the naming system to provide us cross-compatibility with the case where the
/// structure is defined as an overload of the `u8` type