Add and delete configurations for swap virtual memory in Centos

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, you need to release some of the physical memory space, 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 S only when the physical memory is insufficient.

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.

       
       
    1. Dd if =/dev/zero of =/swap bs = 1024 count = 1024000

    2. If // input

    3. Of // output

    4. Bs // block size

    5. Count // Total size


  • Create a Linux swap file

       
       
    1. mkswap    /swap/swap


  • Activate/swap switch file now

       
       
    1. swapon   /swap/swap  


  • Check whether it takes effect

       
       
    1. [root@webserver ~]# free -m  

    2.             total       used       free     shared    buffers     cached  

    3. Mem:          2007        140       1867          0          8         35  

    4. -/+ buffers/cache:         96       1911  

    5. 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:

       
       
    1. echo"/swap/swap    swap    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

       
       
    1. swapoff   /swap/swap


  • Delete a swap partition file

       
       
    1. rm -rf /swap/swap


  • Delete the specified File "/etc/swap"

       
       
    1. sed  -i "/'\/swa\/swap   swap   swap  defaults 0 0'//"  /etc/fstab


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


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.