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

¹ØÓÚswap,ÐéÄâÄÚ´æºÍpageµÄÇø±ð

·¢²¼Ê±¼ä:2008-02-19 11:16:52À´Ô´:ºìÁª×÷Õß:Luoall
ÒªÃ÷°×Õâ¸öÊ×ÏÈÒªÖªµÀʲôÊDZ£»¤Ä£Ê½ºÍʵģʽ¡£

ÒÔÇ°µÄ²Ù×÷ϵͳÊÇʵģʽ£¬ÀýÈçdos¡£Ã¿¸öʱºòÖ»ÓÐÒ»¸ö½ø³ÌÔÚÅÜ£¬Õâ¸ö½ø³ÌʹÓÃÈ«²¿µÄÎïÀíÄÚ´æ¡£

ºóÀ´·¢Õ¹µ½±£»¤Ä£Ê½£¬·Öʱ¶à½ø³Ì¡£Ò»¸öCPUÉÏÅܶà¸ö½ø³Ì£¬ µ«½ø³Ì²»ÖªµÀµ½µ×ÓжàÉÙÄÚ´æ¿ÉÒÔÓã¬ËüÄÜ·ÃÎÊÄÚ´æ×î´óµØÖ·¡£ÀýÈç16λϵͳ¾ÍÄÜ·ÃÎÊ2^16byte£¬32λ¾ÍÊÇ2^32λ¡£µ«ÊÇʵ¼ÊÉÏûÓÐÄÇô¶àÄÚ´æ°¢£¿Ôõô°ì£¿±£»¤Ä£Ê½¾ÍÓ¦Ô˶øÉúÁË¡£

¼ÙÉè½ø³ÌÊÇÒ»¸öÁõÏ飬²ÃÅУ¨ÏµÍ³£©Ò»·¢ÁîËû¾Í¿ªÊ¼Åܲ½¡£µ«ÊDzÃÅÐ˵¸øÄã1Ã룬¿ÉÒÔÅÜ100Ãס£ÓÚÊÇÁõÏ鿪ʼÅܲ½£¨ÄÚ´æµØÖ·£©£¬Ò»ÃëºóÁõÏéÖ»ÅÜÁË10Ã×£¬²ÃÅдµÉÚ˵£ºÁõÏéÄãÏÈЪ»á£¬ÎÒҪȥ¸øÍõ¾üϼ´µÉÚÄØ£¬ÏÖ¼ÇסÄãÅܵ½ÄÄÀïÁË£¨±£»¤£©£¬µÈ»á´ÓÕâÀ↑ʼ¡£²ÃÅиøÍõ¾üϼ´µÉÚ£¬Ò»Ö»ÅÜÒ»Ã룬»ØÀ´ÔÙ¸øÁõÏé´µÉÚÔÙÅÜ1Ã룬Èç´ËÍù¸´¡£¿ªÊ¼Åܲ½µÄÈËÉÙ£¬ÁõÏ黹¿ÉÒÔÕ¾ÔÚÅܵÀÉÏÐÝÏ¢¡£ºóÀ´Åܲ½µÄÈËÔ½À´Ô½¶à£¬ÅܵÀ¶¼¼·ÂúÁËÈË£¬ÄÇôֻÄÜ°ÑһЩÈËÒƶ¯µ½ÅܵÀÅԵIJݵØÉÏÐÝÏ¢£¨½»»»£©¡£ºóÀ´·¢ÏÖÓÐЩÈ˺áÆßÊú°ËµÄÌÉ×Å£¬Õ¼Á˲»Éٿռ䣬ÓÚÊǹ涨ÿ¸öÈËÖ»ÄÜÕ¾×Å£¨page),ÕâÑù¿ÉÒÔÈÝÄɺܶàµÄÈË¡£

