heap_lazy: the docs say 1 MiB chunks, and with the setting off ipc, svc and save writes are as before

Review of #1369: the settings row still said 64 KiB though LAZY_CHUNK is 1 MiB, and two changes ran for every player.
ipc.c and svc.c readable() ask the OS again unless TOTK_HEAP_LAZY is on (mem_heap_lazy), and fs_host.c write_file calls
mem_heap_commit, which commits the buffer's reserved heap chunks in lazy mode and does nothing otherwise, instead of
mem_thaw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ruan ShannonandClaude Opus 5.5 committed 2026-11-23 13:38:10 -08:00
1 parent 54b2975d98
commit ab356192d7
6 files changed
+19 -6

No files matched your search

+1 -1
View File
@@ -1024,7 +1024,7 @@ static uint32_t write_file(uint64_t h, int64_t offset, const void *buffer, uint6
if (!plat_file_id(f, &id)) rt_fatal("fs: host save size");
if ((uint64_t)offset + size > id.size && !(mode & FS_OPEN_APPEND)) return FS_R_APPEND_REQUIRED;
if (file->save) save_touched();
mem_thaw((uintptr_t)buffer, size); // the kernel reads the buffer: heap pages never used yet must be committed
mem_heap_commit((uintptr_t)buffer, size); // TOTK_HEAP_LAZY: the kernel reads the buffer, so its chunks must exist
for (uint64_t done = 0; done < size;) {
uint32_t chunk = size - done > 0x40000000 ? 0x40000000 : (uint32_t)(size - done);
int64_t put = plat_file_pwrite(f, (const uint8_t *)buffer + done, chunk, (uint64_t)offset + done);
+3
View File
@@ -177,6 +177,9 @@ void mem_thaw(uint64_t a, uint64_t n); // makes the frozen r
void mem_freeze_stats(uint64_t *frozen, uint64_t *freezes, uint64_t *fault_thaws, uint64_t *other_thaws);
// regions frozen now; freezes and thaws since the last call
void mem_kernel_free(void *p, uint64_t size); // TLR/TLS reuse after thread exit
int mem_heap_lazy(void); // TOTK_HEAP_LAZY is on (Windows): heap pages commit on first use
void mem_heap_commit(uint64_t a, uint64_t n); // commits the not yet committed heap chunks of [a, a+n) before
// the kernel reads them; nothing when mem_heap_lazy is 0
uint64_t mem_heap_uncommitted(void); // heap bytes set by SetHeapSize but not committed yet
// (TOTK_HEAP_LAZY): commit the game can still claim
int mem_guest_readable(uint64_t a, uint64_t n); // [a, a+n) can be read without a fault: inside a loaded
+5 -2
View File
@@ -66,8 +66,11 @@ void ipc_handle_closed(int kind, void *obj) {
}
// ---- helpers for services
// The heap by the layout (its pages may not be committed before first use), anything else by the OS.
static int readable(uint64_t a, uint64_t n) { return mem_guest_readable(a, n); }
// With TOTK_HEAP_LAZY the heap by the layout (its pages may not be committed before first use), anything else by
// the OS; without it the OS for everything, as before.
static int readable(uint64_t a, uint64_t n) {
return mem_heap_lazy() ? mem_guest_readable(a, n) : plat_mem_readable(a, n);
}
void ipc_backtrace(void) {
const Cpu *c = t_req;
+4
View File
@@ -282,6 +282,10 @@ static int heap_fault_raced(uint64_t a) {
return plat_mem_state(a & ~(PAGE - 1), (a & ~(PAGE - 1)) + PAGE, &end) == PLAT_PROT_RW;
}
int mem_heap_lazy(void) { return heap_lazy; }
void mem_heap_commit(uint64_t a, uint64_t n) { heap_commit_range(a, n); }
uint64_t mem_heap_uncommitted(void) {
if (!heap_lazy) return 0;
uint64_t size = __atomic_load_n(&heap_size, __ATOMIC_ACQUIRE), done = __atomic_load_n(&heap_committed, __ATOMIC_RELAXED);
+5 -2
View File
@@ -31,8 +31,11 @@ RtStats rt_stats(void) {
return (RtStats){__atomic_load_n(&g_svcs, __ATOMIC_RELAXED), kern_threads_created(), hostfn_calls()};
}
// The heap by the layout (its pages may not be committed before first use), anything else by the OS.
static int readable(uint64_t a, uint64_t n) { return mem_guest_readable(a, n); }
// With TOTK_HEAP_LAZY the heap by the layout (its pages may not be committed before first use), anything else by
// the OS; without it the OS for everything, as before.
static int readable(uint64_t a, uint64_t n) {
return mem_heap_lazy() ? mem_guest_readable(a, n) : plat_mem_readable(a, n);
}
void kern_backtrace(const Cpu *c) {
char d[160];