阅读:2270回复:3
如何在module中申请物理连续的大块内存?
要做一个内核态module,负责申请一块几兆大小的物理连续的内存块,用作外设的DMA缓冲区。同时使应用程序可以对该内存进行读写。应该用什么机制获得该内存呢?
查阅资料,kmalloc可以分配物理连续的内存,可是最大只能申请128K。那如何获得这个物理连续的大内存块呢? |
|
|
沙发#
发布于:2004-12-30 20:02
kmalloc allocates physically contiguous memory, memory which
pages are laid consecutively in physical RAM. vmalloc allocates memory which is contiguous in kernel virtual memory space (that means pages allocated that way are not contiguous in RAM, but the kernel sees them as one block). kmalloc is the preffered way, as long as you don't need very big areas. The trouble is, if you want to do DMA from/to some hardware device, you'll need to use kmalloc, and you'll probably need bigger chunk. THE SOLUTION is to allocate memory AS SOON AS possible, before memory gets fragmented. If you only allocate small chunks (page or few pages), just use kmalloc and don't worry about details. :) |
|
|
板凳#
发布于:2004-12-31 10:35
难道必须用kmalloc才能得到物理连续内存吗?可是如果分配大于128K(32pages)的内存,kmalloc是无能为力的。
|
|
|
地板#
发布于:2004-12-31 10:44
找到了,__get_free_pages 在2.0版本之后可以申请最大到2M的物理连续的内存。
|
|
|