简体   繁体   English

在Linux内核中选择内存分配API以频繁分配大内存

[英]Choosing memory allocation api in linux kernel for allocating huge memory frequently

I have to allocate huge amount of memory frequently in my kernel driver. 我必须经常在内核驱动程序中分配大量内存。 Which memory allocation api is better to use and why ? 哪种内存分配API更好用,为什么?

If you need large allocations, kmalloc() is not a good idea, because once the physical address space has become fragmented, large kmalloc() allocations will frequently fail. 如果需要大量分配,则kmalloc()并不是一个好主意,因为一旦物理地址空间变得零散,大型kmalloc()分配将经常失败。

So vmalloc() / vfree() is most probably the way to go - unless you need to share the buffer with the hardware device, in which case look into the CMA (Contiguous Memory Allocator), dma_alloc_from_contiguous() / dma_release_from_contiguous() . 因此, vmalloc() / vfree()最有可能是方法-除非您需要与硬件设备共享缓冲区,否则请查看CMA(连续内存分配器), dma_alloc_from_contiguous() / dma_release_from_contiguous()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM