Linux memory management

Source: Internet
Author: User

I. Linux memory structures include node, zone, and page)

Node ---- {zone ----- {page

......

{Zone ----- {page

Ii. How to map high-end memory:

Permanent kernel mapping and temporary kernel mapping and noncontiguous memory)

1) Permanent ing:

Using a page table stored in the kernel is equivalent to creating a page table ing, because the operation page table may sleep.

Void * kmap (struct page * page );

Usage:

Struct page * page = alloc_pages (gfp_highmem, 1 );

Int * vaddr = kmap (PAGE );

2) Temporary ing:

It is implemented by using a page table entry stored in the kernel. This is equivalent to creating a page table ing, which does not cause sleep.

Void * kmap_atomic (struct page * page );

Usage:

Struct page * page = alloc_pages (gfp_highmem, 1 );

Int * vaddr = kmap_atomic (PAGE );

Iii. Memory region Management

The zone and Buddy algorithms solve the problem when applying for a page box: hardware restrictions and memory fragments.

In actual kernel programming, the most common problem is the application and release of MEM requests with different size data structures. To solve the problem of Memory Request efficiency and memory fragmentation,

The cache and slab need to be used for the following reasons:

1) it is quite common to apply for and release the same size of memory. To prevent the kernel from getting tired of these tasks, the kernel provides a method: to build an Slab System Based on cache, each Slab

The corresponding memory unit size is met in a timely manner when the application is made, and the software is recycled when the application is released. This avoids frequent page box operations.

2) to solve the memory fragmentation problem,

Iv. Management of non-contiguous memory zones

The Discontinuous memory area refers to the vmalloc area with consecutive linear addresses and discontinuous physical addresses. This area is used to map the physical memory page boxes that exceed MB,

Generally, it is only applicable to x86 architectures, and embedded architectures such as arm seldom use such a large amount of memory. Therefore, in the ARM architecture, kmap, permanent kernel ing,

No fixed kernel ing is available.

In fact, the implementation of vmalloc is to apply for several page boxes through alloc_pages. Of course, these page boxes are located in highmem to meet the size of the applied memory,

Then, modify the page table and create a ing between the vmalloc linear address segments and these page tables.

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.