A quick comparison between the kmalloc() (or kzalloc()) and vmalloc() (or vzalloc()) APIs is presented in the following table:
Characteristic | kmalloc() or kzalloc() | vmalloc() or vzalloc() |
Memory allocated is | Physically contiguous | Virtually (logically) contiguous |
Memory alignment | Aligned to hardware (CPU) cacheline | Page-aligned |
Minimum granularity | Arch-dependent; as low as 8 bytes on x86[_64] | 1 page |
Performance | Much faster (physical RAM allocated) for small memory allocations (the typical case); ideal for allocations < 1 page | Slower, demand-paged (only virtual memory allocated; lazy allocation of RAM involving the page fault handler); can service large (virtual) allocations |
Size limitation | Limited (to typically 4 MB) | Very large (the kernel vmalloc region can even be several terabytes on 64-bit systems, though much less on 32-bit) |
Suitability | Suitable for almost all use cases where performance... |