[Linux] Create and enable swap swap areas

Source: Internet
Author: User
Tags vps

If your server is always reporting low memory, and often because of insufficient memory to cause the service to be forced to kill, without increasing physical memory, enable swap area as virtual memory is a good choice, I purchased the Digitalocean VPS 512M memory is not enough , fortunately, the use of a VPS hen SSD, the normal read and write speed is above 300mb/s, the performance improved after the swap enabled, especially in the processing of large memory-consuming script

Create swap principle:
1. The swap size created should be larger than the actual physical memory capacity, but not too large to avoid wasting hard disk space.
2. If the memory IO requests are frequent, and the single swap zone IO queue waits too long, you can create several swap zones more.
3. In principle, priority is created on the device with the fastest IO speed.

To create a step:
1. Create a blank file for swap area hard disk storage.

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

Usually create physical memory 2~2.5 times the size of the file as the swap area.

2. Using Mkswap format file as swap file system

12
Mkswap-f/swap#-f using files as swap swap areas

3. Enable the swap file you just created

1
Swapon/swap

4. If necessary, you can set up auto-enable swap file swap area, modify/etc/fstab, add one line

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

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

1
Swapoff/swap

Delete the swap after closing swap, and if you need to resize the swap area, recreate it from the first section.

[Linux] Create and enable swap swap areas

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.