Common memory allocation functions in Linux kernel (1)

Source: Internet
Author: User
The Linux kernel uses a memory paging model that is applicable to both 32-bit and 64-bit systems. For 32-bit systems, two-level page tables are sufficient, while in x86_64 systems, four-level page table is used. * Page global directory * Page parent directory (page upper directory) * Page intermediate directory (page middle directory) * page table) the global directory on the page contains the addresses of the parent directories on several pages. The parent directory on the page contains the addresses of the intermediate directories on several pages in sequence, and the central directory on the page contains the addresses of several pages and tables, each page table item refers to a page box. Linux uses a 4 kb page as the standard memory allocation unit. In practical applications, the multi-level paging directory structure partner system algorithms often need to assign a set of consecutive page boxes, and frequently apply for and release consecutive page boxes of different sizes, it is inevitable that many idle page boxes are scattered in the memory blocks of the allocated page box. In this way, even if these page boxes are idle, it is difficult for other applications that need to allocate consecutive page boxes to meet the requirements. To avoid this problem, the kernel introduces the buddy system algorithm ). All the empty and idle page boxes are grouped into 11 linked lists, each of which contains page blocks with a size of 1, 2, 4, 8, 16, 32, 64,128,256,512, and 1024 consecutive page boxes. You can apply for a maximum of 1024 consecutive page boxes, corresponding to the continuous memory of 4 MB. The physical address of the first page of each page is an integer multiple of the size of the page. Assume that you want to apply for a block with 256 page frames. First, search for the idle block from the linked list with 256 page frames. If not, find it in the linked list with 512 page frames, if found, the page box is divided into two 256 page boxes, one is allocated to the application, and the other is moved to the linked list of the 256 page boxes. If no idle blocks exist in the linked list of the 512 page boxes, continue to search for the linked list of the 1024 page boxes. If not, an error is returned. When a page block is released, two consecutive page blocks are automatically merged into a large page block. Slab is based on the Distribution Algorithm of Solaris 2.4. It runs on the physical memory page box distributor to manage the cache of objects of specific sizes for fast and efficient memory allocation. The slab splitter creates a separate buffer for each kernel object used. Linux
The kernel has adopted the partner system management physical memory page, so the slab distributor works directly on the partner system. Each buffer is composed of multiple slab, and each slab is a set of consecutive physical memory page boxes, which are divided into a fixed number of objects. By default, slab can contain up to 1024 page boxes, depending on the object size. Due to alignment and other requirements, the memory allocated to objects in slab may be larger than the actual size of the objects required by users, which may cause a certain amount of memory waste.

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.