Set virtual memory in Linux-create and enable Swap zone and linuxswap

Source: Internet
Author: User

Set virtual memory in Linux-create and enable Swap zone and linuxswap

If your server always reports insufficient memory and the service is forced to kill due to insufficient memory, enabling the swap area is a good choice for virtual memory. If it is an SSD hard disk, the normal read/write speed is above 300 MB/S. After swap is enabled, the performance has improved a lot, especially in processing scripts that consume a large amount of memory.

Principle for creating a swap zone:
1. The size of the created swap zone should be greater than the actual physical memory capacity, but not too large, to avoid wasting hard disk space.
2. If memory I/O requests are frequent, and the wait time of the I/O queue in a single swap zone is too long, you can create several more swap zones.
3. In principle, priority should be given to the device with the fastest I/O speed.

Procedure:
1. Create blank files for hard disk storage in the swap area.

12
# Create a 1G blank SWAP swap zone file dd if =/dev/zero of =/SWAP bs = 1 M count = 1024

Generally, 2 ~ physical memory is created ~ 2.5 times the size of the file as the swap area.

2. format the file as a swap file system using mkswap

12
Mkswap-f/swap #-f uses the file as the swap Zone

3. Enable the created Swap file

1
swapon /swap

4. If necessary, you can enable the swap file exchange zone automatically upon startup, modify/etc/fstab, and add a line

1
/Swap defaults 0 0 # enable swap upon startup

5. If you do not need to enable swap or adjust the swap size, you can use the swapoff command to disable swap.

1
swapoff /swap

After swap is disabled, delete the corresponding swap file to delete the swap area. To adjust the size of the swap area, create a new one 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.