I. Introduction:
To improve read and write efficiency and speed, the Linux kernel caches files in memory, which is the cache memory. The Cache memory will not be released automatically even after your program has finished running. This will cause you to read and write files frequently in your Linux system, and you will find that there is less available physical memory. 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 in the swap space until those programs are run and the saved data is restored to memory from the swap partition. In this way, the system always does swap swap when physical memory is not enough.
Two. Check the swap partition size:
[[email protected] ~]# free total used free shared buffers cachedmem: 1906256 158332 1747924 168 6164 44048-/+ buffers/cache: 108120 1798136Swap: 2097148 0 2097148[[email protected] ~]# free -m total used &Nbsp; free shared buffers cachedMem: 1861 154 1706 0 6 43-/+ buffers/cache: 105 1755Swap: 2047 0 2047[[email protected] ~]# swapon -sFilename Type size used priority/dev/dm-1 partition 2097148 0 -1
Three. Release swap space:
Close the swap partition first, and then open the swap partition again.
1. View Swap partition information [[email protected] ~]# free -m total used free shared buffers cachedMem: 1861 154 1706 0 6 43-/+ buffers/cache: 105 1756swap: 2047 0 2047[[ Email protected] ~]# swapon -sfilename type size used Priority/dev/dm-1 partition 2097148 0 -12. Close swap partition [[email protected] ~]# swapoff /dev/dm-1 3. Check swap partition [[email protected] ~]# free -m total used free shared buffers cachedMem: 1861 153 1707 0 6 43-/+ buffers/cache: 104 1757Swap: 0 0 04. Open Swap partition [[email protected] ~]# swapon /dev/dm-1 [[email protected] ~]# free -m total used free shared buffers cachedmem: 1861 155 1706 0 6 43-/+ buffers/cache: 105 1755Swap: 2047 0 2047
Four. Modify the parameter swappiness
Under what circumstances or conditions will the system use the swap partition space? Linux is actually controlled by a parameter swappiness. This parameter value can be 0-100, which controls how much the system swap is used. High values prioritize system performance and actively convert them out of physical memory when the process is inactive. Low values prioritize interactivity and try to avoid converting the process to physical memory, and reduce the latency of the reaction. The default value is 60.
Temporary modification 1:[[email protected] ~]# more/proc/sys/vm/swappiness60[[email protected] ~]# echo >/proc/sys/vm/swappiness[[ Email protected] ~]# more/proc/sys/vm/swappiness10 Temporary modification 2:sysctl vm.swappiness=10 Permanent modification: Echo ' vm.swappiness=10 ' >> /etc/sysctl.conf after restarting the system.
Five. Adjust the swap partition size
Method 1: If the swap is a logical volume
[[EMAIL PROTECTED] ~]# LL /DEV/MAPPER/TOTAL 0CRW-RW---- 1 root root 10, 58 Oct 13 09:49 controllrwxrwxrwx 1 root root     7 OCT 13 09:50 VG_NODE1-LV_ROOT ->&NBSP, .... /dm-0lrwxrwxrwx 1 root root 7 oct 13 10:09  VG_NODE1-LV_SWAP ->&NBSP, .... /dm-1[[email protected] ~]# swapon -sfilename type size Used Priority/dev/dm-1 partition 2097148 0 -11. Close swap swap partition swapoff /dev/dm-1 or swapoff &nbsP;/dev/mapper/vg_node1-lv_swap 2. If the VG has free space, use the Lvextend expansion mode lvextend -l 3g /dev/mapper/vg_node1-lv_ Swap3. Formatting: mkswap /dev/mapper/vg_node1-lv_swap 4. Start swap partition SWAPON /DEV/MAPPER/VG_NODE1-LV_SWAP5. Add to boot Cat /etc/fstab the default system is automatically mounted/dev/mapper/vg_ node1-lv_root / ext4 defaults 1 1
Method 2: Create a swap partition for the file
1. Create file/root/swap# dd If=/dev/zero of=/root/swap bs=1024m count=8 (from/partition 8x1024m size space, hanging on/root/swap) 2. Formatting: # Mkswap/ Root/swap (formatted in swap format) 3. Enable: # Swapon/root/swap (Activate/root/swap, add to swap partition) If an error occurs, Swapon-f/root/swap 4. Add Boot # VIM/ETC /fstab (starting from the newly added swap partition)/root/swap swap swap defaults 0 05. Deleting the new file only needs to be done #swapoff/root/swap
Method 3: New Hard Drive mode
1. Create the partition fdisk--n--t-(adjustment type 82swap) 2. Format into swap format mkswap/dev/sda33. Enabled: Swapon/dev/sda33. Mount from Boot Vim/etc/fstab/dev/sda3 Swap swap defaults 0 0
This article from "High-rise, look at the end of the Road" blog, please be sure to keep this source http://nxyboy.blog.51cto.com/10511646/1972037
Swap partition of Linux system