Ali cloud server to create a swap partition, to solve the problem of insufficient memory

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qiuchangyong/article/details/89929284

I did not expect Ali cloud server gcc compiler ffmpeg also encountered error:

internal compiler error: Killed (program cc1plus)
Please submit a full bug report,

After Baidu, and know that this is caused due to insufficient memory. Ali cloud from the official website that:

swap functions with parameters corresponding to the kernel

Linux part is divided into memory segments of physical memory is called a "page." Refers to the exchange memory page is copied into the preset hard disk space (called a swap space) in the process, release the memory for the purpose of the page. The total size of physical memory and swap space is the amount of virtual memory available. Swap space is usually a disk partition (the partition when the operating system is installed, the system will typically default is a space partitioned for swap, swap space default size is set to 1 to 2 times the memory), or may be a file.

Vm.swappiness kernel parameters is a parameter that represents the extent of the kernel to the preference (or dislike) swap space. Swappiness can have a value from 0 to 100, the default size is typically 60, but some 30. Set this parameter to a low value would reduce the memory exchange, so as to enhance the responsiveness of the system number. If memory is more abundant, it can be vm.swappiness size is set to 30, if less memory may be set to 60. If this value adjustment is too large, the performance of memory loss may have been able to provide, and to increase consumption of disk IO and CPU consumption.

Ali and so on host swap function

Ali cloud provides a cloud server (Elastic Compute Service, referred to as ECS), a host of cloud, virtualization drive current is used in Xen (This can be seen by the bios vendor and virtual type).

By default, swap function Ali and so the host is not enabled, because of course, can reduce the disk IO usage by eliminating the swap feature to allow users to buy more memory, increase disk performance and life.

Ali, the current approach is:

1. Do not create a swap partition is determined by the mirror

2. vm.swappiness set to 0, that is, never use the swap partition

Enabling swap partition, can indeed reduce memory usage pressure, but not a permanent solution, if the application running on the host cloud does require higher memory, recommendations or buy more memory.

So we need to open the swap partition function. See https://blog.csdn.net/qq_35330699/article/details/81223765

Check swap

First, create a swap swap

1, increase the size of the swap 4G

dd if=/dev/zero of=/var/swap bs=1024 count=4096000

means if input file, of a output file. dev / zero linux is an input device for creating an empty file for initialization, such as temporary swap file, it can provide any number you need. refers bs block size, block size byte blocks Block unit data, read / output is 1024 bytes, count = 4096000: a data block (block) number is 4096000, 4096000 i.e., 1024 bytes (1024 bytes = 1kb ). It can be calculated swap partition capacity: 4G. (Dd command expressed in the unit of M 1024 * 1024, k represents 1024)

2, create a swap file

mkswap /var/swap

Note that there is a space between mkswap and / var / swap

3, load this file

swapon / var / swap

Note that there is a space between swapon and / var / swap

The commands above may appear: "unsafe permissions 0644, 0600 recommended" prompt, in fact, has been activated, you can ignore, modify the permissions:

chmod 0600 /var/swap

4, when setting up the system automatically mount the partition boot

Add to / etc / fstab

echo "/var/swap swap swap defaults 0 0" >> /etc/fstab

 

5, view the partition size

free -m

If printed Swap: 0 0 0 Description no zoning

 

Second, delete the swap partition

Stop using partition

swapoff /var/swap

delete

rm -rf  /var/swap
 

But also to add:

See kernel parameter value is 0 in vm.swappiness, if 0 is adjusted according to actual needs 30 or 60

1

2

3

cat /proc/sys/vm/swappiness   

sysctl -a | grep swappiness    

sysctl -w vm.swappiness=60

Note: If you want to permanently modify, edit /etc/sysctl.conf file

Sure enough, after the discovery modify a lot better, but also for other linux server so dry.

 

 

Guess you like

Origin blog.csdn.net/qiuchangyong/article/details/89929284