mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
make oom doom a feature
even though we can do it, I am not sure we should.
This commit is contained in:
parent
fa777b6198
commit
c9ac6142b5
2 changed files with 15 additions and 21 deletions
|
|
@ -35,6 +35,7 @@ precursor = ["utralib/precursor"]
|
||||||
hosted = ["utralib/hosted"]
|
hosted = ["utralib/hosted"]
|
||||||
renode = ["utralib/renode"]
|
renode = ["utralib/renode"]
|
||||||
swap-userspace-testing = []
|
swap-userspace-testing = []
|
||||||
|
oom-doom = []
|
||||||
|
|
||||||
debug-print = []
|
debug-print = []
|
||||||
debug-verbose = []
|
debug-verbose = []
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,13 @@ use xous::{MemoryFlags, MemoryRange, Message, Result, CID, PID, SID};
|
||||||
/// are imprecise, in that there is a chance that one target is active during another
|
/// are imprecise, in that there is a chance that one target is active during another
|
||||||
/// invocation of a routine. This is because the hard OOM handler is entirely asynchronous
|
/// invocation of a routine. This is because the hard OOM handler is entirely asynchronous
|
||||||
/// and could be invoked at any time, including while we are trying to handle a soft OOM.
|
/// and could be invoked at any time, including while we are trying to handle a soft OOM.
|
||||||
const HARD_OOM_PAGE_TARGET: usize = 48;
|
const HARD_OOM_PAGE_TARGET: usize = 32;
|
||||||
/// Target of pages to free in case of OOM Doom
|
/// Target of pages to free in case of OOM Doom
|
||||||
const OOM_DOOM_PAGE_TARGET: usize = 64;
|
#[cfg(feature = "oom-doom")]
|
||||||
|
const OOM_DOOM_PAGE_TARGET: usize = 48;
|
||||||
/// Polling interval for OOM Doom. Slightly off from an even second so we don't have constant
|
/// Polling interval for OOM Doom. Slightly off from an even second so we don't have constant
|
||||||
/// competition with other processes that probably use even-second multiples for polling.
|
/// competition with other processes that probably use even-second multiples for polling.
|
||||||
|
#[cfg(feature = "oom-doom")]
|
||||||
const OOM_DOOM_POLL_INTERVAL_MS: u64 = 1057;
|
const OOM_DOOM_POLL_INTERVAL_MS: u64 = 1057;
|
||||||
|
|
||||||
/// Virtual address prefixes to de-prioritize in the OomDoom sweep
|
/// Virtual address prefixes to de-prioritize in the OomDoom sweep
|
||||||
|
|
@ -334,14 +336,7 @@ fn write_to_swap_inner(
|
||||||
|
|
||||||
// step 2: write the page to swap
|
// step 2: write the page to swap
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(feature = "debug-print")]
|
||||||
writeln!(
|
writeln!(DebugUart {}, "WTS PID{} VA {:x}", candidate.raw_pid(), vaddr_in_swap).ok();
|
||||||
DebugUart {},
|
|
||||||
"WTS PID{}, vaddr_pid {:x}, vaddr_swap {:x}",
|
|
||||||
candidate.raw_pid(),
|
|
||||||
candidate.vaddr(),
|
|
||||||
vaddr_in_swap
|
|
||||||
)
|
|
||||||
.ok();
|
|
||||||
// this is safe because the page is aligned and initialized as it comes from the kernel
|
// this is safe because the page is aligned and initialized as it comes from the kernel
|
||||||
// remember that this page is overwritten with encrypted data
|
// remember that this page is overwritten with encrypted data
|
||||||
let buf: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(vaddr_in_swap as *mut u8, PAGE_SIZE) };
|
let buf: &mut [u8] = unsafe { core::slice::from_raw_parts_mut(vaddr_in_swap as *mut u8, PAGE_SIZE) };
|
||||||
|
|
@ -503,15 +498,7 @@ fn swap_handler(
|
||||||
// after `pt_walk` is necessary. Either way, it's spooky. I wonder if there isn't some minimum
|
// after `pt_walk` is necessary. Either way, it's spooky. I wonder if there isn't some minimum
|
||||||
// time between reads from the SPIM that we're violating??
|
// time between reads from the SPIM that we're violating??
|
||||||
#[cfg(feature = "debug-print")]
|
#[cfg(feature = "debug-print")]
|
||||||
writeln!(
|
writeln!(DebugUart {}, "RFS PID{} VA {:x} PA {:x}", pid, vaddr_in_pid, paddr_in_swap).ok();
|
||||||
DebugUart {},
|
|
||||||
"RFS PID{}, vaddr_pid {:x}, vaddr_swap {:x}, paddr {:x}",
|
|
||||||
pid,
|
|
||||||
vaddr_in_pid,
|
|
||||||
vaddr_in_swap,
|
|
||||||
paddr_in_swap
|
|
||||||
)
|
|
||||||
.ok();
|
|
||||||
// clear the used bit in swap
|
// clear the used bit in swap
|
||||||
ss.sct.counts[paddr_in_swap / PAGE_SIZE] &= !loader::FLG_SWAP_USED;
|
ss.sct.counts[paddr_in_swap / PAGE_SIZE] &= !loader::FLG_SWAP_USED;
|
||||||
|
|
||||||
|
|
@ -547,8 +534,13 @@ fn swap_handler(
|
||||||
|
|
||||||
// free memory for the hard-OOM handler to run
|
// free memory for the hard-OOM handler to run
|
||||||
if let Some(reserved_mem) = ss.hard_oom_reserved_page.take() {
|
if let Some(reserved_mem) = ss.hard_oom_reserved_page.take() {
|
||||||
writeln!(DebugUart {}, "Entering HARD OOM - freeing scratch memory: {:x?}", reserved_mem)
|
writeln!(
|
||||||
.ok();
|
DebugUart {},
|
||||||
|
"Entering HARD OOM attempt to free {} pages - scratch memory: {:x?}",
|
||||||
|
pages_to_free,
|
||||||
|
reserved_mem,
|
||||||
|
)
|
||||||
|
.ok();
|
||||||
xous::unmap_memory(reserved_mem).expect("couldn't free memory for hard OOM handler");
|
xous::unmap_memory(reserved_mem).expect("couldn't free memory for hard OOM handler");
|
||||||
} else {
|
} else {
|
||||||
panic!("No space was reserved for the hard OOM manager to run!");
|
panic!("No space was reserved for the hard OOM manager to run!");
|
||||||
|
|
@ -693,6 +685,7 @@ fn main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// This thread pings the free memory level and will try to clear memory to avoid OOM
|
// This thread pings the free memory level and will try to clear memory to avoid OOM
|
||||||
|
#[cfg(feature = "oom-doom")]
|
||||||
thread::spawn({
|
thread::spawn({
|
||||||
move || {
|
move || {
|
||||||
loop {
|
loop {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue