内存

/proc/meminfo

查看RAM使用情况最简单的方法是通过/proc/meminfo。这个动态更新的虚拟文件实际上是许多其他内存相关工具(如:free / ps / top)等的组合显示。/proc/meminfo列出了所有你想了解的内存的使用情况。进程的内存使用信息也可以通过/proc/<pid>/statm 和 /proc/<pid>/status 来查看。

  1. [root@izuf676tpj6wh2py3ogptyz ~]# cat /proc/meminfo
  2. MemTotal: 3881688 kB
  3. MemFree: 252104 kB
  4. MemAvailable: 177452 kB
  5. Buffers: 9260 kB
  6. Cached: 65732 kB
  7. SwapCached: 0 kB
  8. Active: 3471056 kB
  9. Inactive: 52668 kB
  10. Active(anon): 3449244 kB
  11. Inactive(anon): 116 kB
  12. Active(file): 21812 kB
  13. Inactive(file): 52552 kB
  14. Unevictable: 0 kB
  15. Mlocked: 0 kB
  16. SwapTotal: 0 kB
  17. SwapFree: 0 kB
  18. Dirty: 64 kB
  19. Writeback: 0 kB
  20. AnonPages: 3448844 kB
  21. Mapped: 11476 kB
  22. Shmem: 556 kB
  23. Slab: 37148 kB
  24. SReclaimable: 16912 kB
  25. SUnreclaim: 20236 kB
  26. KernelStack: 3584 kB
  27. PageTables: 23972 kB
  28. NFS_Unstable: 0 kB
  29. Bounce: 0 kB
  30. WritebackTmp: 0 kB
  31. CommitLimit: 1940844 kB
  32. Committed_AS: 4724584 kB
  33. VmallocTotal: 34359738367 kB
  34. VmallocUsed: 14208 kB
  35. VmallocChunk: 34359715580 kB
  36. HardwareCorrupted: 0 kB
  37. AnonHugePages: 436224 kB
  38. HugePages_Total: 0
  39. HugePages_Free: 0
  40. HugePages_Rsvd: 0
  41. HugePages_Surp: 0
  42. Hugepagesize: 2048 kB
  43. DirectMap4k: 34688 kB
  44. DirectMap2M: 3110912 kB
  45. DirectMap1G: 3145728 kB

free
free命令是一个快速查看内存使用情况的方法,它是对 /proc/meminfo 收集到的信息的一个概述。

  1. [root@izuf676tpj6wh2py3ogptyz ~]# free
  2. total used free shared buff/cache available
  3. Mem: 3881688 3512028 229204 556 140456 168720
  4. Swap: 0 0 0

top
top命令提供了实时的运行中的程序的资源使用统计。你可以根据内存的使用和大小来进行排序。

  1. [root@izuf676tpj6wh2py3ogptyz ~]# top
  2. top - 17:52:35 up 12 days, 2:10, 1 user, load average: 0.00, 3.97, 9.16
  3. Tasks: 171 total, 1 running, 170 sleeping, 0 stopped, 0 zombie
  4. %Cpu(s): 0.7 us, 0.3 sy, 0.0 ni, 99.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
  5. KiB Mem : 3881688 total, 272648 free, 3465500 used, 143540 buff/cache
  6. KiB Swap: 0 total, 0 free, 0 used. 213728 avail Mem
  7. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
  8. 20217 root 20 0 2515220 57784 2100 S 1.3 1.5 0:15.40 java
  9. 1071 root 20 0 134704 8344 1344 S 0.7 0.2 96:43.18 AliYunDun
  10. 1050 root 20 0 122084 744 96 S 0.3 0.0 8:41.57 wrapper
  11. 11660 root 20 0 0 0 0 S 0.3 0.0 0:08.98 kworker/1:2
  12. 20367 root 20 0 157724 2272 1540 R 0.3 0.1 0:00.01 top
  13. 1 root 20 0 43268 2320 1140 S 0.0 0.1 0:22.91 systemd
  14. 2 root 20 0 0 0 0 S 0.0 0.0 0:00.08 kthreadd
  15. 3 root 20 0 0 0 0 S 0.0 0.0 0:01.97 ksoftirqd/0
  16. 5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
  17. 7 root rt 0 0 0 0 S 0.0 0.0 4:54.08 migration/0
  18. 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
  19. 9 root 20 0 0 0 0 S 0.0 0.0 3:19.03 rcu_sched
  20. 10 root rt 0 0 0 0 S 0.0 0.0 0:03.91 watchdog/0
  21. 11 root rt 0 0 0 0 S 0.0 0.0 0:03.12 watchdog/1
  22. 12 root rt 0 0 0 0 S 0.0 0.0 3:31.60 migration/1
  23. 13 root 20 0 0 0 0 S 0.0 0.0 0:05.96 ksoftirqd/1
  24. 15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
  25. 17 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kdevtmpfs
  26. 18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
  27. 19 root 20 0 0 0 0 S 0.0 0.0 0:00.33 khungtaskd
  28. 20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
  29. 21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
  30. 22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
  31. 23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
  32. 24 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 md
  33. 31 root 20 0 0 0 0 S 0.0 0.0 187:40.94 kswapd0
  34. 32 root 25 5 0 0 0 S 0.0 0.0 0:00.00 ksmd
  35. 33 root 39 19 0 0 0 S 0.0 0.0 0:10.67 khugepaged
  36. 34 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 crypto
  37. 42 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kthrotld
  38. 44 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kmpath_rdacd
  39. 45 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kpsmoused
  40. 46 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 ipv6_addrconf
  41. 65 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 deferwq
  42. 157 root 20 0 0 0 0 S 0.0 0.0 0:00.22 kauditd