What should I do if the swap area is full?
1. The method without increasing the exchange area
-
free -m or free -h to view the occupancy
-
Use the following command to view the top ten processes occupying swap
for i in $( cd /proc;ls |grep "^[0-9]"|awk ' $0 >100') ;do awk '/Swap:/{a=a+$2}END{print '"$i"',a/1024"M"}' /proc/$i/smaps 2>/dev/null ; done | sort -k2nr | head -10
- kill -9 pid kills the process that takes up too much
2. How to increase the exchange area
dd can read data from standard input or a file, convert the data according to the specified format, and then output to a file, device, or standard output.
The parameters used are as follows:
if=filename: input filename, the default is standard input. That is, specify the source file.
of=filename: output filename, the default is standard output. That is, specify the destination file.
bs=bytes: At the same time, set the block size of the read/output to bytes bytes.
count=blocks: Only blocks blocks are copied, and the block size is equal to the number of bytes specified by ibs.
Parameter Description:
Step 1: Create a file with a size of 1024M
dd if=/dev/zero of=/swap01 bs=1024 count=1048572
Step 2: Turn this file into a swap file:
mkswap /swap01
Step 3: Enable this swap file:
swapon /swap01
Step 4: Edit the /etc/fstab file so that the swap file is automatically loaded every time it is turned on:
vim /etc/fstab
在文件末尾添加下列参数
/swap01 swap swap default 0 0