Article Title: Linux operating system restrictions on virtual memory. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. Description of 2 GB virtual memory limit
1. Early linux restrictions on Virtual Memory
The Linux kernel earlier than linux2.2 supports Linux swap partitions or files up to MB. Linux swap has no more than 16 partitions or files.
Therefore, before linux2.2, the maximum available virtual memory was 128 MB * 8 = 1 GB.
2. Linux2.2.x limitations on Virtual Memory
Linux2.2.x supports Linux swap partitions or files up to 2 GB. The total number of Linux swap partitions or files cannot exceed 8.
Therefore, in Linux2.2.x, the maximum available virtual memory is 2 GB x 8 = 16 GB.
3. Linux2.4.x restrictions on Virtual Memory
Linux swap partitions or files with a maximum of 2 GB are supported before Linux2.4.10. The total number of Linux swap partitions or files cannot exceed 8.
Therefore, before Linux2.4.10, the maximum available virtual memory is 2 GB x 8 = 16 GB.
Linux swap partitions or files with a maximum of 2 GB are supported after Linux2.4.10 (inclusive. Linux swap has no more than 32 partitions or files.
Therefore, after Linux2.4.10, the maximum available virtual memory is 2G * 32 = 64G
In terms of memory management policy, like the change from Windows 98 to Windows, Linux2.4.x saves more dirty pages in the memory and swap areas, rather than timely memory recovery, to improve system efficiency. (See Chapter 18th of Widnows core programming ).
In addition, if you have more than one disk and have created swap on different disks, linux uses these swap partitions in raid 0 mode.
2. How much virtual memory is better?
1. Linux 2.2.x (inclusive) and earlier
The traditional 2 times Virtual Memory concept is effective. We recommend that you use this method for allocation.
2. Linux 2.4.x (inclusive) and later
Considering the appropriate hard disk cost, the demand for virtual memory is more favorable.
Linus clearly states that even a M memory can allocate up to 40 Gb swap zone to improve system performance. Zlatko verified the performance of Linus. Zlatko's experiment shows that the disk I/O fee is not increased in the big swap zone policy.
Iii. Instances
An IBM x365 server with 4 GB memory.
1. the minimum value of the SWAp zone is no less than 4G.
Create two 2G swap zones for each of them as the basic 4G swap Partition
2. Create 8 2G swap files as extended swap partitions
In this way, the total swap partition is about 20 GB. If the hard disk is larger, the maximum number of swap partitions can be increased.
Digress: virtual memory usage in Windows
Since windows, Microsoft has also changed its memory usage policy. They will recycle the memory as late as possible. Therefore, I personally believe that a large exchange zone is more efficient for systems above Windows2000.
Appendix: Linus conversation recording
In the following discussion, it is clear that the Linux2.4 version requires more swap areas than the previous version. Rik val Riel warned: "2.4 (kernel) keeps more dirty pages in the SWAp zone cache, so for the same program, you need more memory to run it ......". He asked Linus Torvalds, "this is something we need to maintain, or we will tell the user that it will run in a certain mode when the swap zone is released, when we exchange data in some non-shared areas?" Linus replied: "I 'd love to see this in the documentation and keep it. I hate two unfair behavior methods. It always recommends "two times the memory (SWAP zone size)". Although we were told in history that "Linux doesn't actually need that much", in linux2.4.x, I really abandoned this idea.
If you have MB of memory, you can request a 40 Gb swap zone. They have become very cheap today.
Zlatko Calusic worries that a larger swap zone will reduce performance because the disk needs more time to search for data. He asked Linus if he confirmed this would not happen. Linus replied: "I'm not _ OK _. As we all know, in any case, I only confirm one thing, that is, the page buffering adhesion, it can simplify many things and make some previously impossible things possible." But recently, he added: "sticking to build may make our IO more dispersed ".
Zlatko did some tests and did not find any problems with the memory management policy of version 2.4.0. He said: "I found that the new kernel will apply for 4 times of swap space in some environments. This may be, or it may not be a problem. It remains visible.