Files
metal2vulkan/docs
Anees Iqbal 3b3739ce45 The idle sweep hands glibc's free heap back, not only a large making
glibc keeps what the process's threads free as free heap, its pages resident, until
malloc_trim hands it back, and only a large pipeline making's return called it. The memory
log of one Iris Xe cold boot at pin 66 (reims's 24852) shows the cost: 1.4 GiB of glibc's 4.0
GiB of arenas free at its end, after 3 trims in all, all from large makings.

Now each device's idle sweep thread also looks at glibc's heap every 5 s (HEAP_EVERY), whether
or not a sweep is due, and trims once the heap holds more than the floor (FREE_FLOOR, 256 MiB)
free above the least free a look read since the last trim, at two looks in a row
(idle_sweep::HeapLook). The least-free rule, not the bytes free alone, because glibc still
counts a trimmed chunk free: a plain fordblks rule would trim again at every look. A trim
counts in WorkCounts::heap_trims, as a large making's does. compile_memory gains heap_bytes()
and trim(), which return_free_heap now uses. Only on Linux with glibc; elsewhere the thread
makes no look and waits as before.

Docs: idle_sweep.rs and compile_memory.rs module docs, WorkCounts::heap_trims, the memory
log's paragraph in docs/API.md.

Tests: tests::idle_heap_look (the look's rule: trimmed at the second look, not again for what
a trim left, again for what was freed after it); tests::idle_heap_trim (device test, m2v_gpu
or m2v_cpu_icd, Linux gnu): 768 MiB of written 64 KiB chunks, all but one in 16 and the last
freed, then idle; the device's thread trims and the resident set falls by 512 MiB or more. The
lavapipe run and its negative control (no heap look: the test must fail) follow this commit.
2026-11-13 01:51:23 -08:00
..