fix: pm running apps grow (death-bit bound 60); spawntest stress: 30 files open, apps until BUSY then room comes back; docs: limits and why

This commit is contained in:
2026-10-28 16:22:19 +01:00
parent 1f2134fcec
commit 0de13f124d
3 changed files with 130 additions and 4 deletions

View File

@@ -26,7 +26,10 @@ use crate::store::DiskStore;
/// An app's limits; its pages are what its manifest asks for.
const PROGRAM: Limits = Limits { pages: 0, endpoints: 1, notifications: 1, regions: 1 };
/// Apps running at once; a death is a bit each on the notification.
const MAX_RUNNING: usize = 8;
/// Apps running at once, at most: each has a bit of the deaths
/// notification, and the bits from 60 up mark launcher and manager copies.
/// What there is room for is the allowance's to say, well before this.
const MAX_RUNNING: usize = 60;
const MAX_ARGS: usize = 16;
/// The session's desktop, started with it and again if it dies.
const HOME: &str = "kos.home";
@@ -72,7 +75,8 @@ pub struct PermissionServer {
/// Bound to the serving thread: deaths of running apps.
deaths: CapSlot,
staged: Staged,
running: [Option<Running>; MAX_RUNNING],
/// By death bit; grown as apps start.
running: Vec<Option<Running>>,
/// Home's starts this session.
homes: u8,
}
@@ -136,7 +140,7 @@ fn parts(page: &[u8]) -> impl Iterator<Item = &str> {
impl PermissionServer {
pub fn new(store: DiskStore, consent: TerminalConsent, ports: Ports, deaths: CapSlot) -> Self {
let Ports { init, display, session, endpoint } = ports;
Self { store, consent, init, display, session, endpoint, deaths, staged: Staged::default(), running: [const { None }; MAX_RUNNING], homes: 0 }
Self { store, consent, init, display, session, endpoint, deaths, staged: Staged::default(), running: Vec::new(), homes: 0 }
}
/// What this device has a server for.
@@ -210,7 +214,10 @@ impl PermissionServer {
let command = *args.first().ok_or(code(reply::NOT_INSTALLED))?;
let available = self.available();
let plan = policy::plan_launch(&mut self.store, command, available).map_err(refused)?;
let index = self.running.iter().position(Option::is_none).ok_or(code(reply::BUSY))?;
let index = self.running.iter().position(Option::is_none).unwrap_or(self.running.len());
if index >= MAX_RUNNING {
return Err(code(reply::BUSY));
}
let file = self.store.binary_grant(&plan.app).ok_or(code(reply::FAILED))?;
let spawned = libkos::spawn::spawn(self.init, file, Limits { pages: plan.app.memory.pages(), ..PROGRAM });
@@ -278,6 +285,9 @@ impl PermissionServer {
syscall::drop_cap(child.process);
return Err(code(reply::FAILED));
}
if self.running.len() <= index {
self.running.resize_with(index + 1, || None);
}
self.running[index] = Some(Running { id: plan.app.id, process: child.process, granted: plan.granted, data, window, manage });
Ok((child.process, plan.granted))
}