Linux memory allocation method

In Linux driver development and application development., When you want to allocate memory, you’ll face a lot of memory allocation functions: malloc kmalloc of the vmalloc alloc_page dma_alloc etc.

Briefly summarized as follows:
malloc: allocate user space memory does not guarantee physically contiguous. Linux in user space and kernel space can not directly access each memory, but with the help from copy_from_user copy_to_user or mmap innuendo.
kmalloc: kernel space in small memory (less than 128K, this value can be modified), continuous inner physical this memory because of the relatively small, not directly from the buddy, but managed by the slab, slab from the buddy in get_free_page method Idle page, then the small memory kmem_cache_alloc etc. (kmalloc is called kmem_cache_alloc) to return to the place of application memory.
vmalloc: kernel space to allocate memory, this memory is not guaranteed to be physically contiguous, and memory can be relatively large, the size does not seem particularly limited.
alloc_page/dma_alloc …: from the buddy allocation, the size of the largest general 4M or 8M restrictions by MAX_ORDER. physically contiguous.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *