(1).查看Memory(內存)運行狀態相關工具
1)free命令查看內存使用情況
[root@youxi1 ~]# free -m //-m選項,以MB為單位顯示 total used free shared buff/cache available Mem: 3934 163 3478 11 292 3513 Swap: 2047 0 2047
在CentOS7中新增了一列available,該列是真正可用內存,其包括了buff/cache中的一些可以被釋放的內存。當物理內存不夠用時,內核會把非活躍的數據清空。
2)top
輸入top命令,按下大寫的M,可以使輸出按照內存的使用率進行排序。top命令使用在內存方面時,可以查看到內存的各種信息,但更多的是用於找出使用內存最多的程序。
詳細查看:Linux命令之uptime
3)ps
按照實際使用內存,從大到小顯示所有進程列表。可以用於找出使用內存最多的程序
[root@youxi1 ~]# ps aux --sort -rss | more USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 801 0.0 0.7 358120 29116 ? Ssl 14:52 0:01 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid root 1140 0.0 0.4 573852 19192 ? Ssl 14:52 0:01 /usr/bin/python -Es /usr/sbin/tuned -l -P polkitd 766 0.0 0.3 539212 12892 ? Ssl 14:52 0:00 /usr/lib/polkit-1/polkitd --no-debug root 814 0.0 0.2 476472 11220 ? Ssl 14:52 0:00 /usr/sbin/NetworkManager --no-daemon root 764 0.1 0.2 298928 8284 ? Ssl 14:52 0:13 /usr/bin/vmtoolsd root 763 0.0 0.1 99656 6116 ? Ss 14:52 0:00 /usr/bin/VGAuthService -s root 1460 0.0 0.1 161396 6016 ? Rs 15:26 0:01 sshd: root@pts/0 root 1141 0.0 0.1 218504 4684 ? Ssl 14:52 0:00 /usr/sbin/rsyslogd -n root 1143 0.0 0.1 112796 4288 ? Ss 14:52 0:00 /usr/sbin/sshd -D postfix 1329 0.0 0.1 89792 4076 ? S 14:52 0:00 qmgr -l -t unix -u --More--
注意:rss前面有減號是降序,沒有減號是升序。
(2).查看內存信息
內存信息存放在/proc/meminfo文件中
[root@youxi1 ~]# cat /proc/meminfo MemTotal: 4028428 kB MemFree: 3561616 kB MemAvailable: 3597164 kB Buffers: 2108 kB Cached: 237892 kB SwapCached: 0 kB Active: 195264 kB //活躍內存,指進程一直讀寫的內存空間 Inactive: 111844 kB //非活躍內存 Active(anon): 67760 kB Inactive(anon): 11152 kB Active(file): 127504 kB Inactive(file): 100692 kB Unevictable: 0 kB Mlocked: 0 kB SwapTotal: 2097148 kB SwapFree: 2097148 kB Dirty: 0 kB Writeback: 0 kB AnonPages: 67108 kB Mapped: 25028 kB Shmem: 11804 kB Slab: 59536 kB SReclaimable: 24896 kB SUnreclaim: 34640 kB KernelStack: 5072 kB PageTables: 4068 kB NFS_Unstable: 0 kB Bounce: 0 kB WritebackTmp: 0 kB CommitLimit: 4111360 kB Committed_AS: 270624 kB VmallocTotal: 34359738367 kB VmallocUsed: 193148 kB VmallocChunk: 34359310332 kB HardwareCorrupted: 0 kB AnonHugePages: 12288 kB CmaTotal: 0 kB CmaFree: 0 kB HugePages_Total: 0 HugePages_Free: 0 HugePages_Rsvd: 0 HugePages_Surp: 0 Hugepagesize: 2048 kB DirectMap4k: 100160 kB DirectMap2M: 4093952 kB
(3).內存調優
我沒看到專門的內存調優,一般都是程序內部調整。正常運行狀態下,長時間占用swap內存就表示需要添加內存條了。(一己之見)