程序go 2018-11-05 05:57 采纳率: 100%
浏览 275

我们可以通过 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 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块
  • ¥15 nhanes加权logistic回归,svyglm函数