Linux Swap swap Space

Source: Internet
Author: User

Linux memory manages the entire memory through virtual memory, and physical RAM physical memory and swap space are the total virtual memories.

Swap usage Scenarios

There are two main uses of swap

1, when the system needs more memory space than the physical memory, the kernel will use less memory inside the memory page swap out to the swap partition, to empty the physical memory to the current should be used to quickly run.

2, some applications when the start of the initialization but the subsequent application is no longer used during the memory page, the system will swap out this part of the page to swap space, to leave the physical memory page to other applications or disk cache.

This memory management strategy for Linux is primarily used to conserve physical memory and improve the execution speed of the current application. But swap cannot be used as a means of expanding memory because swap reads and writes are disk IO, which is much slower than the IO of physical memory.

If the system frequently swaps out memory pages to the swap partition and then swap in swap partitions to memory pages, this indicates that the system is looking for free memory to be run concurrently by multiple applications, which means that the current system task is busy, but the available memory is not enough. The only way to do this is by raising physical memory.

So measuring whether a system's memory usage is a bottleneck can be assessed by observing the swap amount and the frequency of SI so.

Generate swap

Swap space has two forms: one is the swap partition and the other is the swap file. In short, it reads and writes all disk operations.

1. Swap partition

The swap partition can be assigned when the operating system is installed, or it can be used to partition a swap partition with Fdisk after entering the system.

For example, partitioning a/DEV/SDA5 partition on a disk and then marking it as a swap partition.

Then use the Mkswap command to create a swap partition file system on the partition:

Mkswap/dev/sda5

Finally, the swap partition is activated:

Swapon/dev/sda5

2. Exchange of documents

Swap space can also be a file, only need to use the DD command on the disk to establish a file size allocated/home/swapfile

Establishing a Swap partition file system

Mkswap/home/swapfile

Finally activate it

Swapon/home/swapfile

Allocation strategy for Swap space size

Swap space size distribution, there are said that physical memory twice times, there is said physical memory size, there is also said physical memory half. In different scenarios, these statements should all be true. (therefore, the examiner may not really understand the swap) if you take an absolute statement in person.

The following is a red Hat distribution strategy:

Swap should equal 2x physical RAM for up to 2 GB of physical RAM, and then a additional 1x physical RAM for any amount ab Ove 2 GB, but never less than MB.

So, if:

M = Amount of RAM in GB, and S = Amount of swap in GB, then

If m < 2S = m *2elses = m + 2


There is an if else pseudo-code to calculate swap, and finally there is a sentence:

For systems with really large amounts of RAM (more than + GB) can likely get away with a smaller swap partition (Arou nd 1x, or less, of physical RAM).

So how to divide, but also to see the specific application scenarios, as long as not outrageous, are correct.

The Red Hat system also has a note:

Important

File Systems and LVM2 volumes assigned as swap space cannot is in use when being modified. For example, no system processes can is assigned the swap space, as well as no amount of swap should be allocated and used by the kernel. Use the free and cat /proc/swaps commands to verify how much and where swap are in use.

The best-Achieve swap space modifications is-to-boot your system in rescue mode, and then follow the instructions ( For each scenario) in the remainder of this chapter. Refer to the Red Hat Enterprise Linux Installation-instructions on booting into rescue mode. When prompted to mount the file system, select Skip.

Here is another swap allocation strategy for most systems and scenarios:

A rule of thumb is as follows:

1) for a desktop system, use a swap space of double system memory, as it would allow you to run a large number of Applicati ONS (many of which may would be is idle and easily swapped), making more RAM available for the active applications;

2) for a server, there is a smaller amount of swap available (say half of physical memory) so which you have some flexibility F Or swapping when needed, but monitor the amount of swap space used and upgrade your RAM if necessary;

3) for older desktop machines (with say only 128MB), use as much swap space as can spare, even up to 1GB.

Swap optimization

Linux 2.6 Adds a new parameter to manage swap, called swappiness , swappiness can have a value of 0 to 100. Setting this parameter to a lower value will reduce the swapping of memory, thereby increasing the responsiveness of some systems.

The higher the value, the more memory pages swap out into the swap space, the lower the value, the more the application uses the physical memory space. Therefore, to maximize the use of physical memory, you should try to reduce the value of swappiness or even set to 0.

The default setting for Linux is 60, which temporarily modifies its value:

echo >/proc/sys/vm/swappiness

To permanently modify the vm.swappiness parameter can be modified in the/etc/sysctl.conf file

Reference Links:

Https://www.linux.com/news/software/applications/8208-all-about-linux-swap-space

Https://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-swap-what-is.html

HTTPS://WIKI.ARCHLINUX.ORG/INDEX.PHP/SWAP_ (%e7%ae%80%e4%bd%93%e4%b8%ad%e6%96%87)

Linux Swap swap Space

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.