linux kernel preallocated non mapped virtual memory

422 views Asked by At

I have the following scenario:
qemu-kvm(guest) ---has virtual memory, get physical--->
virtio (send physical address to host) ---map physical to host virtual memory--->
host
The physical memory is preallocated. Is there a method to preallocate non mapped virtual memory on the host so that it won't have to search for free virtual address spaces?
Would this be a justifiable design concern if the buffers are pretty big?
The end result that I want is a pool of virtual address spaces to map received buffers.
After every job I want to unmap them and send them back the virtual address space to the pool.

1

There are 1 answers

2
oakad On

To reserve a virtual memory range without actually committing any physical pages to it, pass PROT_NONE as protection parameter to mmap(). Later on, you can use mprotect() on that range to make it readable/writable when necessary - the kernel will commit the physical pages on first access. When you're done, you can use mprotect() again to reset the protection status of the address range back to PROT_NONE.