{"id":197887,"date":"2020-08-15T09:21:10","date_gmt":"2020-08-15T01:21:10","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=197887"},"modified":"2020-08-07T09:21:58","modified_gmt":"2020-08-07T01:21:58","slug":"linux-look-mem","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-look-mem.html","title":{"rendered":"\u603b\u7ed3Linux\u4e0b\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u591a\u79cd\u65b9\u6cd5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u505a Linux \u7cfb\u7edf\u4f18\u5316\u7684\u65f6\u5019\uff0c\u7269\u7406\u5185\u5b58\u662f\u5176\u4e2d\u6700\u91cd\u8981\u7684\u4e00\u65b9\u9762\u3002\u81ea\u7136\u7684\uff0cLinux \u4e5f\u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u7684\u65b9\u6cd5\u6765\u76d1\u63a7\u5b9d\u8d35\u7684\u5185\u5b58\u8d44\u6e90\u7684\u4f7f\u7528\u60c5\u51b5\u3002\u4e0b\u9762\u7684\u6e05\u5355\u8be6\u7ec6\u7684\u5217\u51fa\u4e86 Linux \u7cfb\u7edf\u4e0b\u901a\u8fc7\u89c6\u56fe\u5de5\u5177\u6216\u547d\u4ee4\u884c\u6765\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u5404\u79cd\u65b9\u6cd5\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1.\/proc\/meminfo<\/strong><\/strong><\/span><\/div>\n

\u67e5\u770b RAM \u4f7f\u7528\u60c5\u51b5\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 \/proc\/meminfo<\/span>\u3002\u8fd9\u4e2a\u52a8\u6001\u66f4\u65b0\u7684\u865a\u62df\u6587\u4ef6\u5b9e\u9645\u4e0a\u662f\u8bb8\u591a\u5176\u4ed6\u5185\u5b58\u76f8\u5173\u5de5\u5177 (\u5982\uff1afree \/ ps \/ top) \u7b49\u7684\u7ec4\u5408\u663e\u793a\u3002\/proc\/meminfo<\/span> \u5217\u51fa\u4e86\u6240\u6709\u4f60\u60f3\u4e86\u89e3\u7684\u5185\u5b58\u7684\u4f7f\u7528\u60c5\u51b5\u3002\u8fdb\u7a0b\u7684\u5185\u5b58\u4f7f\u7528\u4fe1\u606f\u4e5f\u53ef\u4ee5\u901a\u8fc7 \/proc\/\/statm<\/span> \u548c \/proc\/\/statu<\/span>s \u6765\u67e5\u770b\u3002<\/p>\n

$\u00a0cat\u00a0\/proc\/meminfo \r\nMemTotal:        8010436 kB\r\nMemFree:         7514008 kB\r\nMemAvailable:    7567204 kB\r\nBuffers:             872 kB\r\nCached:           282844 kB\r\nSwapCached:            0 kB\r\nActive:           213156 kB\r\nInactive:         111632 kB\r\nActive(anon):      41264 kB\r\nInactive(anon):    32888 kB\r\nActive(file):     171892 kB\r\nInactive(file):    78744 kB\r\nUnevictable:           0 kB\r\nMlocked:               0 kB\r\nSwapTotal:             0 kB\r\nSwapFree:              0 kB\r\nDirty:                32 kB\r\nWriteback:             0 kB\r\nAnonPages:         41088 kB\r\nMapped:            35936 kB\r\nShmem:             33080 kB\r\nSlab:              66888 kB\r\nSReclaimable:      48120 kB\r\nSUnreclaim:        18768 kB\r\nKernelStack:        1872 kB\r\nPageTables:         2788 kB\r\nNFS_Unstable:          0 kB\r\nBounce:                0 kB\r\nWritebackTmp:          0 kB\r\nCommitLimit:     4005216 kB\r\nCommitted_AS:     272452 kB\r\nVmallocTotal:   34359738367 kB\r\nVmallocUsed:       22136 kB\r\nVmallocChunk:   34359707388 kB\r\nHardwareCorrupted:     0 kB\r\nAnonHugePages:      4096 kB\r\nHugePages_Total:       0\r\nHugePages_Free:        0\r\nHugePages_Rsvd:        0\r\nHugePages_Surp:        0\r\nHugepagesize:       2048 kB\r\nDirectMap4k:       79740 kB\r\nDirectMap2M:     3065856 kB\r\nDirectMap1G:     7340032 kB\r\n<\/pre>\n
2.atop<\/strong><\/strong><\/span><\/div>\n

atop \u547d\u4ee4\u662f\u4e00\u4e2a\u7ec8\u7aef\u73af\u5883\u7684\u76d1\u63a7\u547d\u4ee4\u3002\u5b83\u663e\u793a\u7684\u662f\u5404\u79cd\u7cfb\u7edf\u8d44\u6e90\uff08CPU, memory, network, I\/O, kernel\uff09\u7684\u7efc\u5408\uff0c\u5e76\u4e14\u5728\u9ad8\u8d1f\u8f7d\u7684\u60c5\u51b5\u4e0b\u8fdb\u884c\u4e86\u5f69\u8272\u6807\u6ce8\u3002<\/p>\n

$\u00a0sudo\u00a0atop<\/pre>\n

\"\"<\/a><\/p>\n

3.free<\/strong><\/strong><\/span><\/div>\n

free \u547d\u4ee4\u662f\u4e00\u4e2a\u5feb\u901f\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u65b9\u6cd5\uff0c\u5b83\u662f\u5bf9 \/proc\/meminfo \u6536\u96c6\u5230\u7684\u4fe1\u606f\u7684\u4e00\u4e2a\u6982\u8ff0\u3002<\/p>\n

$\u00a0free<\/span>\u00a0-h<\/pre>\n
4.GNOME System Monitor<\/strong><\/strong><\/span><\/div>\n

GNOME System Monitor \u662f\u4e00\u4e2a\u663e\u793a\u6700\u8fd1\u4e00\u6bb5\u65f6\u95f4\u5185\u7684 CPU\u3001\u5185\u5b58\u3001\u4ea4\u6362\u533a\u53ca\u7f51\u7edc\u7684\u4f7f\u7528\u60c5\u51b5\u7684\u89c6\u56fe\u5de5\u5177\u3002\u5b83\u8fd8\u63d0\u4f9b\u4e86\u4e00\u79cd\u67e5\u770b CPU \u53ca\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u65b9\u6cd5\u3002<\/p>\n

$\u00a0gnome-system-monitor<\/pre>\n
5.htop<\/strong><\/strong><\/span><\/div>\n

htop \u547d\u4ee4\u663e\u793a\u4e86\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u5b9e\u65f6\u4f7f\u7528\u7387\u3002\u5b83\u63d0\u4f9b\u4e86\u6240\u6709\u8fdb\u7a0b\u7684\u5e38\u9a7b\u5185\u5b58\u5927\u5c0f\u3001\u7a0b\u5e8f\u603b\u5185\u5b58\u5927\u5c0f\u3001\u5171\u4eab\u5e93\u5927\u5c0f\u7b49\u7684\u62a5\u544a\u3002\u5217\u8868\u53ef\u4ee5\u6c34\u5e73\u53ca\u5782\u76f4\u6eda\u52a8\u3002<\/p>\n

$\u00a0htop\r\n<\/pre>\n
6.KDE System Monitor<\/strong><\/strong><\/span><\/div>\n

\u529f\u80fd\u540c 4 \u4e2d\u4ecb\u7ecd\u7684 GENOME \u7248\u672c\u3002<\/p>\n

$\u00a0ksysguard<\/pre>\n
7.memstat<\/strong><\/strong><\/span><\/div>\n

memstat \u662f\u4e00\u4e2a\u6709\u6548\u8bc6\u522b executable(s), process(es) and shared libraries \u4f7f\u7528\u865a\u62df\u5185\u5b58\u60c5\u51b5\u7684\u547d\u4ee4\u3002\u7ed9\u5b9a\u4e00\u4e2a\u8fdb\u7a0b ID\uff0cmemstat \u53ef\u4ee5\u5217\u51fa\u8fd9\u4e2a\u8fdb\u7a0b\u76f8\u5173\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3001\u6570\u636e\u548c\u5171\u4eab\u5e93\u3002<\/p>\n

$\u00a0memstat\u00a0-p<\/pre>\n
8.nmon<\/strong><\/strong><\/span><\/div>\n

nmon \u662f\u4e00\u4e2a\u57fa\u4e8e ncurses \u7684\u7cfb\u7edf\u57fa\u51c6\u6d4b\u8bd5\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u76d1\u63a7 CPU\u3001\u5185\u5b58\u3001I\/O\u3001\u6587\u4ef6\u7cfb\u7edf\u53ca\u7f51\u7edc\u8d44\u6e90\u7b49\u7684\u4e92\u52a8\u6a21\u5f0f\u3002\u5bf9\u4e8e\u5185\u5b58\u7684\u4f7f\u7528\uff0c\u5b83\u53ef\u4ee5\u5b9e\u65f6\u7684\u663e\u793a\u603b \/ \u5269\u4f59\u5185\u5b58\u3001\u4ea4\u6362\u7a7a\u95f4\u7b49\u4fe1\u606f\u3002<\/p>\n

$\u00a0nmon<\/pre>\n
9.ps<\/strong><\/strong><\/span><\/div>\n

ps \u547d\u4ee4\u53ef\u4ee5\u5b9e\u65f6\u7684\u663e\u793a\u5404\u4e2a\u8fdb\u7a0b\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002Reported memory usage information includes %MEM (percent of physical memory used), VSZ (totalamount of virtual memory used), and RSS (total amount of physical memory used)\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 \u201c\u2013sort\u201d \u9009\u9879\u5bf9\u8fdb\u7a0b\u8fdb\u884c\u6392\u5e8f\uff0c\u4f8b\u5982\u6309 RSS \u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n

$ ps aux | sort -rss<\/pre>\n

\u56fe8\uff1aLinux\u4e0b\u67e5\u770b\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u65b9\u6cd5\u603b\u7ed3<\/p>\n

10.smem<\/strong><\/strong><\/span><\/div>\n

smem \u547d\u4ee4\u5141\u8bb8\u4f60\u7edf\u8ba1\u57fa\u4e8e \/ proc \u4fe1\u606f\u7684\u4e0d\u540c\u8fdb\u7a0b\u548c\u7528\u6237\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u3002\u5185\u5b58\u4f7f\u7528\u60c5\u51b5\u7684\u5206\u6790\u53ef\u4ee5\u5bfc\u51fa\u56fe\u8868\uff08\u5982\u6761\u5f62\u56fe\u548c\u997c\u56fe\uff09\u3002<\/p>\n

 \r\nsmem  -P sshd -k\r\n  PID User     Command                         Swap      USS      PSS      RSS \r\n  815 root     \/usr\/sbin\/sshd                     0   868.0K   951.0K     1.3M \r\n14104 root     sshd: root@pts\/0                   0     2.8M     3.5M     5.3M \r\n14292 root     python \/usr\/bin\/smem -P ssh        0     5.1M     5.8M     7.2M \r\n<\/pre>\n
11.top<\/strong><\/strong><\/span><\/div>\n

top \u547d\u4ee4\u63d0\u4f9b\u4e86\u5b9e\u65f6\u7684\u8fd0\u884c\u4e2d\u7684\u7a0b\u5e8f\u7684\u8d44\u6e90\u4f7f\u7528\u7edf\u8ba1\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u5185\u5b58\u7684\u4f7f\u7528\u548c\u5927\u5c0f\u6765\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n

$\u00a0top<\/span><\/pre>\n
12.vmstat<\/strong><\/strong><\/span><\/div>\n

vmstat \u547d\u4ee4\u663e\u793a\u5b9e\u65f6\u7684\u548c\u5e73\u5747\u7684\u7edf\u8ba1\uff0c\u8986\u76d6 CPU\u3001\u5185\u5b58\u3001I\/O \u7b49\u5185\u5bb9\u3002\u4f8b\u5982\u5185\u5b58\u60c5\u51b5\uff0c\u4e0d\u4ec5\u663e\u793a\u7269\u7406\u5185\u5b58\uff0c\u4e5f\u7edf\u8ba1\u865a\u62df\u5185\u5b58\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u67e5\u770b RAM \u4f7f\u7528\u60c5\u51b5\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u901a\u8fc7 \u3002\u8fd9\u4e2a\u52a8\u6001\u66f4\u65b0\u7684\u865a\u62df\u6587\u4ef6\u5b9e\u9645\u4e0a\u662f\u8bb8\u591a\u5176\u4ed6\u5185\u5b58\u76f8\u5173\u5de5\u5177 (\u5982\uff1afree […]<\/p>\n","protected":false},"author":643,"featured_media":198072,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-197887","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=197887"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197887\/revisions"}],"predecessor-version":[{"id":198073,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/197887\/revisions\/198073"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/198072"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=197887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=197887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=197887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}