


The implementation of virtual memory needs to be based on the discretely allocated memory management method. There are three implementation methods: 1. Request paging storage management method; 2. Request segmented storage management method; 3. Segment page storage management method. No matter which method is used, certain hardware support is required: 1. A certain capacity of memory and external memory; 2. Page table mechanism (or segment table mechanism), as the main data structure; 3. Interrupt mechanism, when the user program needs If the accessed part has not yet been transferred into the memory, an interrupt will occur; 4. Address conversion mechanism, conversion from logical address to physical address.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
1. Overview of virtual memory
Traditional storage management keeps multiple processes in memory at the same time to allow multi-programming. They all have the following two common characteristics:
- One-time: The job must be done onceAfter all is loaded into the memory, to start running. This will lead to two situations:
1) When the job is large and cannot be loaded into the memory, the job will be unable to run;
2) When a large number of jobs are required to be run, due to insufficient memory, For all jobs, only a few jobs can be run first, resulting in a decrease in multiprogramming.- Residency: After the job is loaded into the memory, it will always resident in the memory, and no part of it will be swapped out, Until the job runs to the end. A running process will be blocked waiting for I/O and may be in a long-term waiting state.
Therefore, many programs (data) that are not used during program operation or are not used temporarily occupy a large amount of memory space, and some jobs that need to be run cannot be loaded and run, which obviously wastes precious memory. resource.
1.1 Definition and characteristics of virtual memory
Based on the localityprinciple, when the program is loaded , you can load part of the program into the memory , and leave the rest in external memory, and you can start the program execution. During the execution of the program, when the accessed information is not in the memory, the operating system will transfer the required part into the memory , and then continue to execute the program. On the other hand, the operating system swaps out the temporarily unused content in the memory to external storage, thereby freeing up space to store the information that will be transferred into the memory. In this way, since the system provides
partial loading, request transfer and replacement functions (completely transparent to the user), the user feels as if there is a Memory that is much larger than actual physical memory is called virtual memory. The
size of virtual memory is determined by the address structure of the computer, and is not a simple sum of memory and external memory.
Virtual storage has the following three main characteristics:
- Multiple times: No need to install it all at once when the job is running into memory, but allows it to be divided into multiple times and loaded into memory for execution.
- Swapability : There is no need to stay in memory while the job is running, but allows swapping in and out during the running process of the job.
- Virtuality : Logically expand the memory capacity so that the memory capacity seen by the user is much larger than the actual memory capacity.
Virtual memory allows a job to be transferred into the memory multiple times
.When the continuous allocation method is used, a considerable part of the memory space will be in a temporary or "permanent" idle state, resulting in a serious waste of memory resources, and it is impossible to logically expand the memory capacity.
Therefore, the implementation of virtual memory needs to be based on the discrete allocationmemory management method. There are three ways to implement virtual memory:
Request paging- Storage management
- Request segmentation Storage management
- Segment page type Storage management
- No matter which method is used, certain hardware support
A certain amount of memory and external storage.
- Page table mechanism (or segment table mechanism), as the main data structure.
- Interrupt mechanism, when the part to be accessed by the user program has not been transferred into the memory, an interrupt is generated.
- Address conversion mechanism, conversion of logical address to physical address.
Continuous allocation method: refers to allocating a continuous memory space for a user program.
- Fixed partition allocation: Divide the memory space into several fixed-size areas. Only one job is loaded into each partition, and multiple jobs can be executed concurrently. Lack of flexibility will produce a large amount of internal fragmentation, and memory utilization is very low.
- Dynamic partition allocation: Dynamicly allocate memory space to the process according to its actual needs. When a job is loaded into memory, the available memory is divided into a continuous area for the job, and the size of the partition is exactly suitable for the size of the job. A lot of external debris will be generated.
##Discrete allocation method: Load a process into discrete distribution To many non-adjacent partitions, you can make full use of memory.
The concept of paging storage:Pages, page frames and blocks.
- The block in the process is called page or page (Page) , with a page number; The block in the memory is called Page Frame (Page Frame, page frame = memory block = physical block = physical page ) , has a page frame number. External storage is also divided in the same unit, directly called Block. When a process is executed, it needs to apply for main memory space, which means that each page must be allocated an available page frame in the main memory, which creates a one-to-one correspondence between pages and page frames. Each page does not have to be stored consecutively and can be placed in non-adjacent page frames.
- Address structure: The first part is the page number P, and the latter part is the page offset W. The address length is 32 bits, of which bits 0~11 are the intra-page address, that is, the size of each page is 4KB; bits 12~31 are the page number, and the address space allows up to 2^20 pages.
- Page table. In order to facilitate finding the physical block corresponding to each page of the process in the memory, the system establishes a page table for each process to record the physical block number corresponding to the page in the memory, Page table Generally stored in memory. After the page table is configured, when the process is executed, the physical block number of each page in the memory can be found by looking up the table. It can be seen that the role of the page table is to implement the address mapping from the page number to the physical block number.
2. Request paging management to implement virtual memory
Request paging It is currently the most commonly used method to implement virtual memory.
The request paging system is based on thebasic paging system. In order to support the virtual memory function, the request paging function and page replacement## are added. #Function. In the request paging system, only a part of the currently required pages are required to be loaded into the memory before the job can be started.
During the execution of the job, when the page to be accessed is not in the memory, it can be brought in through the paging function. At the same time, the temporarily unused pages can also be swapped out to external memory through the replacement function to free up memory. space.
In order to implement request paging, the system must provide certain hardware support. In addition to a computer system that requires a
certain capacity of memory and external storage, it also needs a page table mechanism, page fault interrupt mechanism, and address conversion mechanism.
2.1 Page table mechanism #The page table mechanism of the request paging system is different from the basic paging system. The request paging system does not start before a job is run. All are required to be loaded into memory at once.
Therefore, during the running process of the job, there will inevitably be a situation where the page to be accessed is not in the memory. How to detect and deal with this situation are two basic problems that the request paging system must solve. To this end, four fields are added to the request page table entry, which are:
Page table entry in the request paging systemPhysical block number | Status bit P | Access field A | Modify bit M | External storage address |
7 | 0 | 1 | 2 | 0 | 3 | 0 | 4 | 2 | 3 | 0 | 3 | 2 | 1 | 2 | 0 | 1 | 7 | 0 | 1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
7 | 7 | 7 | 2 | ##2 |
2 |
##2 |
#7 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0 |
0 |
0 | 0 |
##0 | ##Physical Block 3 |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 |
3 | 3 |
##3 |
|
1 |
##1 | √ |
√ |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##√ | ##√ | ## It can be seen that the number of page fault interruptions is 9, and the number of page replacements is 6. 3.2 First-in-first-out (FIFO) page replacement algorithm The page that enters the memory earliest is eliminated first, that is, The page that has resided longest in memory. The algorithm is simple to implement. You only need to link the pages transferred into the memory into a queue according to the order, and set a pointer to always point to the earliest page. However, this algorithm is not suitable for the actual running time of the process, because some pages are frequently accessed during the process.
|
The above is the detailed content of What does linux use to implement virtual memory?. For more information, please follow other related articles on the PHP Chinese website!

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

Configuring a Debian mail server's firewall is an important step in ensuring server security. The following are several commonly used firewall configuration methods, including the use of iptables and firewalld. Use iptables to configure firewall to install iptables (if not already installed): sudoapt-getupdatesudoapt-getinstalliptablesView current iptables rules: sudoiptables-L configuration

The steps to install an SSL certificate on the Debian mail server are as follows: 1. Install the OpenSSL toolkit First, make sure that the OpenSSL toolkit is already installed on your system. If not installed, you can use the following command to install: sudoapt-getupdatesudoapt-getinstallopenssl2. Generate private key and certificate request Next, use OpenSSL to generate a 2048-bit RSA private key and a certificate request (CSR): openss


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment