[linux study notes] swap virtual memory add and delete configuration

  
        1.swap outlines the Swap partition, that is, the swap area. The role of the Swap space can be simply described as: When the physical memory of the system is not enough, a part of the space in the physical memory needs to be released for use by the currently running program. The freed space may come from programs that haven't been manipulated for a long time. These freed spaces are temporarily saved to the Swap space, and when those programs are running, the saved data is restored from Swap to memory. In this way, the system always performs Swap exchange when the physical memory is insufficient. In fact, Swap's tuning is critical to the performance of Linux servers, especially Web servers. By adjusting Swap, you can sometimes overcome system performance bottlenecks and save system upgrade costs. 2. Create a swap due to the forgotten creation of the swap partition when installing the Centos 6.0 operating system, causing an alarm when monitoring the server using zabbix. At this time, I found that the swap partition was not created. So you need to create a swap partition, the operation is as follows: First, use the user with ROOT permission to log in remotely via SSH or the local terminal to log in to the system to create a swap partition dd if=/dev/zero of=/swap/swap bs=1024 count =1024000if //Enter of //output bs //block size count //total size create Linux swap file mkswap /swap/swap activate /swap/swap swap file immediately swapon /swap/swap check to see if it works [root@webserver ~ ] # free -mtotal used free shared buffers cached Mem: 2007 140 1867 0 8 35-/+ buffers/cache: 96 1911 Swap: 972 0 972 Through the above output information, it can be seen that the swap partition has been successfully created. Set to permanent effect although it is now in effect, but wait for the next server restart. The swap virtual disk will be invalid. To ensure permanent validity, you need to add the following command set to the /etc/fstab file: echo "/swap/swap swap swap defaults 0 0" >> /etc/fstab So far, swap partition The creation has been completed.

2. Delete the swap partition

Sometimes you may need to delete the swap partition, how to delete the partition correctly?
First stop the swap partition swapoff /swap/swap delete the swap partition file rm -rf /Swap/swap delete "/etc/swap"specify file

This allows you to manually add and remove swap partitions.
sed -i "/'\\/swa\\/swap swap swap defaults 0 0'//" /etc/fstab

Copyright © Windows knowledge All Rights Reserved