Create and enable swap zone tutorial in Linux

Source: Internet
Author: User
Tags vps

If your server is always reporting low memory, and often because the service is forced to kill because of insufficient memory, without adding physical memory, enabling the swap Swap area as virtual memory is a good choice, I buy the Digitalocean VPS 512M memory is basically not enough , fortunately, the VPS used by the hen SSD, normal read and write speed above 300mb/s, enable swap after the performance improved a lot, especially in the processing of memory-consuming scripts

Create a swap area principle:

1. The swap size created should be larger than the actual physical memory size, but not too large to avoid wasting hard disk space.
2. If the memory IO request is frequent, and the single swap swap area IO queue is too long, you can create several swap swap areas.
3. In principle, priority is created on the fastest-io device.

To create a step:

1. Create a blank file for the Swap swap area hard drive storage.

The code is as follows Copy Code

#创建一个1个G的SWAP交换区空白文件
DD If=/dev/zero Of=/swap bs=1m count=1024

You typically create a 2~2.5 of physical memory as a swap area.

2. Use mkswap format file as swap file system

The code is as follows Copy Code

Mkswap-f/swap
#-f uses files as swap swap area

3. Enable the swap file you just created

The code is as follows Copy Code

Swapon/swap

4. If necessary, you can set the power-on automatically enable swap file swap area, modify/etc/fstab, add one line

The code is as follows Copy Code

/swap Swap defaults 0 0 #启动即启用swap

5. If you do not need to enable swap or need to adjust the swap size, you can use the Swapoff command to turn off swap.

The code is as follows Copy Code

Swapoff/swap

If you close swap and delete the corresponding swap file, you can remove the swap swap area, and if you need to adjust the swap size, recreate it from the first part.

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.