℡Wang Yan 2018-11-05 05:57 采纳率: 100%
浏览 299

我们可以通过 mmap ()分配物理上的连续内存吗?

I need physically contiguous memory in aarch64 Linux 4.15 for an experimental purpose.

I guessed if the required size is smaller than the page size, the allocated memory may be physically contiguous as below.

void * p = mmap(0, getpagesize() - 1, PROT_READ | PROT_WRITE, MAP_SHARED, 0, 0);

After the allocation, I will identify its physical address by /proc/self/pagemap.

However I cannot find any documentation about this. Can I allocate physicall contiguous memory?

Thank you.

转载于:https://stackoverflow.com/questions/53149071/can-we-allocate-physically-contiguous-memory-by-mmap

  • 写回答

1条回答 默认 最新

  • 七度&光 2018-11-05 06:05
    关注

    You have very little control over physical memory locations. Within a page, the memory will be contiguous (it's more or less the definition of a page). But different pages that are contiguous in virtual address space need not be contiguous in the physical address space (and pages that are contiguous in the physical address space need not be contiguous in the virtual address space).

    Unless you are going to be working in the lowest levels of the kernel memory management, you're not going to be able to spot physical contiguity in a hurry.

    If the memory is dual-ported between Linux and something else, then you may have issues, but simply using mmap() won't resolve them.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