Reputation: 39
I'm allocating memory by alloc_page(GFP_USER)
and I have allocated more than one page.
I need to make that I will see it as contiguous region (I need to make from it buffer), so I want to revoke to it *(vm_beg + off)
.
I know that is possible by mmap
in user space but how I can do that in kernel space?
Upvotes: 1
Views: 494
Reputation: 1099
If you need to allocate virtually contiguous memory, then you can use vmalloc()
to do so (more info here). The actual physical memory might be scattered though, so if you are planning on using that buffer with some hardware block (e.g DMA, PCI bus) outside of your CPU MMU, then vmalloc()
might not be your best bet.
You probably should use kmalloc()
for most purposes (more info here). The difference is that vmalloc()
will always modify the page tables to get you new memory (a bit like mmap()
in userland). Another difference is that kmalloc()
gives you phisically contiguous memory and is usually faster than vmalloc()
which has to always modify the page tables.
A very good source of information on Linux memory is Linux Device Drivers 3 (specifically Chapter 15 in your case), you will probably find the answer to most of your questions inside.
Upvotes: 5