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.
Dd if =/dev/zero of =/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 switch file now
swapon /swap/swap
Check whether 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
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/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
swapoff /swap/swap
Delete a swap partition file
rm -rf /swap/swap
Delete the specified File "/etc/swap"
sed -i "/'\/swa\/swap swap swap defaults 0 0'//" /etc/fstab
In this way, you can manually add and delete swap partitions.