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

linux ÏÂÐéÄâÄÚ´æµÄÓ°Ïì

·¢²¼Ê±¼ä:2008-02-27 20:52:45À´Ô´:ºìÁª×÷Õß:uzrcgunr
Ò²ÐíÄãºÜÉÙÃæÁÙÕâÒ»Çé¿ö£¬µ«ÊÇÒ»µ©Èç´Ë£¬ÄãÒ»¶¨ÖªµÀ³öʲô´íÁË£º¿ÉÓÃÄÚ´æ²»×ã»òÕß˵ÄÚ´æÓþ¡(OOM)¡£½á¹û·Ç³£µäÐÍ£ºÄã²»ÄÜÔÙ·ÖÅäÄڴ棬Äں˻áɱµôÒ»¸öÈÎÎñ(Ò»°ãÊÇÕýÔÚÔËÐÐÄǸö)¡£Ò»°ã°ëËæ×Å´óÁ¿µÄ½»»»¶Áд£¬Äã¿ÉÒÔ´ÓÆÁÄ»ºÍ´ÅÅ̶¯Ïò¿´³öÀ´¡£

Õâ¸öÎÊÌâÏÂÃæÒþº¬×űðµÄÎÊÌ⣺ÄãÐèÒª·ÖÅä¶àÉÙÄڴ棿²Ù×÷ϵͳ¸øÄã·ÖÅäÁ˶àÉÙ£¿OOMµÄ»ù±¾Ô­ÒòºÜ¼òµ¥£¬ÄãÉêÇëµÄÄÚ´æ¶àÓÚϵͳ¿ÉÓÃÁ¿¡£ÎÒµÃ˵ÊÇÐéÄâÄڴ棬ÒòΪ½»»»·ÖÇøÒ²°üÀ¨ÔÚÄÚ¡£

Á˽âOOM

¿ªÊ¼Á˽âOOM£¬Ê×ÏÈÊÔÊÔÕâ¶Î»á·ÖÅä´óÁ¿ÄÚ´æµÄ´úÂ룺

ÒýÓÃ:
#include
#include
#define MEGABYTE 1024*1024
int main(int argc, char *argv[])
{
void *myblock = NULL;
int count = 0;
while (1)
{
myblock = (void *) malloc(MEGABYTE);
if (!myblock) break;
printf(¡±Currently allocating %d MBn¡±, ++count);
}
exit(0);
}


±àÒëһϣ¬ÔËÐÐËüÖ®ºóµÈÒ»»á¡£ÏµÍ³ÔçÍí»áOOM¡£È»ºóÊÔÊÔÏÂÃæÕâ¶Î£¬·ÖÅä´óÁ¿ÄÚ´æ²¢ÓÃ1дÈë:

ÒýÓÃ:
#include
#include
#define MEGABYTE 1024*1024
int main(int argc, char *argv[])
{
void *myblock = NULL;
int count = 0;
while(1)
{
myblock = (void *) malloc(MEGABYTE);
if (!myblock) break;
memset(myblock,1, MEGABYTE);
printf(¡±Currently allocating %d MBn¡±,++count);
}
exit(0);
}


·¢ÏÖ²î±ðÁËô£¿A±ÈB·ÖÅäÁ˸ü¶àÄÚ´æ¡£¶øÇÒB±»É±µôµÄ¸üÔçһЩ¡£Á½¸ö³ÌÐò¶¼ÒòΪûÓпÉÓÃÄÚ´æ¶øÍ˳ö¡£¸ü׼ȷµÄ˵£¬AÒòΪʧ°ÜµÄmalloc()¶øÓÅÑŵÄÍ˳öÁË£¬BÊDZ»OOMɱÊָɵôÁË¡£

Ê×Ïȹ۲ì·ÖÅäµÄÄÚ´æ¿éÊý¡£¼ÙÉèÄãʹÓÃ256MÄڴ棬888M½»»»·ÖÇø(ÎÒµÄÇé¿ö)£¬B½áÊøʱ£º

Currently allocating 1081 MB
¶øA½áÊøʱ£º

Currently allocating 3056 MB

