Example Linux Memory Allocation Code

The below code provides an example allocation of “kmalloc“, “vmalloc“, “kcalloc” and “kzalloc” APIs in the Linux kernel code.

for the different APIs and information about the APIs, refer the article – Allocating Memory in the Linux Kernel Module 

The “kmalloc” API provides a contiguous block of memory in both virtual and physical address space of the kernel. The “vmalloc” API provides a contiguous block of memory in the virtual address space but the memory may not be contiguous in the physical address space of the kernel.

Addresses provided by “vmalloc” API are in the range between VMALLOC_START and VMALLOC_END.

linux kernel locking mechanisms

 

Comments

  1. Pingback: Allocating memory in the Linux Kernel Module – Kernel APIs | Hitch Hiker's Guide to Learning

Leave a Reply

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