From 19128a83a337556c36e0f5944079fa6368a06c44 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 16 May 2024 03:54:51 +0800 Subject: [PATCH] add ability to "touch" an alloc so that the LRU count updates also add some debug access functions --- kernel/src/mem.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kernel/src/mem.rs b/kernel/src/mem.rs index ff08953a5..a52af2ff7 100644 --- a/kernel/src/mem.rs +++ b/kernel/src/mem.rs @@ -317,6 +317,30 @@ impl MemoryManager { Err(xous_kernel::Error::OutOfMemory) } + #[cfg(baremetal)] + #[cfg(feature = "swap")] + // Take a physical address and indicate that it's been queried so it doesn't get suggested as LRU any time + // soon. Addresses outside of RAM are just ignored. + pub fn touch(&self, paddr: usize) { + if paddr >= self.ram_start && paddr < self.ram_start + self.ram_size { + unsafe { + MEMORY_ALLOCATIONS[(paddr - self.ram_start) / PAGE_SIZE].touch(); + } + } + } + + #[cfg(feature = "debug-swap")] + /// This function is "improper" in that it returns a bogus value if the memory allocations are + /// out of range, but its purpose is only for debugging. This is not suitable for use in any + /// other context. + pub unsafe fn get_timestamp(&self, paddr: usize) -> u32 { + if paddr >= self.ram_start && paddr < self.ram_start + self.ram_size { + unsafe { MEMORY_ALLOCATIONS[(paddr - self.ram_start) / PAGE_SIZE].get_timestamp() } + } else { + 0xDEAD_BEEF + } + } + #[cfg(baremetal)] #[cfg(feature = "swap")] /// Similar to alloc_page(), but this implementation can only be called in one location because @@ -473,6 +497,8 @@ impl MemoryManager { #[cfg(not(feature = "swap"))] let phys = self.alloc_page(pid)?; #[cfg(feature = "swap")] + // this should not be OOMable because the callers for map_zeroed page are exclusively from kernel + // services (process creation, queue creation) let phys = self.alloc_page(pid, Some(virt))?; // Actually perform the map. At this stage, every physical page should be owned by us.