A brief introduction to the memory allocation mode under Linux __linux

Source: Internet
Author: User
1.Buddy System

The smallest unit of memory is page (4KB), which is based on the use of "partner system algorithm" to help manage different contiguous length of memory segments, 1,2,4,8,16,32,64,128,256,512 and 1024 consecutive page box block classification management. 2.slab

On the partner system there is also the slab to assist in memory management, the principle of which is to unify the acquisition of large memory segments and cut allocations, when the user needs a specific size of memory, from which to remove the initialization of good memory back. 3. Various API functions:

3.1 Alloc_pages, is the most original way of memory allocation, directly from the partner system to get the original page box, through the Force_max_zoneorder to the maximum number of pages to limit, the general maximum is 10, that is, the maximum return memory of 4M.
3.2__get_free_pages, only the alloc_pages is encapsulated, so the maximum limit is also 4 m.
3.3 Dma_alloc_coherent is also implemented through alloc_pages, so the maximum limit is 4M.
3.4 Kmem_cache_alloc, is a distribution based on slab, which is suitable for repeatedly allocating the same size memory block, first create a cache area by Kmem_cache_create, and then use Kmem_cache_alloc from The cache region gets a new block of memory, kmem_cache_alloc the maximum amount of memory that can be allocated at one time is defined by the Max_obj_order macro in the Mm/slab.c file, which is defined as 5 in the default 2.6.18 kernel version, and can be applied at most once for 1< <5 * 4KB is the continuous physical memory of 128KB.
3.5 Kmalloc is implemented through Kmem_cache_alloc, so Max can only apply for 128KB.
3.6 Vmalloc The previous memory allocation method is physical continuous, vmalloc no size limit, but only logical address continuous.

4. Flags in memory allocation:

The

Gfp_kernel represents a memory allocation (which ultimately calls Get_free_pages to implement the actual allocation; This is the origin of the GFP prefix) that is executed by a process running in kernel space. Using Gfp_kernel allows Kmalloc to allow the current process to sleep while allocating free memory if there is not enough memory to wait. Therefore, the allocation function must be reentrant. If the current process should not sleep outside of the process context such as interrupt handlers, Tasklet, and kernel timers, the driver should use gfp_atomic.

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.