In Linux, how many swap spaces should be divided?

Source: Internet
Author: User

Some time ago, a Linux server in our data center was running slowly, and the system service experienced intermittent stop response. Let me handle this problem. After logging on to the server, it is found that the physical memory of this server is 16 GB, while at the initial installation, the system administrator only allocated 4 GB of virtual memory. Check the memory usage. The physical memory is not completely exhausted, but the virtual memory is exhausted. The CPU load and disk IO of the entire system are very high.

Knowing the problem is caused by insufficient swap partitions, the solution is to increase the virtual memory to 16 GB through virtual files, and the system running status is obviously improved. In fact, the virtual memory is not used until the physical memory is used up. whether to use swap as much as possible or not, there is a parameter control in the kernel space.

[Root @ web ~] # Cat/proc/sys/vm/swappiness

60

When swappiness is set to 0, it indicates that the physical memory is used to the maximum extent, and then the swap space is used. When swappiness is set to 100, it indicates that swap partitions are actively used, in addition, the data in the memory is promptly moved to the swap space. How many swap partitions are suitable for servers with dozens of GB or hundreds of GB of physical memory? For this reason, I will give a brief description of the text in the red hat official article, hey.

Currently, RedHat officially recommends that the swap partition size be linearly proportional to the system's physical memory size, but in systems with less than 2 GB physical memory, the swap partition size should be set to twice the memory size. If the memory size is greater than 2 GB, the swap partition size should be the physical memory size plus 2 GB. The reason is that the larger the physical memory in the system, the greater the load on the memory. However, if the physical memory size is expanded to several hundred GB, it makes no sense to do so!

In fact, the size of swap partitions in the system does not depend on the amount of physical memory, but on the memory load in the system. Red Hat Enterprise Linux can work in this situation: there is no swap partition at all, and the anonymous Memory Page and shared memory page in the system are less than 3/4 of the physical memory. In this case, the system will lock anonymous memory pages and shared memory pages in the physical memory, and use the remaining physical memory to buffer the file system data (pagecache ), when the memory is exhausted, the system kernel only recycles the pagecache memory.

Consider the following situations:

1) It is difficult to determine the memory load when installing the system. How can I set the swap partition size?

2) The larger the physical memory in the system, the less swap partitions required.

Therefore, in Red Hat Enterprise Linux, the following are rules for setting the appropriate swap partition size:

Physical memory SWAP)
<= 4G At least 4 GB
4 ~ 16 GB At least 8 GB
16 GB ~ 64 GB At least 16 GB
64 GB ~ 256 GB At least 32 GB

Note:

1. But when we usually install the system, the default memory is 2 times, because there is a lot of hard disk space, and don't care about those 10 Gb space, hey! (To save trouble)

2. Other operating systems are similar.

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.