Linux kernel-related
1,linux Kernel memory allocation function summary
Unit |
Interface |
Algorithm |
Dynamic size |
Kmalloc/kfree/krealloc/kcalloc |
An array of caches organized by size |
Fixed size |
Kmem_cache_create/kmem_cache_destroy Kmem_cache_alloc/kmem_cache_free |
SLAB[2] |
2^n page |
Alloc_pages/free_pages __get_free_pages/__free_pages |
A partner algorithm that allocates several (physical contiguous) pages, returning a pointer to the first byte of the range |
Vmalloc
Works similar to Kmalloc (), but the virtual address is contiguous and the physical address is not contiguous. Used when obtaining large chunks of memory, usually in the place where the Creat_module () system is called.
2, various API application examples
Kmem_cache_create and Kmem_cache_alloc, for example, call the Kmem_cache_creat () function in the Mnt_int () function of the namespace.c file to create a cache named Mnt_cache, and then call the Do The _mount () function is called when the Kmem_cache_alloc () function is assigned a mount struct.
User-level Related:
3,malloc and Calloc functions
void *calloc (size_t n, size_t size);
allocating n contiguous spaces of size in the dynamic storage of memory, the function returns a pointer to the assigned start address, or null if the assignment is unsuccessful. Calloc automatically initializes the memory space after the memory is dynamically allocated to zero, and malloc is not initialized, and the data inside is random garbage data.
extern void *malloc (unsigned int num_bytes);
Use the free () function to manually release memory after use of memory allocated using the malloc () and calloc () functions.
What is the range of memory space the malloc () function applies To: A: 0x00000000 to 0XBFFFFFFF
4,linux Kernel Some places to allocate memory is not allowed to fail, this time should be how to guarantee
A: Using memory pool technology, the nature of the memory pool is the back cache, just before the use of pre-prepared, the disadvantage is to waste memory.
[Linux memory]linux memory allocation function Summary