AÔõôŪÀ´µÄÁíÍâ1975M£¿ÎÒÆ­ÈË£¿Ã»ÓУ¡Èç¹ûÄã×Ðϸ¿´£¬Äã»á·¢ÏÖBÓÃ1ÌîÂúµÃµ½µÄÄڴ棬¶øA¼¸ºõ²»ÄÃËûÃǸÉʲô¡£LinuxÔÊÐíÍƳٵÄÒ³·ÖÅ䣬»»¾ä»°Ëµ£¬Ö»µ±ÄãÕæµÄÒªÓõÄʱºò²Å¿ªÊ¼·ÖÅ䶯×÷£¬±ÈÈçдÈëÊý¾Ýʱ¡£ËùÒÔ£¬³ý·ÇдÈëÊý¾Ý£¬·ñÔòÄã¿ÉÒÔÒ»Ö±Òª¸ü¶àÄÚ´æ¡£ÊõÓï³Æ֮ΪÀÖ¹ÛµÄÄÚ´æ·ÖÅä¡£

²é¿´/proc//statusÀ´È·ÈÏÐÅÏ¢¡£

ÒýÓÃ:
$ cat /proc//status
VmPeak: 3141876 kB
VmSize: 3141876 kB
VmLck: 0 kB
VmHWM: 12556 kB
VmRSS: 12556 kB
VmData: 3140564 kB
VmStk: 88 kB
VmExe: 4 kB
VmLib: 1204 kB
VmPTE: 3072 kB


ÕâÊÇÔÚB±»É±Ö®Ç°µÄ¼Ç¼£º

ÒýÓÃ:
$ cat /proc//status
VmPeak: 1072512 kB
VmSize: 1072512 kB
VmLck: 0 kB
VmHWM: 234636 kB
VmRSS: 204692 kB
VmData: 1071200 kB
VmStk: 88 kB
VmExe: 4 kB
VmLib: 1204 kB
VmPTE: 1064 kB


VmRSSÐèÒªÔÙÏêϸµã½âÊÍ¡£RSSÊÇResident Set Size£¬Ò²¾ÍÊǵ±Ç°½ø³ÌÔÚÄÚ´æÖзÖÅäµÄ¿é¡£Ò²×¢Ò⣬ÔÚBµ½OOM֮ǰÒѾ­ÓõôÁ˼¸ºõÈ«²¿½»»»·ÖÇø£¬¶øA¸ù±¾Ã»Ó᣺ÜÃ÷ÏÔmalloc()³ýÁ˱£ÁôÄÚ´æÖ®ÍâʲôҲû×ö¡£

ÁíÍâÒ»¸öÎÊÌâÊÇ£º¼ÈȻûÓÐдҳ£¬ÎªÊ²Ã´ÓÐ3056MÕâ¸öÉÏÏÞ£¿ÕⱩ¶³öÁíÍâÒ»¸öÏÞÖÆ¡£ÔÚ32λϵͳÉÏ£¬ÄÚ´æµØÖ·ÓÐ4GB¡£ÆäÖÐ0£­3GBÊÇÓû§Ê¹Óã¬3£­4GBΪÄں˿ռ䡣

×¢Ò⣺ÓÐÄں˲¹¶¡¿ÉÒÔʵÏÖÈ«²¿·ÖÅä4GB¸øÓû§¿Õ¼ä£¬ÐèҪһЩÉÏÏÂÎÄÇл»µÄ¿ªÏú¡£OOMµÄ½áÂÛ£º

VMÖÐûÓпÉÓÃÒ³¡£
ûÓÐ×ã¹»µÄÓû§µØÖ·¿Õ¼ä¡£
ÒÔÉÏÁ½Õß¡£

ÁíÍ⣬ÔÚlinux »·¾³Ï£¬ÓÃmalloc·ÖÅäµÄÄÚ´æ¿Õ¼ä»á±È¿É¼ûµÄfree memoryÒª´ó£¨¼ûÏÂÀý£¬malloc size =0x7d000000 > MemFree: 1762136 kB£©£¬Ò²ÊÇÒòΪ½»»»¿Õ¼äswap´æÔÚÔì³ÉµÄ¡£¶øǶÈëʽµ¥°åÉÏûÓÐswapÇø£¬¾Í²»»á³öÏÖÕâ¸öÇé¿ö¡£

ÒýÓÃ:
[wind@fw-csvr mpc8313]$ cat /proc/meminfo

MemTotal: 2074844 kB

MemFree: 1762136 kB

Buffers: 21764 kB

Cached: 229040 kB

SwapCached: 23016 kB

Active: 236684 kB

Inactive: 38376 kB


[wind@fw-csvr mpc8313]$ ./mpc8313_mem_mini

Now doing DDR SDRAM test, please wait............

diagSDRAMSub[88] : malloc size =0x7d000000, addr = 0x3a5db008!

ddrMemDiag[53]: test size = 2000MB! time = 118s


swap½»»»ÇøµÄ֪ʶ²Î¼û£º¡¶½Ò¿ªLinuxϵͳSwap½»»»ÇøÖ®ÃÕ¡·
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