리눅스에서 메모리 사용량을 확인하는 방법이다.
# Ubuntu or CentOS 6이하 버전 free
$ free -m total used free shared buffers cached Mem: 245998 24545 221453 83 59 541 -/+ buffers/cache: 23944 222053 Swap: 0 0 0 |
# CentOS 7.X free
CentOS7에서 free 명령에 -/+ buffers/cache이 출력되지 않는다.
Refer: https://www.centos.org/forums/viewtopic.php?t=54403
[root@private6 ~]# free -m total used free shared buff/cache available Mem: 31934 26963 1604 1308 3366 2873 Swap: 32767 5625 27142 |
* total: 31934MB는 물리적인 메모리 총 사이즈
* used: 26963M은 실제 사용한 메모리 (단, buffer, cache 메모리 미포함)
* free: 1604M은 남은 메모리 사이즈 (단, buffer, cache 메모리 포함되어 있음)
리눅스에서는 실행중인 어플리케이션에서 요구하는 메모리를 제외한 대부분의 메모리를 디스크 캐쉬로 사용한다.
free(1604M)이 작지만 buff/cached(3366M) 메모리는 어플리케이션에서 메모리가 필요한 경우 반환이 가능하다.
따라서 리눅스에서 가용이 가능한 메모리는 free + buffers + cached이다.
# top과 free에서 available 메모리 (man free: available)
Estimation of how much memory is available for starting new applications, without swapping.
Unlike the data provided by the cache or free fields, this field takes into account page cache and also that not all reclaimable memory slabs will be reclaimed due to items being in use (MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on kernels 2.6.27+, otherwise the same as free)
# 참고 명령어
$ sar -r 1
$ free -k; cat /proc/meminfo | grep Mem; top -n1 | grep "KiB Mem"; vmstat -s | grep memory;
$ dstat --time --cpu --mem --net --disk
# 참고 스크립트
#!/bin/bash while : do TOTAL=`free | grep ^Mem | awk '{print $2}'` USED=`free | grep ^Mem | awk '{print $3}'` FREE=`free | grep ^Mem | awk '{print $4}'` BUFFER=`free | grep ^Mem | awk '{print $6}'` USAGE=`echo "100-($FREE/$TOTAL*100)" | bc -l` USED=`echo "$USED/$TOTAL*100" | bc -l` ACTUAL=`echo "($TOTAL-$FREE-$BUFFER)/$TOTAL*100" | bc -l` echo USAGE=${USAGE:0:5}% USED=${USED:0:5}% ACTUAL=${ACTUAL:0:5}% sleep 1; done |
# 메모리 사용량 (free, top, sar, dmstat, vmstat, /proc/meminfo)
※ 참고 사이트※
http://tigerbum.tistory.com/44
https://www.howtoforge.com/linux-free-command/
http://klero.tistory.com/entry/linuxfreememory
https://www.linuxatemyram.com/
'리눅스 > 명령어' 카테고리의 다른 글
nohup 명령어 사용 방법 정리 (0) | 2018.11.20 |
---|---|
프로세스별 메모리 사용량 (ps, top) (0) | 2018.05.30 |
curl 사용법 (0) | 2018.05.03 |
fping, nmap: IP 스캔 (0) | 2017.12.23 |
man 페이지 정보를 txt, html, pdf 파일로 저장하는 방법 (0) | 2017.12.21 |