叼花硬汉 2018-11-05 05:57 采纳率: 0%
浏览 347
已采纳

我们可以通过 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)