Re:Writing a Memory Allocator (2019)
by andi999 on Sunday December 13, 2020 @02:29AM
(#25404958)
Can you explain what you mean by mmap is how memory is obtained nowadays?
[ Parent
| on HN ]
mmap is not only to map a file content into a process address space, it can also be used to request memory from the OS using the MAP_ANONYMOUS flag. Early on a malloc-like allocator would use brk/sbrk to get a chunk of "raw" memory, and manage this for the user providing access using malloc/free. Nowadays the same "raw" memory can be obtained using an anonymous map. A raw pool, when unused, can be returned to the OS by unmapping it.
Using an anonymous map provides address space randomization by default (for the raw pool location), whereas brk/sbrk extends a limit and because of this are predictable.
Re:Writing a Memory Allocator (2019)
by DmitrySoshnikov on Sunday December 13, 2020 @04:04PM
(#25410266)
sbrk is emulated via mmap today on MacOS and others, this is an abstraction (for bump allocation), not just a function
you may implement custom sbrk via mmap easily