[Linux memory]linux memory allocation function Summary

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.