Swap is used if the system's physical memory is used up. The system will run slowly but still run. If swap space is used up, the system will have an error. Generally, the error "application is out of memory" may occur. In severe cases, the service process may be deadlocked. Therefore, we must attach great importance to it.
There are many ways to view swap:
Free
Free-m
We can see the swap used by the current system. So how can we check which processes use swap, so as to make targeted optimization.
Top
Centos (before 6.0 ):
Top only displays the total usage of swap
Many people on the Internet say that top + F + P can display swap. However, when you press F to view the result, swap in man Top explains:
Swap is not actually used. But VIRT-RES. The swap part used in the virtual memory
Centos (after 6.0 ):
Man top
In this way, we can see that the swap of each process is extracted, and it is very convenient to view which processes use swap. You can also see a message. That is, read/proc/#/status
Vmstat
Vmstat-N 1 can also be viewed
You still cannot see which processes are used. However, we can see Si and so
Memory (memory ):
SWPD: virtual memory size used
Free: available memory size
Buff: memory size used as a buffer
Cache: memory size used as the cache
Swap:
Si: size of memory written from swap zone per second
So: memory size written to swap zone per second
Shell introduced a system memory interface feature in Linux kernel 2.6.16. This interface is located in the smaps file under the/proc/$ PID/directory. It is found that the process memory image information is displayed, more detailed than the maps file in the same directory. CAT/proc/1/smaps the content in samps is explained here: bfdca000-bfddf000 is the starting and ending position of the virtual memory segment
RW-P: the permission of the memory segment. RW refers to the read/write permission, and P refers to the private permission, if it is S, it will be the index node number of the file that is mapped to the virtual memory file with the offset of the shared bffea000 in the corresponding ing file. the file name mapped to the virtual memory size is the memory space used by the process, not necessarily actually allocated memory (VSS)
RSS is actually allocated memory (which can be used without page missing interruption)
Unrewritten page shared by shared_clean and other processes
The rewritten page shared by shared_dirty and other processes
Private_clean private page not rewritten
Private_dirty modified private page
The data size of swap in the SWAp partition (if the physical memory is limited, some of the data may exist in the primary storage and some in the SWAp partition)
(Some memory will be shared with other processes, such as MMAP)
The following figure shows the swap:
awk '/^Swap:/ {SWAP+=$2}END{print SWAP" KB"}' /proc/$(pid)/smaps
You can also write shell statistics for the process:
#!/bin/bash# Get current swap usage for all running processes# writted by xlyfunction getswap {SUM=0OVERALL=0for DIR in `find /proc/ -maxdepth 1 -type d | egrep "^/proc/[0-9]"` ; doPID=`echo $DIR | cut -d / -f 3`PROGNAME=`ps -p $PID -o comm --no-headers`for SWAP in `grep Swap $DIR/smaps 2>/dev/null| awk '{ print $2 }'`dolet SUM=$SUM+$SWAPdoneecho "PID=$PID - Swap used: $SUM - ($PROGNAME )"let OVERALL=$OVERALL+$SUMSUM=0doneecho "Overall swap used: $OVERALL"}getswap#getswap|egrep -v "Swap used: 0"
Now that we know the principle, we can use each of them to count iotop in every language.
Official Website: http://guichaz.free.fr/iotop/, detailed description: iotop is a python program with a top like UI used to show of behalf of which process is the I/O going on. it requires Python ≥ 2.5 (or Python ≥ 2.4 With the ctypes module) and a Linux
Kernel ≥ 2.6.20 with the task_delay_acct config_taskstats, task_io_accounting and config_vm_event_counters options on
After pythonpython2.7, The psutil module is available. You can also view swap, learning...
To be continued...