Linux Memory management

Source: Internet
Author: User
Two main features of linux Memory management are process virtual memory and kernel memory allocation. First, let's talk about the virtual memory of processes. linux uses a three-level page table structure, which consists of the page Directory, Page Center Directory, and page table. Page Directory: an active process has a page Directory. the page directory size... information & nbs

Two main features of linux Memory management are process virtual memory and kernel memory allocation.

First, let's talk about the virtual memory of processes. linux uses a three-level page table structure, which consists of the page Directory, Page Center Directory, and page table.

Page Directory: an active process has a page directory with a size of one page. each item in the page Directory points to a page in the middle of the page Directory.

Page Center Directory: the page center directory can have multiple pages. each item of the page Center Directory points to one page in the page table.

Page table: a page table can contain multiple pages. each page table item points to a virtual page of the process.

The address translation in the virtual memory solution is as follows:

To improve the read/write memory efficiency, linux maps consecutive pages to consecutive leaf boxes. for this purpose, linux uses the kernel of the partner system to maintain a series of fixed-size leaf boxes. a set of pages can contain 1, 2, 4, 8, 16, and 32 leaf boxes, when a page is allocated or recycled in memory, the available groups are split or merged using the partner algorithm.

The page replacement algorithm in linux is a variant of the clock algorithm.

 

 

What is the kernel memory allocation? the kernel memory management physical memory page is mainly used to allocate and recycle specific pages. the page owner may be a user space process, dynamic Distribution of kernel data, static kernel code, and high-speed cache. linux kernel memory allocation uses a paging mechanism based on user virtual memory management, in the paging mechanism, the partner algorithm can be used to allocate one page or multiple pages. Therefore, the smallest unit of this allocation is the page, and there are many small objects in the kernel, these objects are frequently constructed and recycled, such as inode. if a page is requested from the kernel every time a component is built, but the actual size may be several bytes, this is a waste, therefore, linux uses an slab mechanism when allocating pages. Generally, the page size is 4 kB, and slab is used to allocate a small storage area in the same page box, blocks with less than one page can be unallocated to 32, 64, 128, 256... 4048 bytes. linux maintains a set of cache linked lists. each block size corresponds to a linked list. The blocks can be merged in a way similar to the partner algorithm and moved between the linked lists.

The slab layer mainly plays two roles:

1. slab can allocate small objects so that no page box is allocated for each small object, saving space.

2. some small objects in the kernel are frequently created. slab caches these small objects and can reuse the same objects to reduce the number of memory allocations.

The slab structure is as follows:

In linux, cache is used to manage blocks or objects of the same size. Each cache contains a set of slab lists. There are three types of slab linked lists:

Slab_full: completely allocated, no idle list

Slab_partial: List of allocated parts

Slab_free: slab that is completely idle

When the request memory is sent, it will first be searched from slab_partial. if not, it will be searched in slab_free and then put this slab into slab_partial.

Compared with the traditional memory management mode, the slab cache distributor provides many advantages. First, the kernel usually relies on the allocation of small objects, which will be allocated countless times in the system lifecycle. The slab cache distributor provides this function by caching objects of similar sizes, thus avoiding common fragmentation problems. The slab splitter also supports initialization of common objects, thus avoiding repeated initialization of an object for the same object. Finally, the slab splitter supports hardware cache alignment and coloring, which allows objects in different caches to occupy the same cache row, thus improving the cache utilization and improving performance.

Reference: https://www.ibm.com/developerworks/cn/linux/l-linux-slab-allocator/

Related Article

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.