Contiguous physical memory from userspace

后端 未结 4 2206
忘了有多久
忘了有多久 2020-11-27 07:27

Is there a way to allocate contiguous physical memory from userspace in linux? At least few guaranteed contiguous memory pages. One huge page isn\'t the answer.

4条回答
  •  粉色の甜心
    2020-11-27 07:44

    Yes, if all you need is a few pages, this may indeed be possible.

    The file /proc/[pid]/pagemap now allows programs to inspect the mapping of their virtual memory to physical memory.

    While you cannot explicitly modify the mapping, you can just allocate a virtual page, lock it into memory via a call to mlock, record its physical address via a lookup into /proc/self/pagemap, and repeat until you just happen to get enough blocks touching eachother to create a large enough contiguous block. Then unlock and free your excess blocks.

    It's hackish, clunky and potentially slow, but it's worth a try. On the other hand, there's a decently large chance that this isn't actually what you really need.

提交回复
热议问题