Differences between swap, virtual memory, and page

Source: Internet
Author: User

Previous operating systems were in real mode, such as DOS. Only one process is running at a time, and the process uses all the physical memory.

Later, the protection mode was developed, with multiple processes in time-sharing mode. A cpu runs multiple processes, but the process does not know how much memory can be used. It can access the maximum memory address. For example, a 16-bit system can access 2 ^ 16 byte, and 32 is 2 ^ 32. But actually there is not that much memory? What should I do? The protection model came into being.

Assume that the process is Liu Xiang, and the referee (system) starts to run. But the referee said it would take 1 second for you to run 100 meters. So Liu Xiang started running (memory address). One second later, Liu Xiang only ran for 10 meters. The referee said, "Liu Xiang, you'll have a rest first. I'm going to blow a whistle to Wang Junxia, now remember where you are running (protection). It will start from here. The referee gave Wang Junxia a whistle, one second, and then Liu Xiang another second. Few people start to run, and Liu Xiang can stand on the runway to rest. Later, as there were more and more people running and the runway was crowded with people, some people could only be moved to the grass next to the runway to rest (exchange ). Later, it was found that some people were lying in full swing, occupying a lot of space, so it was stipulated that everyone could only stand (PAGE), which could accommodate a lot of people.

Swap-lawn is the hard disk space for storing pages.
Virtual Memory-assume that Liu Xiang has been running n laps in Beijing, but they are still in place. Virtual machines do not exist.
Page -- cells on the lawn, each containing only one person.

In order to improve disk access efficiency, Linux has made some careful designs, in addition to caching dentry (for VFS, accelerating the conversion of file path names to inode ), two major cache methods are also adopted: buffer cache and page cache. the former is used to read and write disk blocks, and the latter is used to read and write inode files. these caches effectively shorten the time for I/O system calls (such as read, write, getdents.

Memory activity can basically be quantified using three numbers: total active virtual memory, swapping rate and paging rate. the first digit indicates the total memory demand, and the last two digits indicate the proportion of memory in use. the goal is to reduce memory activity or increase the amount of memory until the page rate remains at an acceptable level.

Total active virtual memory (VM) = actual memory size (size of real memory) + used swap space (amount of swap space used)

When the program requires more memory than the physical memory, the UNIX system uses the page adjustment mechanism, that is, the system copies some pages in the memory to the disk, and releases the space for the process to use.

Most systems can tolerate occasional page adjustments, but frequent page adjustments will cause a sharp drop in system performance.

UNIX memory management: the UNIX system manages the memory in two ways: "Page adjustment algorithm" and "exchange technology ".

The paging algorithm is used to change pages that are not frequently used in the memory to disks and keep frequently used pages (Active pages) in the memory for the process to use.

Switching technology means that the system switches the entire process, not some pages, to the disk. Under normal circumstances, the system will have some exchange process.

When the memory is seriously insufficient, the system will frequently use paging and swap, which increases the disk I/O load. This further reduces the execution speed of the system on the job, that is, the system I/O resource issue will affect the allocation of memory resources.

UNIX virtual memory

UNIX virtual memory is a very complex sub-system. It implements the transparency of the code and data sharing mechanism between processes, and can allocate more memory to the existing physical memory of the system, some operating system virtual storage can even affect the performance of the file system by providing the cache function. The implementation of UNIX virtual storage in various styles is very different, but they cannot be separated from the following four concepts.

1: actual memory

The actual memory refers to the physical memory actually exists in a system, which is called ram. The actual memory is the fastest and most effective way to store temporary data. Therefore, you must allocate it to applications as much as possible. There are multiple ram forms: Simm, dimm, Rambus, DDR, etc, many Ram users can use the error correction mechanism (ECC ).

2: swap space

Swap space is a disk space dedicated for temporary storage of memory. It is usually used for page scheduling and process data exchange. It is recommended that swap space be two to four times the size of physical memory.

3: Page Scheduling

Page scheduling refers to the process of transferring data from the disk to the memory, and the opposite. This process is called page scheduling because the Unix memory is evenly divided into large and small equal pages; the page size is usually 4 kb and 8 KB (you can use the pagesize command in Solaris to view the page size ). When an executable program starts to run, its image is converted from the disk page by page. Similarly, when some programs are idle for a period of time, they can be swapped out to the swap space, so that free RAM can be handed over to other programs that need it.

4: Exchange

Page scheduling is often confused with the concept of switching. Page scheduling refers to transferring the idle part of the memory occupied by a process to the disk, switching means that when the actual memory in the system is insufficient to meet the new allocation requirements, the entire process is transmitted to the disk. Switching activities usually mean that the memory is insufficient.

Vmstat monitors memory performance: this command is used to check statistics of virtual memory and displays Process status, idle and swap space, paging, disk space, CPU load, and swap, cache refresh and interrupt information.

Procs

R: The number of processes waiting for run time.

Number of processes running and waiting (CPU time slice). This value can also determine whether to increase the CPU (more than 1 for a long time)

B: The number of processes in uninterruptable sleep.

Number of processes that are in the non-disruptive state, which is usually caused by Io.

W: The number of processes swapped out but otherwise runnable.

Memory

SWPD: The amount of virtual memory used (KB ).

Free: The amount of idle memory (KB ).

Idle physical memory

Buff: The amount of memory used as buffers (KB ).

Used as the buffer cache memory to buffer reading/writing of Block devices

Cache: The amount of memory used as cache.

Swap

Si: amount of memory swapped in from disk (kb/s). Virtual Memory Page import (import Ram from swap disk)

So: amount of memory swapped to disk (kb/s). Page export of virtual memory.

(From Ram to swap disk)

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.