fix: fix login wallpaper startup delay

This commit is contained in:
daniel committed 2026-08-30 08:05:31 +02:00
1 parent 21828990c4
commit fdbb233cd3
12 files changed
+271 -32

No files matched your search

+1 -1
View File
@@ -12,4 +12,4 @@
#pragma once
#define MONTAUK_BUILD_NUMBER 179
#define MONTAUK_BUILD_NUMBER 182
+39 -1
View File
@@ -45,7 +45,12 @@ namespace montauk::abi {
static constexpr uint64_t VmProtWrite = 2;
static constexpr uint64_t VmProtExec = 4;
inline uint64_t Sys_MapAnonymous(uint64_t size, uint64_t prot) {
// Sys_MapAnonymous flags. Populate commits the whole range at mapping
// time; without it every page is materialized on first touch.
static constexpr uint64_t VmFlagPopulate = 1;
inline uint64_t Sys_MapAnonymous(uint64_t size, uint64_t prot,
uint64_t flags = 0) {
auto* proc = Sched::GetCurrentProcessPtr();
if (proc == nullptr) return 0;
int slot = GetCurrentSlot();
@@ -83,6 +88,33 @@ namespace montauk::abi {
g_heapAllocs[slot] = new HeapAlloc { userVa, numPages, prot, allocationId,
g_heapAllocs[slot] };
// Populate is best effort: commit as much of the range as the frame
// allocator will give up front, and leave the remainder to the fault
// path. A caller that is about to touch every page (a decode buffer,
// a heap slab) then pays one loop instead of one trap, one mutex
// acquire and one VMA walk per 4 KiB.
if ((flags & VmFlagPopulate) != 0) {
bool writable = (prot & VmProtWrite) != 0;
bool executable = (prot & VmProtExec) != 0;
// Bounded so one syscall cannot pin an unbounded amount of memory
// with the slot's heap lock held. Anything past the cap faults in.
static constexpr uint64_t MaxPopulatePages = 64 * 1024 * 1024 / 0x1000;
uint64_t populate = numPages < MaxPopulatePages ? numPages
: MaxPopulatePages;
for (uint64_t i = 0; i < populate; i++) {
uint64_t pageVa = userVa + i * 0x1000ULL;
void* page = Memory::g_pfa->AllocateZeroed();
if (page == nullptr) break;
uint64_t phys = Memory::SubHHDM((uint64_t)page);
if (!Memory::VMM::Paging::MapUserInPermissions(
proc->pml4Phys, phys, pageVa, writable, executable)) {
Memory::g_pfa->Free(page);
break;
}
Sched::g_allocatedPages[slot]++;
}
}
g_heapLocks[slot].Release();
return userVa;
}
@@ -91,6 +123,12 @@ namespace montauk::abi {
return Sys_MapAnonymous(size, VmProtRead | VmProtWrite);
}
// As Sys_Alloc, but commits the pages immediately instead of faulting them
// in one at a time.
inline uint64_t Sys_AllocEager(uint64_t size) {
return Sys_MapAnonymous(size, VmProtRead | VmProtWrite, VmFlagPopulate);
}
// Reset heap allocation tracking for a process slot.
// The actual physical pages are freed by Paging::FreeUserHalf() during process cleanup.
inline void CleanupHeapForSlot(int slot, uint64_t /*pml4Phys*/) {
+2
View File
@@ -116,6 +116,8 @@ namespace montauk::abi {
(int)frame->arg4);
case SYS_ALLOC:
return (int64_t)Sys_Alloc(frame->arg1);
case SYS_ALLOC_EAGER:
return (int64_t)Sys_AllocEager(frame->arg1);
case SYS_FREE:
Sys_Free(frame->arg1);
return 0;
+5
View File
@@ -338,6 +338,11 @@ namespace montauk::abi {
static constexpr uint64_t SYS_SPAWN_CAPS = 185;
static constexpr uint64_t SYS_SPAWN_REDIR_CAPS = 186;
/* Heap.hpp -- as SYS_ALLOC, but commits every page up front instead of
faulting them in one at a time. For buffers the caller is about to
touch in full (image decode, heap slabs). */
static constexpr uint64_t SYS_ALLOC_EAGER = 187; // (bytes) -> va, 0 on failure
/* Kernel-owned process capabilities. User identities may namespace
per-user resources, but never participate in authorization decisions. */
static constexpr uint64_t CAP_PROCESS_ADMIN = 1ULL << 0;