Faster way to move memory page than mremap()?

后端 未结 2 1878
夕颜
夕颜 2021-02-02 13:50

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-02 14:10

    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.

提交回复
热议问题