0

I am implementing a device driver in guest OS. For this I need to allocate a buffer space which is required to be contiguous physical memory. Does allocating buffer using kmalloc in guest OS guarantee contiguous physical address? If not, how can I achieve this?

Proy
  • 336
  • 2
  • 13

1 Answers1

1

kmalloc() will guarantee contiguous physical memory, and is supposed to be used for small objects, as stated in the function documentation:

* kmalloc is the normal method of allocating memory
* for objects smaller than page size in the kernel.

For bigger physically contiguous allocations, you should use alloc_pages() instead.

However, since you are in a guest OS, the physical memory you will be allocating is the one seen by the guest, not by the hypervisor (the "real" one). Whether the memory allocated is actually physically contiguous depends on how your hypervisor exposes memory to the guest OS.

rgouicem
  • 351
  • 2
  • 3