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?
0
votes
Are you allocating more than one page worth of memory?
– Michael Hampton
Currently, I am. But I can configure it to one page buffer space. @MichaelHampton
– Proy
AFAIK kmalloc() guarantees contiguous physical memory. You need this for DMA transfers, for instance. But there's an upper limit on how large a block it will provide.
– Michael Hampton
Does it handled by linux kvm? @MichaelHampton
– Proy
1 Answers
1
votes
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.