Nyxus: Inside the Retained Heap
Chapters
- Follow the backing allocation
- Take a slot, then a page run
- Give the provider space back
Transcript
Follow the backing allocation
Follow Inventory's item map into main memory. Nyxus allocates its native B-tree nodes there. An allocator test makes the same choice with a simpler collection, a vector. The native test starts with two vectors. An ordinary Rust vector gets its buffer from Global. The second constructor names Nyxus. The retained buffer starts with one, two, three. In a canister, the runtime and Nyxus ask one provider for sixty-four kibibyte pages. It tracks which allocator owns each claim. As either client needs space, it can claim available pages from that same pool.
Take a slot, then a page run
Inside a page, the allocator divides space into spans. A span serves one size class, with slots of equal size. A nine-byte request aligned to eight bytes takes a sixteen-byte slot. Both layouts fit the same slot, so growing to sixteen keeps the same address. The test requests zeroed growth. The first nine bytes keep their values and the seven added bytes start at zero. Give the vector more elements and it eventually needs a larger buffer. The native test reaches twenty thousand integers. For a large allocation in Wasm, the allocator claims a run of whole pages. When resizing moves a buffer, the existing elements follow it into the new space.
Give the provider space back
Dropping the vector releases its buffer. A whole-page run goes straight back to the provider. Other live allocations stay where they are. On the smaller page, a freed slot can take another request of its class. When the last allocation goes, the whole page becomes available. Either allocator can claim it next. The Wasm memory extent stays the same. In the next canister, Payloads uses Nyxus and Records uses Hylix. Both attach to the same root. Records keeps a small descriptor in main memory. Its data lives in stable memory.