title: Why is kmalloc() more efficient than vmalloc()?
body: <p>I think <code>kmalloc()</code> allocates continuous physical pages in the kernel because the virtual memory space is directly mapping to the physical memory space, by simply adding an offset.</p>
  
  <p>However, I still don't understand why it is more efficient than <code>vmalloc()</code>.
  It still needs to go through the page table (the kernel page table), right? Because the MMU is not disabled when the process is switching to the kernel. So why Linux directly maps the kernel virtual space to the physical memory? What is the benefit?</p>
  
  <p>In <code>include/asm-x86/page_32.h</code>, there is:</p>
  
  <pre class="lang-c prettyprint-override"><code>#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
  #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
  </code></pre>
  
  <p>Why does the kernel need to calculate the physical address? It has to use the virtual address to access the memory anyway, right? I cannot figure out why the physical address is needed.</p>