喵-见缝插针 2018-11-05 05:57 采纳率: 0%
浏览 1603

我们可以通过 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条回答 默认 最新

  • YaoRaoLov 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 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试