swap -- ²ÝµØ£¬¾ÍÊÇ´æ·ÅpageµÄÓ²Å̿ռ䡣
virtual memory -- ¼ÙÉèÁõÏéÅÜnȦ¾ÍÒѾ­Êǵ½±±¾©µÄ¾àÀëÁË£¬¿ÉÊÇËûÃÇ»¹ÔÚÔ­µØ¡£ÐéÄâ¾ÍÊDz»´æÔڵġ£
page -- ²ÝµØÉϵĸñ£¬Ã¿´ÎÖ»ÈÝÄÉÒ»¸öÈË¡£

ΪÁËÌá¸ß´ÅÅÌ´æȡЧÂÊ, Linux×öÁËһЩ¾«ÐĵÄÉè¼Æ, ³ýÁ˶Ôdentry½øÐлº´æ(ÓÃÓÚVFS,¼ÓËÙÎļþ·¾¶Ãûµ½inodeµÄת»»), »¹²ÉÈ¡ÁËÁ½ÖÖÖ÷ÒªCache·½Ê½:Buffer CacheºÍPage Cache.Ç°ÕßÕë¶Ô´ÅÅÌ¿éµÄ¶Áд,ºóÕßÕë¶ÔÎļþinodeµÄ¶Áд.ÕâЩCacheÓÐЧËõ¶ÌÁËI/Oϵͳµ÷ÓÃ(±ÈÈçread,write,getdents)µÄʱ¼ä.

ÄÚ´æ»î¶¯»ù±¾ÉÏ¿ÉÒÔÓÃ3¸öÊý×ÖÀ´Á¿»¯:»î¶¯ÐéÄâÄÚ´æ×ÜÁ¿,½»»»(swapping)Âʺ͵÷Ò³(paging)ÂÊ.ÆäÖеÚÒ»¸öÊý×Ö±íÃ÷ÄÚ´æµÄ×ÜÐèÇóÁ¿,ºóÁ½¸öÊý×Ö±íʾÄÇЩÄÚ´æÖÐÓжàÉÙ±ÈÀýÕý´¦ÔÚʹÓÃÖ®ÖÐ.Ä¿±êÊǼõÉÙÄÚ´æ»î¶¯»òÔö¼ÓÄÚ´æÁ¿,Ö±µ½µ÷Ò³Âʱ£³ÖÔÚÒ»¸ö¿ÉÒÔ½ÓÊܵÄˮƽÉÏΪֹ.

»î¶¯ÐéÄâÄÚ´æµÄ×ÜÁ¿(VM)=ʵ¼ÊÄÚ´æ´óС(size of real memory)(ÎïÀíÄÚ´æ)+ʹÓõĽ»»»¿Õ¼ä´óС(amount of swap space used)

µ±³ÌÐòÔËÐÐÐèÒªµÄÄÚ´æ´óÓÚÎïÀíÄÚ´æʱ£¬UNIXϵͳ²ÉÓÃÁ˵÷Ò³»úÖÆ£¬¼´ÏµÍ³copyһЩÄÚ´æÖеÄÒ³Ãæµ½´ÅÅÌÉÏ£¬ÌÚ³öÀ´¿Õ¼ä¹©½ø³ÌʹÓá£

´ó¶àÊýϵͳ¿ÉÒÔÈÌÊÜż¶ûµÄµ÷Ò³£¬µ«ÊÇƵ·±µÄµ÷Ò³»áʹϵͳÐÔÄܼ±¾çϽµ¡£

UNIXÄÚ´æ¹ÜÀí£ºUNIXϵͳͨ¹ý2ÖÖ·½·¨½øÐÐÄÚ´æ¹ÜÀí£¬¡°µ÷Ò³Ëã·¨¡±£¬¡°½»»»¼¼Êõ¡±¡£

µ÷Ò³Ëã·¨Êǽ«ÄÚ´æÖÐ×î½ü²»³£Ê¹ÓõÄÒ³Ãæ»»µ½´ÅÅÌÉÏ£¬°Ñ³£Ê¹ÓõÄÒ³Ã棨»î¶¯Ò³Ã棩±£ÁôÔÚÄÚ´æÖй©½ø³ÌʹÓá£

