linux storage management

The linux system uses the concept of address space to manage memory data. If the physical address is exposed to the process will bring several problems:
1. Illegal programs may damage the operating system.
2. It is difficult to achieve concurrency.
Therefore, the concept of address space is introduced: an address space is a set of addresses that a process can use to address memory.
Simply put, the address space creates an abstract memory for the process. Each process has its own address space, and this address space is independent of the address space of other processes.
To ensure that multiple applications are in memory at the same time and do not affect each other, two problems need to be solved: protection and relocation.

Solve memory overload

There are two ways to deal with memory overload:
1. The simplest strategy is the swap technology : a process runs in memory first, and then runs in the disk when it is idle, then it will not occupy memory when it sleeps. When swapping, when swapping idle processes from disk to memory, the location on the memory will be different from the memory location before swapping to the disk. So it is necessary to relocate the address. In order to avoid insufficient memory due to memory growth when the process is running, we will allocate some additional memory to reserve for memory when we apply for memory.

2. Virtual memory: Each program has its own address space, this space is divided into many blocks, each block is called a page. Each page is a continuous address range. These pages are mapped to physical memory. When the program references a part of the address space in physical memory, the necessary mapping is performed by hardware. When the program is applied to a part of the address space that is not in the physical memory, the operating system is responsible for loading the missing part into the physical memory and re-executing the failed instruction.
The virtual memory technology solves the problem that the program size is larger than the physical memory size and saves computer resources. Insert picture description here
Virtual memory mainly provides three capabilities:
1. Regarding the main memory as a cache of the address space stored on the disk, only active activities are stored in the main memory, and back and forth between the disk and the main memory as needed. To transfer data, it is necessary to be able to run programs that are much larger than memory.
2. Provides a consistent address space for the process and simplifies memory management.
3. Protect the address space of each process from being damaged by other processes.

The virtual address space is composed of several pages. The operating system maintains a page table for each process. The page table stores the mapping of the process's page to the memory page frame. Insert picture description here
In different processes, if the logical addresses of two variables are the same, but because the page tables of each process are different, the result of the mapping is also different. So the physical address is completely different.

Speed ​​up the paging process

The need for large and fast page mapping has become an important constraint for building computers. So there are two ways to speed up the mapping:
1. Conversion detection buffer (TLB): It is a hardware device.
2. Software TLB management;

Page table for large memory

1. Multi-level page tables: Avoid keeping all page tables in memory all the time. The first-level page table wraps the second-level page table.
2. Inverted page table: each page frame has one table item, not each virtual page has one table item.

Guess you like

Origin blog.csdn.net/ALITAAAA/article/details/109430969