Linux system add swap virtual memory and delete configuration method

Source: Internet
Author: User

  


Brother even Linux training tutorial Linux system add swap virtual memory and delete configuration (www.lampbrother.net)

1.swap overview

swap partition, swap area, swap space can be simply described as: when the system's physical memory is not sufficient, it is necessary to release some of the space in physical memory for use by the currently running program. The freed space may come from programs that have not been manipulated for a long time, and the freed space is temporarily saved to swap space, waiting for those programs to run, then from swap . This way, the system is always swap interchange when there is insufficient physical memory. In fact, swap 's adjustment to linux server, especially web server performance is critical. By adjusting the swap , it is sometimes possible to bypass system performance bottlenecks and save system upgrade costs.

  2. Create Swap

Because you forgot to create a swap partition when installing the Centos 6.0 operating system, an alarm occurs when you use Zabbix to monitor the server. Only then did you find that the swap partition was not created. So you need to create a swap partition that works as follows:

First, a user with ROOT access via SSH remote login or local terminal log in to the system, to create a 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 swap file now

  Swapon/swap/swap

See if it takes effect

  [Email protected] ~]# 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 output above, the swap partition has been successfully created.

Set to permanent effect

Although it is now in effect, wait until the next time the server restarts. The swap virtual disk will fail to be valid for permanent use, and you will need to add the following instruction set in the /etc/fstab file:

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

So far, theswap partition has finished creating.

  2. Delete a swap partition

Sometimes you may need to delete a swap partition, how do you 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 the code code as follows :

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


Linux system add swap virtual memory and delete configuration method

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.