Linux系统调优——Memory内存(二)

(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内存就表示需要添加内存条了。(一己之见)

原文地址:https://www.cnblogs.com/diantong/p/11271312.html