ºìÁªLinuxÃÅ»§
Linux°ïÖú

Linux²é¿´ÄÚ´æÃüÁî¼°Æä¶ÔÃüÁîÏÔʾµÄ½âÊÍ

·¢²¼Ê±¼ä:2011-06-17 20:56:52À´Ô´:LinuxÉçÇø×÷Õß:linuxʹÓÃÕß

ÎÒÃÇͨ¹ýLinux²é¿´ÄÚ´æfreeÃüÁî²é¿´»úÆ÷¿ÕÏÐÄÚ´æʱ£¬»á·¢ÏÖfreeµÄÖµºÜС¡£ÏÂÃæÎÒÃǾÍÀ´Á˽âѧϰÏÂLinux²é¿´ÄÚ´æµÄÃüÁîºÍ¶ÔÕâЩÃüÁîµÄ½âÊÍ£¬ÕâÑù´ó¼Ò¸üÄܹ»Éî¿ÌÀí½âÎÒÃǵÄLinux²é¿´ÄÚ´æÃüÁî¡£


ÔÚ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


ÏÂÃæÊǶÔLinux²é¿´ÄÚ´æÃüÁîÖÐÕâЩÊýÖµµÄ½âÊÍ£º
total:×ܼÆÎïÀíÄÚ´æµÄ´óС¡£
used:ÒÑʹÓöà´ó¡£
free:¿ÉÓÃÓжàÉÙ¡£
Shared:¶à¸ö½ø³Ì¹²ÏíµÄÄÚ´æ×ܶ
Buffers/cached:´ÅÅÌ»º´æµÄ´óС¡£
µÚÈýÐÐ(-/+ buffers/cached):
used:ÒÑʹÓöà´ó¡£
free:¿ÉÓÃÓжàÉÙ¡£
µÚËÄÐоͲ»¶à½âÊÍÁË¡£


Çø±ð£ºµÚ¶þÐÐ(mem)µÄused/freeÓëµÚÈýÐÐ(-/+ buffers/cache) used/freeµÄÇø±ð¡£ ÕâÁ½¸öµÄÇø±ðÔÚÓÚʹÓõĽǶÈÀ´¿´£¬µÚÒ»ÐÐÊÇ´ÓOSµÄ½Ç¶ÈÀ´¿´£¬ÒòΪ¶ÔÓÚOS£¬buffers/cached ¶¼ÊÇÊôÓÚ±»Ê¹Óã¬ËùÒÔËûµÄ¿ÉÓÃÄÚ´æÊÇ16176KB,ÒÑÓÃÄÚ´æÊÇ3250004KB,ÆäÖаüÀ¨£¬Äںˣ¨OS£©Ê¹ÓÃ+Application(X, oracle,etc)ʹÓõÄ+buffers+cached.


µÚÈýÐÐËùÖ¸µÄÊÇ´ÓÓ¦ÓóÌÐò½Ç¶ÈÀ´¿´£¬¶ÔÓÚÓ¦ÓóÌÐòÀ´Ëµ£¬buffers/cached ÊǵÈÓÚ¿ÉÓõģ¬ÒòΪbuffer/cachedÊÇΪÁËÌá¸ßÎļþ¶ÁÈ¡µÄÐÔÄÜ£¬µ±Ó¦ÓóÌÐòÐèÔÚÓõ½ÄÚ´æµÄʱºò£¬buffer/cached»áºÜ¿ìµØ±»»ØÊÕ¡£


ËùÒÔ´ÓÓ¦ÓóÌÐòµÄ½Ç¶ÈÀ´Ëµ£¬¿ÉÓÃÄÚ´æ=ϵͳfree memory+buffers+cached¡£


ÈçÉÏÀý£º
2795064=16176+110652+2668236


½ÓÏÂÀ´½âÊÍʲôʱºòÄÚ´æ»á±»½»»»£¬ÒÔ¼°°´Ê²Ã´·½½»»»¡£ µ±¿ÉÓÃÄÚ´æÉÙÓڶֵµÄʱºò£¬¾Í»á¿ª»á½øÐн»»»¡£


Linux²é¿´ÄÚ´æÃüÁîʱÈçºÎ¿´¶î¶¨Öµ£º
cat /proc/meminfo
[root@scs-2 tmp]# cat /proc/meminfo
MemTotal:      3266180 kB
MemFree:         17456 kB
Buffers:        111328 kB
Cached:        2664024 kB
SwapCached:          0 kB
Active:         467236 kB
Inactive:      2644928 kB
HighTotal:           0 kB
HighFree:            0 kB
LowTotal:      3266180 kB
LowFree:         17456 kB
SwapTotal:     2048276 kB
SwapFree:      1968116 kB
Dirty:  8 kB
Writeback:           0 kB
Mapped:         345360 kB
Slab:           112344 kB
Committed_AS:   535292 kB
PageTables:       2340 kB
VmallocTotal: 536870911 kB
VmallocUsed:    272696 kB
VmallocChunk: 536598175 kB
HugePages_Total:     0
HugePages_Free:      0
Hugepagesize:     2048 kB


ÓÃ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


Linux²é¿´ÄÚ´æÃüÁîµÄÊä³ö½âÊÍ
CPU ÒÔ¼°CPU0¡£¡£¡£µÄÿÐеÄÿ¸ö²ÎÊýÒâ˼£¨ÒÔµÚÒ»ÐÐΪÀý£©Îª£º


²ÎÊý ½âÊÍ /proc//status
Size (pages) ÈÎÎñÐéÄâµØÖ·¿Õ¼äµÄ´óС VmSize/4
Resident(pages) Ó¦ÓóÌÐòÕýÔÚʹÓõÄÎïÀíÄÚ´æµÄ´óС VmRSS/4
Shared(pages) ¹²ÏíÒ³Êý \
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