Smem - Linux에서 프로세스별 및 사용자별 메모리 소비를 보고합니다.
메모리 사용량 모니터링 측면에서 메모리 관리는 Linux 시스템에서 수행해야 하는 중요한 작업 중 하나입니다. 다양한 Linux 배포판에서 메모리 사용량을 모니터링하는 데 사용할 수 있는 도구가 많이 있습니다. 그러나 그들은 서로 다른 방식으로 작동합니다. 이 가이드 방법에서는 smem이라는 도구를 설치하고 사용하는 방법을 살펴보겠습니다.
놓치지 마세요: Linux 성능을 모니터링하는 20가지 명령줄 도구
Smem은 Linux 시스템의 메모리 사용량에 대한 다양한 보고서를 사용자에게 제공하는 명령줄 메모리 보고 도구입니다. smem에는 다른 기존 메모리 보고 도구와는 달리 한 가지 독특한 점이 있습니다. 바로 PSS(Proportional Set Size)를 보고하는 것입니다. 가상 메모리 설정.
기존 도구는 주로 물리적 메모리 체계에서 메모리 사용량을 모니터링하기 위한 표준 측정값인 RSS(Resident Set Size)를 읽는 데 중점을 두지만 애플리케이션의 메모리 사용량을 과대평가하는 경향이 있습니다. .
반면 PSS는 가상 메모리 체계에서 애플리케이션과 라이브러리가 사용하는 메모리의 '공정한 공유'를 결정하여 합리적인 척도를 제공합니다.
Linux 시스템의 메모리 소비를 이해하기 위해 이 가이드(메모리 RSS 및 PSS 관련)를 읽을 수 있지만 계속해서 smem의 일부 기능을 살펴보겠습니다.
Smem 도구의 특징
- 시스템 개요 목록
- 프로세스, 매핑 또는 사용자별 목록 및 필터링
- /proc 파일 시스템의 데이터 사용
- 여러 데이터 소스의 구성 가능한 목록 열
- 구성 가능한 출력 단위 및 백분율
- 목록의 헤더와 합계를 쉽게 구성할 수 있습니다.
- 디렉터리 미러 또는 압축된 tar 파일의 데이터 스냅샷 사용
- 내장 차트 생성 메커니즘
- 임베디드 시스템에 사용되는 경량 캡처 도구
Smem 설치 방법 – Linux의 메모리 보고 도구
smem 설치를 진행하기 전에 시스템이 다음 요구 사항을 충족해야 합니다.
- 최신 커널(> 2.6.27 정도)
- 최신 버전의 Python(2.4 정도)
- 차트 생성을 위한 선택적 matplotlib 라이브러리
오늘날 대부분의 Linux 배포판에는 Python 2 또는 3을 지원하는 최신 커널 버전이 함께 제공되므로 유일한 요구 사항은 matplotlib 라이브러리를 설치하는 것입니다. 좋은 차트를 생성하는 데 사용됩니다.
RHEL, CentOS 및 Fedora에서
먼저 EPEL(Enterprise Linux용 추가 패키지) 저장소를 활성화한 후 다음과 같이 설치합니다.
yum install smem python-matplotlib python-tk
데비안과 우분투에서
sudo apt-get install smem
리눅스 민트에서
sudo apt-get install smem python-matplotlib python-tk
아치 리눅스에서
이 AUR 저장소를 사용하세요.
Smem 사용 방법 - Linux의 메모리 보고 도구
모든 시스템 사용자의 전체 시스템에 대한 메모리 사용량 보고서를 보려면 다음 명령을 실행하십시오.
$ sudo smem
PID User Command Swap USS PSS RSS
6367 tecmint cat 0 100 145 1784
6368 tecmint cat 0 100 147 1676
2864 tecmint /usr/bin/ck-launch-session 0 144 165 1780
7656 tecmint gnome-pty-helper 0 156 178 1832
5758 tecmint gnome-pty-helper 0 156 179 1916
1441 root /sbin/getty -8 38400 tty2 0 152 184 2052
1434 root /sbin/getty -8 38400 tty5 0 156 187 2060
1444 root /sbin/getty -8 38400 tty3 0 156 187 2060
1432 root /sbin/getty -8 38400 tty4 0 156 188 2124
1452 root /sbin/getty -8 38400 tty6 0 164 196 2064
2619 root /sbin/getty -8 38400 tty1 0 164 196 2136
3544 tecmint sh -c /usr/lib/linuxmint/mi 0 212 224 1540
1504 root acpid -c /etc/acpi/events - 0 220 236 1604
3311 tecmint syndaemon -i 0.5 -K -R 0 252 292 2556
3143 rtkit /usr/lib/rtkit/rtkit-daemon 0 300 326 2548
1588 root cron 0 292 333 2344
1589 avahi avahi-daemon: chroot helpe 0 124 334 1632
1523 root /usr/sbin/irqbalance 0 316 343 2096
585 root upstart-socket-bridge --dae 0 328 351 1820
3033 tecmint /usr/bin/dbus-launch --exit 0 328 360 2160
1346 root upstart-file-bridge --daemo 0 348 371 1776
2607 root /usr/bin/xdm 0 188 378 2368
1635 kernoops /usr/sbin/kerneloops 0 352 386 2684
344 root upstart-udev-bridge --daemo 0 400 427 2132
2960 tecmint /usr/bin/ssh-agent /usr/bin 0 480 485 992
3468 tecmint /bin/dbus-daemon --config-f 0 344 515 3284
1559 avahi avahi-daemon: running [tecm 0 284 517 3108
7289 postfix pickup -l -t unix -u -c 0 288 534 2808
2135 root /usr/lib/postfix/master 0 352 576 2872
2436 postfix qmgr -l -t unix -u 0 360 606 2884
1521 root /lib/systemd/systemd-logind 0 600 650 3276
2222 nobody /usr/sbin/dnsmasq --no-reso 0 604 669 3288
....
일반 사용자가 smem을 실행하면 사용자가 시작한 프로세스별로 메모리 사용량이 표시되며 PSS가 증가하는 순서대로 프로세스가 정렬됩니다.
aaronkilik
사용자가 시작한 프로세스의 메모리 사용량에 대한 내 시스템의 아래 출력을 살펴보세요.
$ smem
PID User Command Swap USS PSS RSS
6367 tecmint cat 0 100 145 1784
6368 tecmint cat 0 100 147 1676
2864 tecmint /usr/bin/ck-launch-session 0 144 166 1780
3544 tecmint sh -c /usr/lib/linuxmint/mi 0 212 224 1540
3311 tecmint syndaemon -i 0.5 -K -R 0 252 292 2556
3033 tecmint /usr/bin/dbus-launch --exit 0 328 360 2160
3468 tecmint /bin/dbus-daemon --config-f 0 344 515 3284
3122 tecmint /usr/lib/gvfs/gvfsd 0 656 801 5552
3471 tecmint /usr/lib/at-spi2-core/at-sp 0 708 864 5992
3396 tecmint /usr/lib/gvfs/gvfs-mtp-volu 0 804 914 6204
3208 tecmint /usr/lib/x86_64-linux-gnu/i 0 892 1012 6188
3380 tecmint /usr/lib/gvfs/gvfs-afc-volu 0 820 1024 6396
3034 tecmint //bin/dbus-daemon --fork -- 0 920 1081 3040
3365 tecmint /usr/lib/gvfs/gvfs-gphoto2- 0 972 1099 6052
3228 tecmint /usr/lib/gvfs/gvfsd-trash - 0 980 1153 6648
3107 tecmint /usr/lib/dconf/dconf-servic 0 1212 1283 5376
6399 tecmint /opt/google/chrome/chrome - 0 144 1409 10732
3478 tecmint /usr/lib/x86_64-linux-gnu/g 0 1724 1820 6320
7365 tecmint /usr/lib/gvfs/gvfsd-http -- 0 1352 1884 8704
6937 tecmint /opt/libreoffice5.0/program 0 1140 2328 5040
3194 tecmint /usr/lib/x86_64-linux-gnu/p 0 1956 2405 14228
6373 tecmint /opt/google/chrome/nacl_hel 0 2324 2541 8908
3313 tecmint /usr/lib/gvfs/gvfs-udisks2- 0 2460 2754 8736
3464 tecmint /usr/lib/at-spi2-core/at-sp 0 2684 2823 7920
5771 tecmint ssh -p 4521 [email 0 2544 2864 6540
5759 tecmint /bin/bash 0 2416 2923 5640
3541 tecmint /usr/bin/python /usr/bin/mi 0 2584 3008 7248
7657 tecmint bash 0 2516 3055 6028
3127 tecmint /usr/lib/gvfs/gvfsd-fuse /r 0 3024 3126 8032
3205 tecmint mate-screensaver 0 2520 3331 18072
3171 tecmint /usr/lib/mate-panel/notific 0 2860 3495 17140
3030 tecmint x-session-manager 0 4400 4879 17500
3197 tecmint mate-volume-control-applet 0 3860 5226 23736
...
smem을 사용하는 동안 호출할 수 있는 옵션이 많이 있습니다. 예를 들어 시스템 전체 메모리 소비를 보려면 다음 명령을 실행하십시오.
$ sudo smem -w
Area Used Cache Noncache
firmware/hardware 0 0 0
kernel image 0 0 0
kernel dynamic memory 1425320 1291412 133908
userspace memory 2215368 451608 1763760
free memory 4424936 4424936 0
사용자별 메모리 사용량을 보려면 아래 명령을 실행하세요.
$ sudo smem -u
User Count Swap USS PSS RSS
rtkit 1 0 300 326 2548
kernoops 1 0 352 385 2684
avahi 2 0 408 851 4740
postfix 2 0 648 1140 5692
messagebus 1 0 1012 1173 3320
syslog 1 0 1396 1419 3232
www-data 2 0 5100 6572 13580
mpd 1 0 7416 8302 12896
nobody 2 0 4024 11305 24728
root 39 0 323876 353418 496520
tecmint 64 0 1652888 1815699 2763112
다음과 같이 매핑을 통해 메모리 사용량을 보고할 수도 있습니다.
$ sudo smem -m
Map PIDs AVGPSS PSS
/dev/fb0 1 0 0
/home/tecmint/.cache/fontconfig/7ef2298f 18 0 0
/home/tecmint/.cache/fontconfig/c57959a1 18 0 0
/home/tecmint/.local/share/mime/mime.cac 15 0 0
/opt/google/chrome/chrome_material_100_p 9 0 0
/opt/google/chrome/chrome_material_200_p 9 0 0
/usr/lib/x86_64-linux-gnu/gconv/gconv-mo 41 0 0
/usr/share/icons/Mint-X-Teal/icon-theme. 15 0 0
/var/cache/fontconfig/0c9eb80ebd1c36541e 20 0 0
/var/cache/fontconfig/0d8c3b2ac0904cb8a5 20 0 0
/var/cache/fontconfig/1ac9eb803944fde146 20 0 0
/var/cache/fontconfig/3830d5c3ddfd5cd38a 20 0 0
/var/cache/fontconfig/385c0604a188198f04 20 0 0
/var/cache/fontconfig/4794a0821666d79190 20 0 0
/var/cache/fontconfig/56cf4f4769d0f4abc8 20 0 0
/var/cache/fontconfig/767a8244fc0220cfb5 20 0 0
/var/cache/fontconfig/8801497958630a81b7 20 0 0
/var/cache/fontconfig/99e8ed0e538f840c56 20 0 0
/var/cache/fontconfig/b9d506c9ac06c20b43 20 0 0
/var/cache/fontconfig/c05880de57d1f5e948 20 0 0
/var/cache/fontconfig/dc05db6664285cc2f1 20 0 0
/var/cache/fontconfig/e13b20fdb08344e0e6 20 0 0
/var/cache/fontconfig/e7071f4a29fa870f43 20 0 0
....
smem 출력을 필터링하는 옵션도 있으며 여기서는 두 가지 예를 살펴보겠습니다.
사용자 이름으로 출력을 필터링하려면 아래와 같이 -u
또는 --userfilter="regex"
옵션을 호출하십시오.
$ sudo smem -u
User Count Swap USS PSS RSS
rtkit 1 0 300 326 2548
kernoops 1 0 352 385 2684
avahi 2 0 408 851 4740
postfix 2 0 648 1140 5692
messagebus 1 0 1012 1173 3320
syslog 1 0 1400 1423 3236
www-data 2 0 5100 6572 13580
mpd 1 0 7416 8302 12896
nobody 2 0 4024 11305 24728
root 39 0 323804 353374 496552
tecmint 64 0 1708900 1871766 2819212
프로세스 이름별로 출력을 필터링하려면 다음과 같이 -P
또는 --processfilter="regex"
옵션을 호출합니다.
$ sudo smem --processfilter="firefox"
PID User Command Swap USS PSS RSS
9212 root sudo smem --processfilter=f 0 1172 1434 4856
9213 root /usr/bin/python /usr/bin/sm 0 7368 7793 11984
4424 tecmint /usr/lib/firefox/firefox 0 931732 937590 961504
출력 형식화는 매우 중요할 수 있으며 메모리 보고서 형식화에 도움이 되는 옵션이 있으며 아래에서 몇 가지 예를 살펴보겠습니다.
보고서에 원하는 열을 표시하려면 다음과 같이 -c
또는 --columns
옵션을 사용하세요.
$ sudo smem -c "name user pss rss"
Name User PSS RSS
cat tecmint 145 1784
cat tecmint 147 1676
ck-launch-sessi tecmint 165 1780
gnome-pty-helpe tecmint 178 1832
gnome-pty-helpe tecmint 179 1916
getty root 184 2052
getty root 187 2060
getty root 187 2060
getty root 188 2124
getty root 196 2064
getty root 196 2136
sh tecmint 224 1540
acpid root 236 1604
syndaemon tecmint 296 2560
rtkit-daemon rtkit 326 2548
cron root 333 2344
avahi-daemon avahi 334 1632
irqbalance root 343 2096
upstart-socket- root 351 1820
dbus-launch tecmint 360 2160
upstart-file-br root 371 1776
xdm root 378 2368
kerneloops kernoops 386 2684
upstart-udev-br root 427 2132
ssh-agent tecmint 485 992
...
아래 명령과 같이 -p
옵션을 호출하여 메모리 사용량을 백분율로 보고할 수 있습니다.
$ sudo smem -p
PID User Command Swap USS PSS RSS
6367 tecmint cat 0.00% 0.00% 0.00% 0.02%
6368 tecmint cat 0.00% 0.00% 0.00% 0.02%
9307 tecmint sh -c { sudo /usr/lib/linux 0.00% 0.00% 0.00% 0.02%
2864 tecmint /usr/bin/ck-launch-session 0.00% 0.00% 0.00% 0.02%
3544 tecmint sh -c /usr/lib/linuxmint/mi 0.00% 0.00% 0.00% 0.02%
5758 tecmint gnome-pty-helper 0.00% 0.00% 0.00% 0.02%
7656 tecmint gnome-pty-helper 0.00% 0.00% 0.00% 0.02%
1441 root /sbin/getty -8 38400 tty2 0.00% 0.00% 0.00% 0.03%
1434 root /sbin/getty -8 38400 tty5 0.00% 0.00% 0.00% 0.03%
1444 root /sbin/getty -8 38400 tty3 0.00% 0.00% 0.00% 0.03%
1432 root /sbin/getty -8 38400 tty4 0.00% 0.00% 0.00% 0.03%
1452 root /sbin/getty -8 38400 tty6 0.00% 0.00% 0.00% 0.03%
2619 root /sbin/getty -8 38400 tty1 0.00% 0.00% 0.00% 0.03%
1504 root acpid -c /etc/acpi/events - 0.00% 0.00% 0.00% 0.02%
3311 tecmint syndaemon -i 0.5 -K -R 0.00% 0.00% 0.00% 0.03%
3143 rtkit /usr/lib/rtkit/rtkit-daemon 0.00% 0.00% 0.00% 0.03%
1588 root cron 0.00% 0.00% 0.00% 0.03%
1589 avahi avahi-daemon: chroot helpe 0.00% 0.00% 0.00% 0.02%
1523 root /usr/sbin/irqbalance 0.00% 0.00% 0.00% 0.03%
585 root upstart-socket-bridge --dae 0.00% 0.00% 0.00% 0.02%
3033 tecmint /usr/bin/dbus-launch --exit 0.00% 0.00% 0.00% 0.03%
....
아래 명령은 출력의 각 열 끝에 합계를 표시합니다.
$ sudo smem -t
PID User Command Swap USS PSS RSS
6367 tecmint cat 0 100 139 1784
6368 tecmint cat 0 100 141 1676
9307 tecmint sh -c { sudo /usr/lib/linux 0 96 158 1508
2864 tecmint /usr/bin/ck-launch-session 0 144 163 1780
3544 tecmint sh -c /usr/lib/linuxmint/mi 0 108 170 1540
5758 tecmint gnome-pty-helper 0 156 176 1916
7656 tecmint gnome-pty-helper 0 156 176 1832
1441 root /sbin/getty -8 38400 tty2 0 152 181 2052
1434 root /sbin/getty -8 38400 tty5 0 156 184 2060
1444 root /sbin/getty -8 38400 tty3 0 156 184 2060
1432 root /sbin/getty -8 38400 tty4 0 156 185 2124
1452 root /sbin/getty -8 38400 tty6 0 164 193 2064
2619 root /sbin/getty -8 38400 tty1 0 164 193 2136
1504 root acpid -c /etc/acpi/events - 0 220 232 1604
3311 tecmint syndaemon -i 0.5 -K -R 0 260 298 2564
3143 rtkit /usr/lib/rtkit/rtkit-daemon 0 300 324 2548
1588 root cron 0 292 326 2344
1589 avahi avahi-daemon: chroot helpe 0 124 332 1632
1523 root /usr/sbin/irqbalance 0 316 340 2096
585 root upstart-socket-bridge --dae 0 328 349 1820
3033 tecmint /usr/bin/dbus-launch --exit 0 328 359 2160
1346 root upstart-file-bridge --daemo 0 348 370 1776
2607 root /usr/bin/xdm 0 188 375 2368
1635 kernoops /usr/sbin/kerneloops 0 352 384 2684
344 root upstart-udev-bridge --daemo 0 400 426 2132
.....
-------------------------------------------------------------------------------
134 11 0 2171428 2376266 3587972
또한 사용할 수 있는 그래픽 보고서에 대한 옵션도 있으며 이 하위 섹션에서 이에 대해 자세히 살펴보겠습니다.
프로세스의 막대 그래프와 해당 PSS 및 RSS 값을 생성할 수 있습니다. 아래 예에서는 루트 사용자가 소유한 프로세스의 막대 그래프를 생성합니다.
수직면은 프로세스의 PSS 및 RSS 측정값을 표시하고 수평면은 각 루트 사용자 프로세스를 나타냅니다.
$ sudo smem --userfilter="root" --bar pid -c"pss rss"
PSS 또는 RSS 값을 기준으로 프로세스와 메모리 소비를 보여주는 원형 차트를 생성할 수도 있습니다. 아래 명령은 값을 측정하는 루트 사용자가 소유한 프로세스에 대한 원형 차트를 출력합니다.
--pie
이름은 이름별 레이블을 의미하고 -s
옵션은 PSS 값별로 정렬하는 데 도움이 됩니다.
$ sudo smem --userfilter="root" --pie name -s pss
차트 라벨링에 사용되는 PSS 및 RSS 외에도 알려진 필드가 많이 있습니다.
도움을 받으려면 smem -h
를 입력하거나 수동 입력 페이지를 방문하세요.
여기서는 smem에 대해 설명하겠습니다. 더 잘 이해하려면 매뉴얼 페이지에서 찾을 수 있는 다른 많은 옵션과 함께 사용하세요. 평소와 마찬가지로 아래 의견 섹션을 사용하여 생각이나 우려 사항을 표현할 수 있습니다.
참조 링크: https://www.selenic.com/smem/