linux下檢視記憶體使用情況

2022-02-19 06:18:57 字數 1860 閱讀 8300

在linux下檢視記憶體我們一般用free命令:

[root@scs-2 tmp]# free

total       used       free     shared    buffers     cached

mem:       3266180    3250004      16176          0     110652    2668236

-/+ buffers/cache:     471116    2795064

swap:      2048276      80160    1968116

接下來解釋什麼時候記憶體會被交換,以及按什麼方交換。 當可用記憶體少於額定值的時候,就會開會進行交換。

如何看額定值:

cat /proc/meminfo

用free -m檢視的結果:

[root@scs-2 tmp]# free -m

total       used       free     shared    buffers     cached

mem:          3189       3173         16          0        107       2605

-/+ buffers/cache:        460       2729

swap:         2000         78       1921

檢視/proc/kcore檔案的大小(記憶體映象):

[root@scs-2 tmp]# ll -h /proc/kcore

-r-------- 1 root root 4.1g jun 12 12:04 /proc/kcore

備註:占用記憶體的測量

測量乙個程序占用了多少記憶體,linux為我們提供了乙個很方便的方法,/proc目錄為我們提供了所有的資訊,實際上top等工具也通過這裡來獲取相應的資訊。

/proc/meminfo 機器的記憶體使用資訊

/proc/pid/maps pid為程序號,顯示當前程序所占用的虛擬位址。

/proc/pid/statm 程序所占用的記憶體

[root@localhost ~]# cat /proc/self/statm

654 57 44 0 0 334 0

輸出解釋

cpu 以及cpu0。。。的每行的每個引數意思(以第一行為例)為:

引數 解釋 /proc//status

size (pages) 任務虛擬位址空間的大小 vmsize/4

resident(pages) 應用程式正在使用的物理記憶體的大小 vmrss/4

shared(pages) 共享頁數 0

trs(pages) 程式所擁有的可執行虛擬記憶體的大小 vmexe/4

lrs(pages) 被映像到任務的虛擬記憶體空間的庫的大小 vmlib/4

drs(pages) 程式資料段和使用者態的棧的大小 (vmdata+ vmstk )4

dt(pages) 04

檢視機器可用記憶體

/proc/28248/>free

total used free shared buffers cached

mem: 1023788 926400 97388 0 134668 503688

-/+ buffers/cache: 288044 735744

swap: 1959920 89608 1870312

我們通過free命令檢視機器空閒記憶體時,會發現free的值很小。這主要是因為,在linux中有這麼一種思想,記憶體不用白不用,因此它盡可能的cache和buffer一些資料,以方便下次使用。但實際上這些記憶體也是可以立刻拿來使用的。

所以 空閒記憶體=free+buffers+cached=total-used

Linux下檢視記憶體使用情況

測量乙個程序占用了多少記憶體,linux為我們提供了乙個很方便的方 法,proc目錄為我們提供了所有的資訊,實際上top等工具也通過 這裡來獲取相應的資訊。proc meminfo 機器的記憶體使用資訊 proc pid maps pid為程序號,顯示當前程序所占用的虛擬位址。proc pid st...

linux下檢視記憶體使用情況

在linux下檢視記憶體我們一般用free命令 free total used free shared buffers cached mem 3266180 3250004 16176 0 110652 2668236 buffers cache 471116 2795064 swap 204827...

linux下檢視記憶體使用情況

在linux下檢視記憶體我們一般用free命令 free total used free shared buffers cached mem 3266180 3250004 16176 0 110652 2668236 buffers cache 471116 2795064 swap 204827...