½â¾öLinuxϵͳÄÚ´æËéƬÎÊÌâµÄÒªÁì
linuxϵͳÖг£¼ûµÄÄÚ´æËéƬÎÊÌâ¼°Æä½â¾öÒªÁì
ÈôÊÇÄãÊÇÒ»¸öʹÓÃLinux²Ù×÷ϵͳµÄÓû§£¬Äã¿ÉÄÜ»áÔÚʹÓÃÀú³ÌÖÐÓöµ½Ò»Ð©ÄÚ´æÖÎÀí·½ÃæµÄÎÊÌâ¡£ÆäÖУ¬ÄÚ´æËéƬÎÊÌâÊÇÒ»¸ö½ÏÁ¿³£¼ûµÄÎÊÌ⣬Ëü»áµ¼ÖÂϵͳÐÔÄÜϽµÒÔ¼°ÄÚ´æ×ÊÔ´µÄÆÌÕÅ¡£±¾ÎĽ«Ì½ÌÖLinuxϵͳÖг£¼ûµÄÄÚ´æËéƬÎÊÌ⣬²¢ÌṩһЩ½â¾öÒªÁì¡£
Ê×ÏÈ£¬ÈÃÎÒÃÇÏÈÏàʶһÏÂʲôÊÇÄÚ´æËéƬ¡£ÔÚLinuxϵͳÖУ¬ÄÚ´æÊÇÒÔÒ³µÄÐÎʽ¾ÙÐÐÖÎÀíµÄ¡£µ±³ÌÐòÉêÇëÄÚ´æʱ£¬ÏµÍ³»á½«ÄÚ´æ·ÖÅÉΪһϵÁеÄÒ³£¬²¢¼Í¼ÿ¸öÒ³µÄʹÓÃ״̬¡£ÄÚ´æËéƬÊÇÖ¸µ±Óдó×ÚµÄС¿éÄÚ´æÊèÉ¢ÔÚ¸÷¸ö·ÖÒ³ÖУ¬¶øûÓÐ×ã¹»µÄÒ»Á¬µÄ¿Õ¼äÀ´Öª×ã´ó¿éÄÚ´æµÄÉêÇë¡£ÕâÑù¾Í»áµ¼ÖÂϵͳÎÞ·¨ÓÐÓõØʹÓÃÄڴ棬´Ó¶øÓ°ÏìϵͳÐÔÄÜ¡£
ÄÚ´æËéƬÎÊÌâ¿ÉÒÔ·ÖΪÁ½ÖÖÀàÐÍ£ºÍⲿËéƬºÍÄÚ²¿ËéƬ¡£ÍⲿËéƬÊÇÖ¸´ó×ÚµÄС¿éÄÚ´æÉ¢²¼ÔÚ¸÷¸ö·ÖÒ³ÖУ¬µ¼ÖÂûÓÐ×ã¹»µÄÒ»Á¬¿Õ¼äÀ´Öª×ã´ó¿éÄÚ´æµÄÉêÇë¡£ÄÚ²¿ËéƬÊÇÖ¸ÔÚÿ¸öÒ³ÖÐÓÐһЩδ±»Ê¹ÓõIJ¿·Ö£¬µ¼ÖÂÄÚ´æ×ÊÔ´µÄÆÌÕÅ¡£ÏÂÃæÎÒÃǽ«»®·ÖÏÈÈÝÕâÁ½ÖÖÄÚ´æËéƬÎÊÌâµÄ½â¾öÒªÁì¡£
¹ØÓÚÍⲿËéƬÎÊÌ⣬ÎÒÃÇ¿ÉÒÔͨ¹ýÄÚ´æËõ¶ÌÀ´½â¾ö¡£ÄÚ´æËõ¶ÌÊÇÖ¸½«¸÷¸ö·ÖÒ³ÖеÄÄÚ´æÖØÐÂ×éÖ¯£¬ÒÔ½¨Éè¸ü´óµÄÒ»Á¬ÄÚ´æ¿éÀ´Öª×ã´ó¿éÄÚ´æµÄÉêÇë¡£LinuxϵͳÌṩÁËÒ»¸öÃûΪ”compaction”µÄ»úÖÆ£¬ÓÃÓÚÄÚ´æËõ¶Ì¡£Í¨¹ýÖ´ÐÐÈçÏÂÏÂÁ¿ÉÒÔÊÖ¶¯´¥·¢ÄÚ´æËõ¶Ì£º
echo 1 > /proc/sys/vm/compact_memory
µÇ¼ºó¸´ÖÆ
±ðµÄ£¬»¹¿ÉÒÔ½«ÄÚ´æËõ¶ÌÉèÖÃΪ×Ô¶¯¾ÙÐС£Í¨¹ýÔËÐÐÈçÏÂÏÂÁ¿ÉÒÔ½«ÄÚ´æËõ¶ÌÉèÖÃΪ×Ô¶¯Ä£Ê½£º
echo 1 > /proc/sys/vm/compact_automatically
µÇ¼ºó¸´ÖÆ
¹ØÓÚÄÚ²¿ËéƬÎÊÌ⣬ÎÒÃÇ¿ÉÒÔͨ¹ýʹÓÃÄÚ´æ·ÖÅÉÆ÷À´½â¾ö¡£ÄÚ´æ·ÖÅÉÆ÷ÊÇÓÃÓÚÖÎÀíϵͳÖеÄÄÚ´æ·ÖÅɺÍÊͷŵŤ¾ß¡£ÔÚLinuxϵͳÖУ¬glibc¿âÌṩÁËÒ»¸öÃûΪmallocµÄÄÚ´æ·ÖÅÉÆ÷¡£È»¶ø£¬glibc¿âµÄmallocÄÚ´æ·ÖÅÉÆ÷ÔÚ´¦ÀíС¿éÄÚ´æʱ¿ÉÄܻᱬ·¢½Ï´óµÄÄÚ²¿ËéƬ¡£ÎªÏàʶ¾öÕâ¸öÎÊÌ⣬ÎÒÃÇ¿ÉÒÔʹÓÃÆäËûÄÚ´æ·ÖÅÉÆ÷£¬Èçjemalloc¡¢tcmallocµÈ£¬ËüÃǶÔÄÚ²¿ËéƬµÄ´¦ÀíЧ¹û¸üºÃ¡£
ÎÒÃÇ¿ÉÒÔͨ¹ý½«ÄÚ´æ·ÖÅÉÆ÷ÉèÖÃΪjemallocÀ´½â¾öÄÚ²¿ËéƬÎÊÌâ¡£¿ÉÒÔͨ¹ýÔÚ³ÌÐòÔËÐÐ֮ǰÉèÖÃÇéÐαäÁ¿À´ÆôÓÃjemalloc£º
export LD_PRELOAD=/usr/lib/libjemalloc.so
µÇ¼ºó¸´ÖÆ
±ðµÄ£¬»¹¿ÉÒÔͨ¹ýÉèÖÃÇéÐαäÁ¿MALLOC_CONFÀ´ÓÅ»¯jemallocµÄÐÐΪ£º
export MALLOC_CONF=oversize_threshold:32,background_thread:true
µÇ¼ºó¸´ÖÆ
Õ⽫ʹjemallocÔÚÁè¼Ý32×Ö½ÚµÄÄÚ´æ¿éÉÏʹÓúǫ́Ị̈߳¬ÒÔïÔÌÄÚ´æËéƬ¡£
³ýÁËʹÓÃjemallocÍ⣬»¹¿ÉÒÔʵÑéʹÓÃtcmallocµÈÆäËûÄÚ´æ·ÖÅÉÆ÷À´½â¾öÄÚ²¿ËéƬÎÊÌâ¡£ÕâЩÄÚ´æ·ÖÅÉÆ÷ͨ³£ÓиüºÃµÄÄÚ´æÖÎÀíÄÜÁ¦£¬Äܹ»¸üºÃµØ´¦ÀíÄÚ´æËéƬÎÊÌâ¡£
×ÛÉÏËùÊö£¬LinuxϵͳÖеÄÄÚ´æËéƬÎÊÌâÊÇÒ»¸ö³£¼ûµÄÎÊÌ⣬µ«¿ÉÒÔͨ¹ýһЩҪÁìÀ´½â¾ö¡£Í¨¹ýʹÓÃÄÚ´æËõ¶ÌºÍÓÅ»¯ÄÚ´æ·ÖÅÉÆ÷£¬ÎÒÃÇ¿ÉÒÔÓÐÓõØïÔÌÄÚ´æËéƬÎÊÌâ´øÀ´µÄ¸ºÃæÓ°Ï죬Ìá¸ßϵͳµÄÐÔÄܺÍÄÚ´æʹÓÃÂÊ¡£
ÒÔÉϾÍÊǽâ¾öLinuxϵͳÄÚ´æËéƬÎÊÌâµÄÒªÁìµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