I\'ve been experimenting with mremap(). I\'d like to be able to move virtual memory pages around at high speeds. At least higher speeds than copying them. I have some ideas for
What makes you think mremap
could ever be efficient for swapping single 4k pages? At the very least, a round-trip to kernelspace even just to read a single value (like pid) and return it will cost more than moving 4k of data. And that's before we get to the cache invalidation/TLB costs of remapping memory, which I don't understand well enough to address in this answer, but which should have some serious cost.
mremap
is useful for basically one thing: implementing realloc
for large allocations that were serviced by mmap
. And by large, I mean probably at least 100k.