在内核空间中创建连续区域
我通过 alloc_page(GFP_USER)
分配内存,并且分配了不止一页。 我需要将其视为连续区域(我需要从它的缓冲区中创建),所以我想撤销它*(vm_beg + off)
。
我知道这可以通过用户空间中的 mmap
实现,但是我如何在内核空间中做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要虚拟分配连续内存,则可以使用
vmalloc()
来执行此操作(更多信息此处)。不过,实际的物理内存可能是分散的,因此,如果您计划将该缓冲区与 CPU MMU 外部的某些硬件块(例如 DMA、PCI 总线)一起使用,那么vmalloc()
可能不适合您最好的选择。对于大多数用途,您可能应该使用
kmalloc()
(更多信息此处 )。不同之处在于,vmalloc()
将始终修改页表以获取新内存(有点像用户态中的mmap()
)。另一个区别是 kmalloc() 为您提供了物理上连续的内存,并且通常比必须始终修改页表的 vmalloc() 更快。关于 Linux 内存的一个非常好的信息来源是 Linux Device Drivers 3 (特别是您的情况下的第 15 章) ,您可能会在其中找到大多数问题的答案。
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, thenvmalloc()
might not be your best bet.You probably should use
kmalloc()
for most purposes (more info here). The difference is thatvmalloc()
will always modify the page tables to get you new memory (a bit likemmap()
in userland). Another difference is thatkmalloc()
gives you phisically contiguous memory and is usually faster thanvmalloc()
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.