½»»»¼¼ÊõÊÇϵͳ½«Õû¸ö½ø³Ì£¬¶ø²»ÊDz¿·ÖÒ³Ã棬ȫ²¿»»µ½´ÅÅÌÉÏ¡£Õý³£Çé¿öÏ£¬ÏµÍ³»á·¢ÉúһЩ½»»»¹ý³Ì¡£

µ±ÄÚ´æÑÏÖز»×ãʱ£¬ÏµÍ³»áƵ·±Ê¹Óõ÷Ò³ºÍ½»»»£¬ÕâÔö¼ÓÁË´ÅÅÌI/OµÄ¸ºÔØ¡£½øÒ»²½½µµÍÁËϵͳ¶Ô×÷ÒµµÄÖ´ÐÐËٶȣ¬¼´ÏµÍ³I/O×ÊÔ´ÎÊÌâÓÖ»áÓ°Ïìµ½ÄÚ´æ×ÊÔ´µÄ·ÖÅä¡£

UnixµÄÐéÄâÄÚ´æ

UnixµÄÐéÄâÄÚ´æÊÇÒ»¸öÊ®·Ö¸´ÔÓµÄ×Óϵͳ£¬ËüʵÏÖÁ˽ø³Ì¼ä´úÂëÓëÊý¾Ý¹²Ïí»úÖƵÄ͸Ã÷ÐÔ£¬²¢Äܹ»·ÖÅä±ÈϵͳÏÖÓÐÎïÀíÄÚ´æ¸ü¶àµÄÄڴ棬ijЩ²Ù×÷ϵͳµÄÐé´æÉõÖÁÄÜͨ¹ýÌṩ»º´æ¹¦ÄÜÓ°Ïìµ½ÎļþϵͳµÄÐÔÄÜ£¬¸÷ÖÖ·ç¸ñµÄUNIXµÄÐé´æµÄʵÏÖ·½Ê½Çø±ðºÜ´ó£¬µ«¶¼Àë²»¿ªÏÂÃæµÄ4¸ö¸ÅÄî¡£

1:ʵ¼ÊÄÚ´æ

ʵ¼ÊÄÚ´æÊÇÖ¸Ò»¸öϵͳÖÐʵ¼Ê´æÔÚµÄÎïÀíÄڴ棬³ÆΪRAM¡£Êµ¼ÊÄÚ´æÊÇ´æ´¢ÁÙʱÊý¾Ý×î¿ì×îÓÐЧµÄ·½Ê½£¬Òò´Ë±ØÐ뾡¿ÉÄܵطÖÅä¸øÓ¦ÓóÌÐò£¬ÏÖÔÚµÄRAMµÄÐÎʽÓжàÖÖ£ºSIMM¡¢DIMM¡¢Rambus¡¢DDRµÈ£¬ºÜ¶àRAM¶¼¿ÉÒÔʹÓþÀ´í»úÖÆ£¨ECC£©¡£

2:½»»»¿Õ¼ä

½»»»¿Õ¼äÊÇרÃÅÓÃÓÚÁÙʱ´æ´¢ÄÚ´æµÄÒ»¿é´ÅÅ̿ռ䣬ͨ³£ÔÚÒ³Ãæµ÷¶ÈºÍ½»»»½ø³ÌÊý¾ÝʱʹÓã¬Í¨³£ÍƼö½»»»¿Õ¼äµÄ´óСӦ¸ÃÊÇÎïÀíÄÚ´æµÄ¶þµ½Ëı¶¡£

3:Ò³Ãæµ÷¶È

