Linux Memory Management Study Notes--Overview

Abstract: With the increase in the number of servers to be maintained, the various strange problems encountered will also increase. To completely solve these "small" problems often require deeper knowledge of Linux. The more professional and the finer the division of labor, the higher the requirements in this regard. This time, the process of exploring the problem of MySQL Swap accidentally fell into the research of Linux Memory Management (Linux MM), and it took a long time to come out. Here is a series of notes.

As the number of servers to be maintained increases, the variety of bizarre problems encountered will also increase. To completely solve these "small" problems often requires deeper knowledge of Linux. The more professional and the finer the division of labor, the higher the requirements in this regard. This time, the process of exploring the problem of MySQL Swap accidentally fell into the research of Linux Memory Management (Linux MM), and it took a long time to come out. Here is a series of notes.

Many of the contents in the notes refer to "Understanding the Linux Kernel, 3rd Edition", Linux Source Code and other places. I made some summaries by myself, and I feel that the meaningful summaries are recorded here for reference.

1. Written in the front
Linux MM is a relatively obscure system. Although there are not many theories, there are many details. To open up the entire joint from the underlying physical memory management to the upper-level virtual memory management, on the one hand, more knowledge of the underlying architecture and deep knowledge of Linux are required. Since it is a study note, let me talk about my study materials first:

1. Linux Memory Management David A Rusling This book is very old, and the Kernel at that time was still version 2.0.33; the advantage of this book is that it is very abstract, and the The basic modules and ideas of Linux_MM are introduced in an easy-to-understand manner. This is also one of the recommended readings in kernel-docs.txt;

2. Chapters 2, 8, and 17 in "Understanding the Linux Kernel, 3rd Edition" are based on the 2.6 kernel and are of great reference value. The introduction is very detailed and can be viewed together with the kernel source code.

3. Linux Source Code only read a few functions that I care about, it is not that difficult :)

I am not from a computer science class, and the foundation of the architecture is relatively poor, so it took a relatively long time to get started, and it took about a month before and after. The desk time is about 50 hours, and this is just the beginning

2. Basic framework The


above is a brief diagram, which will be introduced later, how Kernel uses memory, how Kernel manages memory allocation, and memory management in user space. Some of the details will be introduced separately, such as large page memory, memory reclamation and so on.

2. Linux startup and memory
management The first process of booting up is BIOS self-check, BIOS uses 0x00000000 to 0x10000 (1MB) memory, this 1MB memory includes the self-check program, self-check results, and a part is reserved for the display device; After the check is completed, start to load the Linux kernel. Linux starts to use physical memory from 1MB, generally 5MB is enough. You can see in the symbol information of the kernel that the Linux kernel starts from _text and ends at _edata

$more /boot/System .map-2.6.9-55.ELsmp|grep "\ _text$\|_etext$\| _edata$\| _end$"
ffffffff80100000 A _text
ffffffff80310399 A _etext
ffffffff80456aa8 A _edata
sketch:



The details of paging and segmentation under the x86 architecture are not involved here, which will be introduced separately later.

This article is very simple and is a start :)

[update 2011-03-29]

In 64-bit systems, Linux (2.6.18) starts to use physical memory from 2MB. (32-bit system, still starting from 1MB)

file: ./arch/x86_64/defconfig
CONFIG_PHYSICAL_START=0x200000
//This gives the physical address where the kernel is loaded

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326224399&siteId=291194637