Linux system add swap virtual memory and delete configuration

Source: Internet
Author: User

1.swap Overview

Swap partition, or swap area, the role of swap space can be simply described as: when the system's physical memory is not enough, it is necessary to release some of the space in physical memory, for the current running program to use. The freed space may come from programs that are not operating for a long time, and these freed spaces are temporarily saved to the swap space, waiting for those programs to run, and then recover the saved data from swap to memory. In this way, the system always swaps when there is not enough physical memory. In fact, swap tuning is critical to the performance of Linux servers, especially Web servers. By adjusting swap, you can sometimes bypass system performance bottlenecks and save system upgrade costs.

2. Create swap

Because you forgot to create the swap partition when you installed the CentOS 6.0 operating system, the alert occurs when you use Zabbix to monitor the server. It was then discovered that the swap partition was not created. So you need to create a swap partition that looks like this:

First, use the user with root permission to log in to the system via SSH remote login or local terminal to create the swap partition

DD If=/dev/zero Of=/swap/swap bs=1024 count=1024000

If//input

of//Output

BS//block size

Count//Total size

Create a Linux swap file

Mkswap/swap/swap

Activate/swap/swap Exchange file now

Swapon/swap/swap

See if it takes effect

[Root@webserver ~]# Free-m

Total used free shared buffers Cached

MEM:2007 140 1867 0 8 35

-/+ buffers/cache:96 1911

swap:972 0 972

As you can see from the above output information, you have successfully created the swap partition.

Set to permanent effect

Although it is now in effect, wait until the next time the server restarts. The swap virtual disk will be invalidated and the following instruction set needs to be added to the/etc/fstab file to ensure permanent effect:

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

So far, the swap partition has been created.

2. Delete the swap partition

Sometimes you may need to delete the swap partition, how do I delete the partition correctly?

First stop the Swap partition

Swapoff/swap/swap

Delete a swap partition file

Rm-rf/swap/swap

Delete "/etc/swap" specified file

This allows you to manually add and remove swap partitions.

Copy Code

The code is as follows:

Sed-i "/'/swa/swap Swap swap defaults 0 0 '//"/etc/fstab

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.