Linux kernel (v) virtual memory

Source: Internet
Author: User

 Reprint Please specify the Source:Jiq ' s technical Blog

The Memory Management Unit (MMU) completes the conversion of the virtual storage address to the physical address.


1 What is virtual memory:

Two key technologies of virtual memory:

( 1 ) page table ( address transformation mechanism " virtual address ( continuous ) ( discontinuous pages "

( 2 ) page replacement functionality. put the temporarily unused pages to disk, allowing the running to get a larger physical space.

Virtual memory is a technology of computer system memory management. It allows the application to assume that it has contiguous available memory (a contiguous, complete address space), and in fact, it is usually separated into multiple physical memory fragments, and some are temporarily stored on external disk storage and exchanged for data when needed. (Page replacement algorithm)

Systems that use this technology make it easier to write large programs than systems that do not use virtual memory technology, and are more efficient at using real physical memory, such as RAM.

Note: Virtual memory is more than just "using disk space to extend physical memory"-this simply expands the memory level to include the hard drive. Extending memory to disk is only a result of using virtual memory technology, and its role can be achieved by overwriting or swapping the inactive programs and their data all the way to disk. The definition of virtual memory is based on the redefinition of the address space, which defines the address space as a "contiguous virtual memory address" in order to "spoof" the program so that they think they are using a chunk of "contiguous" addresses.

All modern operating systems for general applications use virtual memory technology for common applications, such as word processing software, spreadsheet software, multimedia players, and so on. Older operating systems, such as DOS and windows of the 1980, or those of the 1960 's mainframes, generally do not have the functionality of virtual memory-but atlas,b5000 and Apple's Lisa are notable exceptions. [1]

Embedded systems that require fast access or very consistent response times, and other computer systems for special applications, may choose not to use virtual memory in order to avoid reducing the predictability of computational results.

2Linux the virtual memory in

The Linux operating system supports two forms of swap space: swap partitions and swap files .

Swap partition: A disk partition is dedicated to swapping swap files: Creating a file for swap swap space does not specify a specific value, and if physical memory is small (less than 512M bytes), it is generally set to 1.5 times times the physical memory of twice times.

Linux supports the use of multiple switching devices at the same time, as well as assigning them to different priority levels. When you need to swap out physical in-memory pages, the operating system selects the available switching devices based on the order of precedence. If there are multiple swap devices with the same priority, they are allocated in a similar level0raid manner. If you can access these switching devices in parallel, assigning them the same priority will enable system performance to be provided. Therefore, you should pay special attention to some of the issues when assigning priorities. For example, multiple swap partitions on the same physical disk should not be used in parallel, but should be used in the order in which the access speed is high. So when there is only one physical disk, setting up multiple swap partitions does not improve performance, but may degrade performance.

3 Why virtual memory?

(1) Security:

(a) isolation of different processes:

By mapping the virtual storage space of different processes to different physical memory, the physical isolation between processes is realized. Makes it impossible for one process to access the process space of other processes. :

(b) Isolate the implementation of the user mode and kernel mode------Dual processor modes:

Dual processor mode refers to user mode and kernel mode. Through the virtual storage mechanism, the operating system uses two sets of different mapping registers to map user space and kernel space to different physical memory, thus eliminating the possibility of direct user program Access (rather than using system calls) of kernel space.

For example, a 16-bit application Hello_jiq, the maximum address space is 64k, where 32k space 0x0~0x7fff is mapped to the physical memory of 0X4000~0XBFFF, the remaining 32k space 0x8000~0xffff is not made any mapping. The kernel space is mapped to the physical memory 0x0~0x3fff.

When an application accesses 0X0~0X7FFF, it actually accesses the 0x4000~0xbfff of the physical space, and the bus error is caused by no mapping when accessing 0X8000~0XFFFF. Anyway, it doesn't have access to kernel space anyway.


(2) Increase space utilization:

Due to the limit of the instruction word length of the program instruction, it can only access 16-bit 64K address space.

However, the bus supports 18-bit address mode with a maximum physical space of up to 256K.

Actual memory dram is also more, generally greater than 256K or even higher.

However, the instructions of the user program can only access the physical memory of 0-64k if the physical memory is accessed directly (not accessing the 64k-256k section).

Using virtual memory, you can map each 64K space of a process to every 64K part of physical memory (including the high-address physical space portions that were not previously accessible). Multiple processes can take full advantage of all memory space.

(3) Multi-process support:

Any process can allocate code areas and data areas in its own "0-64k" space. If there is no virtual storage mechanism, and any process is trying to use the 0-64k address space, but only one process can use it at the same time, it can be difficult to implement.

(4) Another important function of virtual storage in modern operating system is the dynamic link of realization program!!!

Compiling---> Linking---> Loading---> Running

Linux kernel (v) virtual memory

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.