UP | HOME

Reducing syscalls for large allocations with a free list allocator

This is an allocator wrapper with a sort of free list to reuse allocations. Simple, but effective. The source can be found in a Gist.

Before (BinnedAllocator by silversquirl):

read(3, "FRAME\n013101011./21110010/379<@B"..., 4096) = 4096
mmap(0x7f3ac5b65000, 155648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3ac5b65000
read(3, "/........0..//.--,,-+,/024588999"..., 147974) = 147974
munmap(0x7f3ac5b65000, 155648)          = 0
read(3, "FRAME\n013101011./21110010/379<@B"..., 4096) = 4096
mmap(0x7f3ac5b8b000, 155648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3ac5b8b000
read(3, "/........0..//.--,,-+,/024588999"..., 147974) = 147974
munmap(0x7f3ac5b8b000, 155648)          = 0

After (FreeListAllocator wrapping std.heap.page_allocator):

read(3, "FRAME\n013101011./21110010/379<@B"..., 4096) = 4096
read(3, "/........0..//.--,,-+,/024588999"..., 147974) = 147974
read(3, "FRAME\n013101011./21110010/379<@B"..., 4096) = 4096
read(3, "/........0..//.--,,-+,/024588999"..., 147974) = 147974

This is only worth it for relatively few large allocations. This isn't a clever allocator, I just quickly hacked up what came to mind. Adjust max_allocations according to your needs.