kmalloc返回的地址的物理地址

时间:2022-05-08 18:04:26

I'm a bit confused about the addresses that kmalloc is returning to me. According to the virtual memory map, the addresses I'm getting are in the ffff880000000000 - ffffc7ffffffffff range, so the "direct mapping of all phys. memory". How does this mapping work? I'm pretty certain that kmalloc doesn't simply return a physical address.

我对kmalloc返回给我的地址有点困惑。根据虚拟内存映射,我得到的地址在ffff880000000000 - ffffc7ffffffffffff范围内,所以是“所有phys的直接映射”。记忆”。这个映射是如何工作的?我很确定kmalloc不会简单地返回一个物理地址。

1 个解决方案

#1


3  

You're right, kmalloc is returning a virtual address, not a physical one. The memory map you linked to is describing the virtual memory map, not the physical memory map.

你说得对,kmalloc返回的是一个虚拟地址,而不是一个物理地址。您链接的内存映射描述的是虚拟内存映射,而不是物理内存映射。

A virtual address typically is translated to a physical address by the MMU when you access data at the address. What the virtual address translates to depends on the memory map specified by the kernel.

当您访问地址上的数据时,MMU通常将虚拟地址转换为物理地址。虚拟地址的含义取决于内核指定的内存映射。

The memory map you linked to shows how Linux does the mapping. It is saying, if you have a virtual address between 0xffff880000000000 and 0xffffc7ffffffffff, it is mapped to somewhere in physical memory (we don't know where exactly nor do we care unless we're doing DMA).

您所链接的内存映射显示Linux是如何进行映射的。它是说,如果在0xff880000000000和0xffffc7ffffffffffffffffffffffff之间有一个虚拟地址,那么它将映射到物理内存中的某个地方(我们不知道确切的位置,也不关心,除非我们正在执行DMA)。

#1


3  

You're right, kmalloc is returning a virtual address, not a physical one. The memory map you linked to is describing the virtual memory map, not the physical memory map.

你说得对,kmalloc返回的是一个虚拟地址,而不是一个物理地址。您链接的内存映射描述的是虚拟内存映射,而不是物理内存映射。

A virtual address typically is translated to a physical address by the MMU when you access data at the address. What the virtual address translates to depends on the memory map specified by the kernel.

当您访问地址上的数据时,MMU通常将虚拟地址转换为物理地址。虚拟地址的含义取决于内核指定的内存映射。

The memory map you linked to shows how Linux does the mapping. It is saying, if you have a virtual address between 0xffff880000000000 and 0xffffc7ffffffffff, it is mapped to somewhere in physical memory (we don't know where exactly nor do we care unless we're doing DMA).

您所链接的内存映射显示Linux是如何进行映射的。它是说,如果在0xff880000000000和0xffffc7ffffffffffffffffffffffff之间有一个虚拟地址,那么它将映射到物理内存中的某个地方(我们不知道确切的位置,也不关心,除非我们正在执行DMA)。