[Linux study notes] add and delete configurations for swap virtual memory

Source: Internet
Author: User
1 Swap overview Swap partition, that is, swap zone. The role of Swap space can be simply described as: when the system's physical memory is insufficient, it is necessary to leave a part of the physical memory empty 1. Swap overview
Swap partition, that is, Swap zone. The role of Swap space can be simply described as: when the physical memory of the system is insufficient, a part of the physical memory needs to be released, for the currently running program. The released space may come from some programs that haven't been operated for a long time. the released space is temporarily saved to the Swap space and will be executed by those programs, then, the stored data is restored from Swap to the memory. In this way, the system always performs Swap switching when the physical memory is insufficient. In fact, Swap adjustment is crucial to the performance of Linux servers, especially Web servers. By adjusting Swap, the system performance bottleneck is sometimes crossed to save system upgrade costs.
2. create a swap
When you install Centos 6.0, you forget to create a swap partition. as a result, zabbix is used to monitor the server. Then we found that no swap partition was created. Create a swap partition as follows:
First, use a user with ROOT permissions to remotely log on to the system through SSH or a local terminal to create a swap partition.
Dd if =/dev/zero of =/swap bs = 1024 count = 1024000

If // input
Of // output bs // block size
Count // Create a Linux swap file in total size
Mkswap/swap activate immediately/swap file
Check whether swapon/swap takes effect
[Root @ webserver ~] # Free-mtotal used free shared buffers cached
Mem: 2007 140 1867 0 8 35-/+ buffers/cache: 96 1911
Swap: 972 0 972 the above output shows that the swap partition has been successfully created.
Set to permanently valid
It takes effect now, but wait until the next restart of the server. This swap virtual disk will become invalid. to ensure permanent effectiveness, you need to add the following instruction set in the/etc/fstab file:
Echo "/swap defaults 0 0">/etc/fstab so far, the swap partition has been created.

2. delete swap partitions

Sometimes you may need to delete the swap partition. how can you delete the partition correctly?

Stop swap partition first
Swapoff/swap delete swap partition file
Rm-rf/swap delete the specified File "/etc/swap"

In this way, you can manually add and delete swap partitions.

Sed-I "/'\/swa \/swap defaults 0 0' //"/etc/fstab
Related Article

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.