SWAP partition in Linux

Source: Internet
Author: User
Tags linux sleep sleep function

During system installation in most Linux systems, you will be reminded and recommended to divide a SWAP partition. If you are a new user switching from Windows to Linux, you may be very confused about this SWAP.

What is the use of SWAP partition? Do we really need to partition a SWAP? The answer is: depending on the situation! SWAP partitions can improve the Linux operating system performance in some cases, but in some cases it will become a bottleneck for system operation. Next we will introduce SWAP partitions in Linux in detail.

Store memory overflow data

How to expand/delete SWAP partitions

How to Create a SWAP partition in an OpenStack Virtual Machine instance

In Linux, how many SWAP spaces should be divided?

Linux SWAP partition creation and memory release

Linux SWAP partition Configuration

Ubuntu 12.04 SWAP settings

In short, SWAP partitions are used to store data from memory overflow. We can think of the memory as a basin, and the data during running the program is put as water in the basin. If you run too many applications and cause too much water (memory) to be installed, more water will be loaded into the SWAP partition.

Theoretically, SWAP partitions increase the available memory space, but this is not the case. Because the data exchange speed in the memory is very fast, and the SWAP partition regards the physical disk as the memory carrier, that is: although SWAP allows us to run more or more applications, the data exchange speed on the physical disk is far slower than that on the physical memory, which may lead to a reduction in the running performance. Frequent read/write operations on hard disks, especially SSD disks, can also shorten the disk life and reduce the performance.

In fact, we can compare the SWAP partition to the pagefile page file in Windows, but there are still many technical differences between the two.

SWAP priority

SWAP partitions move less data in the memory to the disk to free up more memory space for other important applications, that is: less data in the memory is moved to the SWAP partition.

"Rarely used" actually depends on the "swappiness" threshold, which is actually a configuration item in Linux. A higher value in swappiness means that the data is more likely to be moved to the SWAP partition. a lower value in swappiness indicates that the data is unlikely to be moved to the SWAP partition.

SWAP and Linux sleep

Finally, you must note that the sleep data in Linux is stored in the SWAP partition. That is to say, if the system does not configure the SWAP partition, it cannot sleep in Linux.

Do you need SWAP partitions?

 

Do you need to partition a SWAP for your Linux system? Is SWAP partition necessary for you? Absolutely not! The Linux system can run well without configuring SWAP. Whether to divide SWAP partitions also has the following advantages and disadvantages:

Advantages:

  • More runtime space is provided when the memory is used up
  • Sleep

Disadvantages:

  • After SWAP's disk usage is set, it is fixed and cannot be dynamically adjusted.
  • Increases the disk read/write count and loss rate.
  • Not necessarily improve performance (see below for details)
Adverse effects of SWAP

Enabling SWAP partitions does not improve Linux performance. In some cases, using SWAP may be worse than not using it.

If you have installed Linux on a 1 GB memory and 5400 RPM hard drive netbook, you only need to open a few more browser labels and open several more applications. This will cause the memory to occupy and start using SWAP partitions. Since the hard disk is only 5400 rpm, a performance bottleneck occurs later. This is because the hard drive speed is too slow, and a large amount of data needs to be accessed to the SWAP partition, so the machine will become slower and slower. At this time, we usually need to restart the system to completely clear SWAP content.

SWAP suggestions
  • If you need the Linux sleep function, divide the SWAP partition. This partition is generally your memory size plus 10-25%
  • If your memory is less than 4 GB and you want a small Performance Improvement (at least 7200 to disk), you can divide a swap partition.
  • If your disk speed is less than 7200 RPM, we recommend that you do not divide the SWAP partition.
Change Swappiness

We can directly go to/etc/sysctl. edit the swappiness value in the conf file and find the vm in the file. swappiness and change its value (preferably 10). If you do not find this parameter, you can add it directly at the end of the file:

1 vm.swappiness=10

 

This value mainly indicates the strength of data exchange between Linux memory and SWAP partitions. If the value is 10, data is written to SWAP when the memory usage reaches 90%. The default swappiness value of Ubuntu is 60, which indicates that data is written to SWAP when the memory usage reaches 40%.

This article permanently updates the link address:

Related Article

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.