3 ms·
Maybe I'm just not seeing it, but I don't see how mmap let's you remap an existing address to a new one? Looks like there is a mremap on Linux in any case.
by ndriscoll 4y ago
Maybe I'm just not seeing it, but I don't see how mmap let's you remap an existing address to a new one? Looks like there is a mremap on Linux in any case.
- pencilguin 4y agoOr, you can map new space onto the end of an existing mapping, at a slightly greater cost of keeping track. Mremap is usually better.
- comex 4y agoIf you want to stick to mmap, you can do it by creating a file which doesn’t have any actual disk backing (one way to do this is with POSIX shm_open), and handling all memory allocations by mmapping parts of that file rather than mapping true anonymous memory. Then, ‘remapping’ an address to a new one is a matter of calling mmap again with the same file offset. Unlike mremap, this allows mapping the same memory at different addresses simultaneously, which can be useful for some purposes.
- pencilguin 4y ago/dev/hugepages/ is a good place to put this if you have enough control over the host.