Colors of Ray+Hue'

What is the return address of kmalloc() ? Physical or Virtual?


It is virtual.   But let us go below the C language function - assembly programming instead, to understand everything better. 

Generally, at the assembly - every time you save or load from memory - either direct or through registers, it is also virtual.   This is because every addresses that comes out of the CPU address bus, is in virtual address:

or this (From wikipedia):

The virtual address will then be translated into physical address, which the CPU cannot see or even know its value.

vmalloc() is physically non-contiguous and kmalloc() is physically contiguous - so how does the CPU know it is contiguous or not?   This is because of linear mapping, or also called one-to-one mapping (or direct mapping):

Sometimes DMA devices require the physical addresses - and so through these "mapping", since we know the virtual address, the physical can thus be derived, but remember that the CPU cannot use it, ie,

load (eax), ebx:   where eax contained the physical address, is wrong.

Source from: https://www.quora.com/What-is-the-return-address-of-kmalloc-Physical-or-Virtual


'Linux Kernel' 카테고리의 다른 글

Block I/O Operation  (0) 2016.08.06
What is wmb() in linux driver  (0) 2016.08.05
Memory Mapping  (0) 2016.07.28
고정 크기 ramdisk 만들기 및 swap 영역 사용  (0) 2016.03.22
sysinfo 관련  (0) 2016.02.26