Linux Kernel high-end Memory Management

Source: Internet
Author: User

 

Highmem

Hedgehog @ http://blog.csdn.net/littlehedgehog

 

 

 

 

 

 

I have always had a vague understanding of the management of high-end Linux memory, probably because the first time I came into contact with Linux kernel was version 0.11. The original memory design was 16 Mb, linus is eager to have 32 MB of memory, and I am afraid that 1 GB of memory is a fantasy. 16 M memory where high-end memory is taken into account, the concept has never been used in mind. Let's take a look at why there is high-end memory?

 

The linear addressing space of 80386 is 4 GB, and the kernel space starts from 3 GB. If "linear ing" is adopted (the physical address and logical address are only one constant PAGE_OFFSET), a maximum of 1 GB physical memory can be managed, that is, the physical memory of 1 GB corresponds to the 3 GB to 4 GB location of the virtual address. If the memory is larger than 1 GB,What linear addresses do we use to hold these extra addresses?My friend's machine has 2 GB, and it is said that the game is awesome (AMD64300 + ). obviously, my friends will waste 1 GB of memory for linear ing. to enable the kernel to access these "high-end memory", the kernel uses HighMem.Instead of ing all the virtual address space of 1 GB in the kernel into the physical memory, we reserve a portion for the high-end memory for temporary ing.

 

In fact, the kernel not only reserves the highmem address space, but also provides fixmap and vmalloc reserves the virtual storage space. In fact, the system reserves MB of virtual storage during initialization and MB for "direct" ing of physical memory. Next we will post a picture from understand linux kernel.

 

 

After all, obscenity tests the space imagination of everyone, so we can refer to the picture to see what the image says:

 

There are three high-end memory ing methods:

1. ing to "kernel dynamic ing space"
This method is very simple, because when applying for memory from "kernel dynamic ing space" (vmalloc_start to vmalloc_end) through vmalloc, the page may be obtained from the high-end memory (see the implementation of vmalloc). Therefore, the high-end memory may be mapped to the "kernel dynamic ing space.

2. Permanent kernel ing
If alloc_page () is used to obtain the page corresponding to the high-end memory, how can we find a linear space for it?
The kernel sets aside a linear space for this purpose, from pkmap_base to fixaddr_start (the penultimate region), to map high-end memory. On the 2.4 kernel, the address range is 4G-8 m to 4G-4 m. This space is called "permanent kernel ing space" or "permanent kernel ing space ".
This space uses the same page Directory table as other spaces. For the kernel, It is swapper_pg_dir. For common processes, it points to the table through the 33rd register.

Generally, the space is 4 MB, so only one page table is required. The kernel searches for this page table through pkmap_page_table. You can map a page to this space through kmap. Because the space is 4 MB, up to 1024 pages can be mapped at the same time. Therefore, for unused pages, and should be released from this space (that is, the ing relationship is removed), through kunmap (), you can release the linear address of a page from this space.

3. Temporary ing

The kernel reserves some linear space between fixaddr_start and fixaddr_top for special requirements. This space is called a "fixed ing space"

Some of this space is used for temporary ing of high-end memory.

This space has the following features:

1. Each CPU occupies one space

2. the space occupied by each CPU is divided into multiple small spaces. Each small space is one page, and each small space is used for one purpose, these goals are defined in km_type in kmap_types.h.

To perform a temporary ing, You need to specify the ing purpose. Based on the ing purpose, you can find the corresponding small space and use the address of the space as the ing address. This means that a temporary ing will overwrite the previous ing.

You can use kmap_atomic () to implement temporary ing.

 

 

 

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.