▲ | benlwalker 4 days ago | ||||||||||||||||
For an expanding array in a 64 bit address space, reserving a big region and mmaping it in as you go is usually the top performing solution by a wide margin. At least on Linux, it is faster to speculatively mmap ahead with MAP_POPULATE rather than relying on page faults, too. And, if you find you didn't reserve enough address space, Linux has mremap() which can grow the reserved region. Or map the region to two places at once (the original place and a new, larger place). | |||||||||||||||||
▲ | OptionOfT 3 days ago | parent | next [-] | ||||||||||||||||
One place I had issues was rapidly allocating space I needed temporarily but then discarding it. The space I needed was too large to be added to the heap, so I used mmap. Because of the nature of the processing (mmap, process, yeet mmap) I put the system under a lot of pressure. Maintaining the set of mapped blocks and reusing them around fixed the issue. | |||||||||||||||||
| |||||||||||||||||
▲ | vlovich123 3 days ago | parent | prev [-] | ||||||||||||||||
FWIW mremap is very expensive as it involves a TLB shootdown. |