Ò³Ãæµ÷¶ÈÊÇÖ¸´Ó´ÅÅÌÏòÄÚ´æ´«ÊäÊý¾Ý£¬ÒÔ¼°Ïà·´µÄ¹ý³Ì£¬Õâ¸ö¹ý³ÌÖ®ËùÒÔ±»³ÆΪҳÃæµ÷¶È£¬ÊÇÒòΪUnixÄڴ汻ƽ¾ù»®·Ö³É´óСÏàµÈµÄÒ³Ã棻ͨ³£Ò³Ãæ´óСΪ4KBºÍ8KB£¨ÔÚSolarisÖпÉÒÔÓÃpagesizeÃüÁî²é¿´£©¡£µ±¿ÉÖ´ÐгÌÐò¿ªÊ¼ÔËÐÐʱ£¬ËüµÄÓ³Ïó»áÒ»Ò³Ò»Ò³µØ´Ó´ÅÅÌÖл»È룬Óë´ËÀàËÆ£¬µ±Ä³Ð©ÄÚ´æÔÚÒ»¶Îʱ¼äÄÚ¿ÕÏУ¬¾Í¿ÉÒÔ°ÑËüÃÇ»»³öµ½½»»»¿Õ¼äÖУ¬ÕâÑù¾Í¿ÉÒÔ°Ñ¿ÕÏеÄRAM½»¸øÆäËûÐèÒªËüµÄ³ÌÐòʹÓá£

4:½»»»

Ò³Ãæµ÷¶Èͨ³£ÈÝÒ׺ͽ»»»µÄ¸ÅÄî»ìÏý£¬Ò³Ãæµ÷¶ÈÊÇÖ¸°ÑÒ»¸ö½ø³ÌËùÕ¼ÄÚ´æµÄ¿ÕÏв¿·Ö´«Êäµ½´ÅÅÌÉÏ£¬¶ø½»»»ÊÇÖ¸µ±ÏµÍ³ÖÐʵ¼ÊµÄÄÚ´æÒѲ»¹»Âú×ãеķÖÅäÐèÇóʱ£¬°ÑÕû¸ö½ø³Ì´«Êäµ½´ÅÅÌÉÏ£¬½»»»»î¶¯Í¨³£Òâζ×ÅÄÚ´æ²»×ã¡£

vmstat¼àÊÓÄÚ´æÐÔÄÜ£º¸ÃÃüÁîÓÃÀ´¼ì²éÐéÄâÄÚ´æµÄͳ¼ÆÐÅÏ¢£¬²¢¿ÉÏÔʾÓйؽø³Ì״̬¡¢¿ÕÏкͽ»»»¿Õ¼ä¡¢µ÷Ò³¡¢´ÅÅ̿ռ䡢CPU¸ºÔغͽ»»»£¬cacheË¢ÐÂÒÔ¼°Öжϵȷ½ÃæµÄÐÅÏ¢¡£


Procs

r: The number of processes waiting for run time.

ÔËÐеĺ͵ȴý(CPUʱ¼äƬ)ÔËÐеĽø³ÌÊý£¬Õâ¸öÖµÒ²¿ÉÒÔÅжÏÊÇ·ñÐèÒªÔö¼ÓCPU(³¤ÆÚ´óÓÚ1)

b: The number of processes in uninterruptable sleep.

´¦ÓÚ²»¿ÉÖжÏ״̬µÄ½ø³ÌÊý£¬³£¼ûµÄÇé¿öÊÇÓÉIOÒýÆðµÄ

w: The number of processes swapped out but otherwise runnable.

Memory

swpd: the amount of virtual memory used (kB).

free: the amount of idle memory (kB).

¿ÕÏеÄÎïÀíÄÚ´æ

buff: the amount of memory used as buffers (kB).

×÷Ϊbuffer cacheµÄÄڴ棬¶Ô¿éÉ豸µÄ¶Áд½øÐлº³å

cache: the amount of memory used as cache.

Swap

si: Amount of memory swapped in from disk (kB/s). ÐéÄâÄÚ´æµÄÒ³µ¼Èë(´ÓSWAP DISKµ¼ÈëRAM)

so: Amount of memory swapped to disk (kB/s). ÐéÄâÄÚ´æµÄÒ³µ¼³ö.

(´ÓRAMµ½SWAP DISK)
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 2 ÌõÆÀÂÛ

  1. liaoyonghan ÓÚ 2008-02-19 18:38:28·¢±í:

    Â¥Ö÷½²µÄºÜÇå³þ

  2. chenjiancong ÓÚ 2008-02-19 12:52:21·¢±í:

    ²»´í£¬½²½âµÃÏ൱²»´í£¡