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

ÓÅ»¯linux ÐÔÄÜ

·¢²¼Ê±¼ä:2005-05-13 00:16:16À´Ô´:ºìÁª×÷Õß:ÐÂÐÂ
ʹÓÃhdparm¸ÄÉÆLinuxϵͳÐÔÄÜ

Èç¹ûÄãµÄLinuxϵͳÔËÐÐÓÚIDEÓ²ÅÌ£¬¿ÉÒÔʹÓÃhdparm¹¤¾ßÀ´Ìá¸ß´ÅÅÌI/OµÄÐÔÄÜ¡£²»¹ýʹÓÃhdparmҪСÐÄ£¬ÒòΪ¿ÉÄÜÆÆ»µÓ²ÅÌÉϵÄÊý ¾Ý¡£ËùÒÔÔÚʹÓÃhdparm֮ǰ£¬×ÐϸÔĶÁÄãµÄÓ²ÅÌÊֲᡣ¸ù¾ÝÄã¾ßÌåµÄÓ²Å̹æ¸ñÀ´Ê¹ÓÃÏàÓ¦µÄhdparm¿ª¹Ø²ÎÊý¡£¶ÔÒ»¿éUltraATA/66 EIDE Ó²ÅÌ£¬Æä¿ØÖÆоƬ֧³Ö¶à PIO ģʽºÍDMA£¬ÎÒÃÇʹÓÃÒÔÏÂÃüÁîÀ´µ÷г´ÅÅÌÐÔÄÜ£º


# /sbin/hdparm -x66 -d1 -u1 -m16 -c3 /dev/hda



Ñ¡Ïî˵Ã÷£º


¢Ù c3 £º¾ÍÊÇ°ÑÓ²Å̵Ä16λ¸ñʽת»»Îª32λģʽ£¨32-bit mode w/sync£©¡£¿ØÖÆÊý¾ÝÈçºÎ´Ópci×ÜÏß´«µÝµ½¿ØÖÆÆ÷¡£
¢Ú m16 £º¸Ä±äÓ²Å̵Ķà·ÉÈÇøµÄ¶Á¹¦ÄÜ£¬-m16¿ÉÒÔʹµÃÓ²ÅÌÔÚÒ»´Îi/oÖжÏÖжÁÈë16¸öÉÈÇøµÄÊý¾Ý£¨¾Ý¾ßÌåÓ²Å̶ø¶¨£©¡£
¢Û d1£º´ò¿ªDMAģʽ¡£
¢Ü x66 £ºÔÚÖ§³ÖUDMA-capableµÄÓ²ÅÌÖУ¬Õâ¸ö²ÎÊý¿ÉÒÔÖ§³ÖË«DMAͨµÀµÄÊý¾Ý´«Êäģʽ¡£
¢Ý u1 £ºLinuxÔÚ´¦Àí´ÅÅÌÖжÏʱ£¬¿ÉÒÔunmaskÆäËûµÄÖжϻòÕßÏìÓ¦ÆäËûÖжÏÏà¹ØµÄÈÎÎñ¡£

¡¡¡¡

²é¿´ÒÔÉϵĸü¸ÄÇé¿ö¿ÉÒÔʹÓÃÃüÁ


# /sbin/hdparm /dev/hda



²âÊÔ´ÅÅÌI/OÐÔÄÜ¿ÉÒÔʹÓÃÃüÁ


# /sbin/hdparm -tT /dev/hda



Èç¹û´ÅÅ̵ÄÐÔÄÜÓиĽøµÄ»°£¬¿ÉÒÔʹÓÃÒÔÏÂÃüÁîÀ´±£´æÉèÖãº


# /sbin/hdparm -k1 /dev/hda



2.3 LinuxÏÂʹÓÃÈíRAID



RAID£¨´ÅÅÌÈßÓàÕóÁУ©ÊÇͨ¹ý½«Êý¾Ý·Ö²¼ÔÚ¶à¸ö´ÅÅÌÉÏÀ´ÔöÇ¿´ÅÅÌÐÔÄܺͿɿ¿ÐԵļ¼Êõ¡£Èç¹ûÄãµÄϵͳûÓÐÓ²¼þRAID¿ØÖÆÆ÷µÄ»°£¬ÔÚLinuxÏÂ¿É ÒÔͨ¹ýÈí¼þÀ´ÊµÏÖRAID¡£RAIDµÄÓкܶàµÄ¼¶±ð£¬²»Í¬µÄ¼¶±ð¶ÔÓ²¼þÓв»Í¬µÄÒªÇó£¬ÏàÓ¦Ò²»áµÃµ½²»Í¬µÄÐÔÄܺͿɿ¿ÐÔ¡£RAID0ΪÊý¾Ý·Ö¸î£¬Êý¾Ý¿é±»½» Ìæдµ½´ÅÅÌ£¬¿ÉÒԵõ½×îºÃµÄ¶ÁдÐÔÄÜ£¬µ«ÊDz»ÌṩÊý¾ÝÈßÓà¡£RAID1Ϊ´ÅÅ̾µÏñ£¬Ð´µ½´ÅÅÌ1ÖеÄÒ»ÇÐҲдµ½´ÅÅÌ2ÖУ¬´ÓÈκÎÒ»¸ö´ÅÅ̶¼¿ÉÒÔ¶ÁÈ¡¡£ RAID3³ýÁËÊý¾Ý·Ö¸îÖ®Í⣬»¹Ö¸¶¨Ò»¸ö´ÅÅÌÇý¶¯Æ÷À´´æ´¢ÆæżÐÅÏ¢¡£



ÔÚLINUXÏÂͨ¹ýÈí¼þÀ´ÊµÏÖRAID£¬ ÐèÒªLINUXµÄÄÚºËÖ§³Ö£¬¿ÉÒÔͨ¹ý±àÒëÐÂÄÚºËÀ´Ìí¼Ó¶ÔRAIDµÄÖ§³Ö¡£È»ºó»¹Ðè±àÒë²¢°²×° raidtools Èí¼þ°ü¡£raidtools ÊÇ¿ÉÒÔ³õʼ»¯¡¢Æô¶¯¡¢Í£Ö¹¼°¿ØÖÆ RAID ÕóÁеÄÓû§¼¶¹¤¾ß¡£ÏÂÃæÊÇÎÒÃÇÓÃÁ½¿éIDEÓ²ÅÌÔÚLINUXÄÚºË2.4ÉÏʵÏÖRAID0µÄ·½·¨¡£



ÉèÖ÷ÖÇø ʹÓÃRAID0ÖÁÉÙÐèÒªÁ½¸ö·ÖÇø£¬ËüÃÇλÓÚ²»Í¬µÄ´ÅÅÌ¡£×îºÃ×öRAID0µÄÁ½¸ö·ÖÇøÓÐÏàͬµÄ´óС¡£´´½¨·ÖÇøʱ£¬½«·ÖÇøÀàÐÍÖ¸¶¨Îª "FD"¡£ÒÔʹ Linux ÄÚºËÄܽ«ËüÃÇʶ±ðΪ RAID ·ÖÇø£¬ÕâÑù£¬ÕâЩ·ÖÇø¾Í¿ÉÔÚÿ´ÎÒýµ¼Ê±×Ô¶¯±»¼ì²â²¢Æô¶¯¡£Èç¹ûÄúûÓÐÒÔÕâÖÖ·½Ê½±ê¼Ç RAID ·ÖÇø£¬ÔòÔÚÿ´ÎÒýµ¼Ö®ºó£¬±ØÐëÊ×ÏÈÊäÈë "raidstart all" ²ÅÄܹÒÔØ RAID ÕóÁС£ÎÒÃÇ×ö³ÉRAID0µÄÁ½¸ö·ÖÇøΪhda5ºÍhdc5¡£



±à¼­/etc/raidtabÎļþ ´´½¨/etc/raidtabÎļþÒÔÃèÊöRAIDÕóÁеÄÅäÖÃÐÅÏ¢¡£Linux ÄÚºËʹÓÃÕâЩÐÅÏ¢ÔÚÒýµ¼Ê±×Ô¶¯¼ì²â²¢Æô¶¯ RAID ÕóÁУ¬Òò´Ë±ØÐë¶Ô´´½¨µÄÿ¸ö RAID ÕóÁнøÐÐÕâÖÖÅäÖ᣽«·ÖÇøhda5ºÍhdc5×é³Émd0 RAID0ÕóÁеÄÅäÖÃÎļþÈçÏ£º




raiddev /dev/md0
raid-level 0
nr-raid-disks 2
persistent-superblock 1
chunk-size 32
device /dev/hda5
raid-disk 0
device /dev/hdc5
raid-disk 1



ͼ£¨Èý£© raidtabÎļþ

ÔÚraidtabÎļþÖУ¬ "raiddev" ÌõÄ¿Ö¸Ã÷Òª´´½¨µÄ RAID ÕóÁУ»"nr-raid-disks" Ö¸¶¨ÕóÁÐÖеĴÅÅÌÊýÄ¿£»"persistent-superblock" ÉèÖÃΪ 1£¬¸æËß raid ¹¤¾ßºÎʱ´´½¨¸Ã¾í£»"chunk-size" ÒÔK×Ö½ÚÖ¸¶¨ RAID0 ʹÓõĿé´óС£»×îºó£¬ÒªÖ¸¶¨µÄÊÇ×é³É¸ÃÕóÁеÄÉ豸¼´·ÖÇø¡£



mkraid ºÍ´´½¨Îļþϵͳ ʹÓÃÃüÁî"# mkraid /dev/md0" ÃüÁî³õʼ»¯/dev/md0·ÖÇø£¬Í¬Ê±½«Æô¶¯md0 RAID0ÕóÁС£½ÓÏÂÀ´£¬¼´¿ÉÔÚmd0ÉÏ´´½¨ÄãÏëÒªµÃÎļþϵͳ¡£ÎÒÃÇÔÚLinux·þÎñÆ÷ÉÏʹÓõÄÊÇReiserfsÈÕÖ¾Îļþϵͳ£¬´´½¨µÄÃüÁîΪ"# mkreiserfs /dev/md0"¡£



ÕâÑù£¬¾Í¿ÉÒÔÏñÆäËüÎļþϵͳÄÇÑùÀ´¼ÓÔØд´½¨µÄ»ùÓÚRAID0µÄÎļþϵͳÁË¡£



2.4 ʹÓÃelvtuneµ÷г´ÅÅÌI/O



ÔÚLinuxÄÚºË 2.4ÒÔºóµÄ°æ±¾ÖУ¬¿ÉÒÔͨ¹ý´ÅÅÌI/OµÄµ÷¶È²Ù×÷£¬À´¿ØÖÆ´ÅÅÌI/OµÄÏìӦʱ¼äºÍÍÌÍÂÁ¿¡£Í¨¹ýµ÷ÕûI/OÇëÇóÔÚ¶ÓÁÐÖеÄ×î´óµÈ´ýʱ¼ä£¬¿ÉÒÔÔÚÏìӦʱ¼äºÍ ÍÌÍÂÁ¿Ö®¼äµ÷г¡£Èç¹ûÒªÇó½ÏÉÙµÄÏìӦʱ¼ä£¬ÄÇôÍÌÍÂÁ¿½«½µµÍ£¬·´Ö®£¬½Ï³¤µÄÏìӦʱ¼äÔò¿ÉÒԵõ½½Ï´óµÄÍÌÍÂÁ¿¡£¿ÉÒÔʹÓù¤¾ß"/sbin/elvtune" À´¸Ä±ä×î´óµÄÏìӦʱ¼äÖµ¡£Ê¹Ó÷½·¨ÈçÏ£º



²é¿´µ±Ç°µÄÉèÖÃ


# /sbin/elvtune /dev/hda1



Ð޸ĵ±Ç°µÄÅäÖÃ


# /sbin/elvtune -r 2000 -w 4000 /dev/hda1



ÆäÖÐ-r²ÎÊýÕë¶Ô¶Á²Ù×÷£¬-w²ÎÊýÕë¶Ôд²Ù×÷.



¿É ÒÔͨ¹ýÃüÁî"iostat -d -x /dev/hda1"µÃµ½µÄƽ¾ùÐÅÏ¢£¨°üÀ¨Æ½¾ùÇëÇó´óСºÍƽ¾ù¶ÓÁг¤¶È£©À´¼àÊÓÒÔÉÏI/OÅäÖõÄЧ¹û£¬²¢µ÷ÕûÅäÖã¬ÒԵõ½×î¼ÑµÄÐÔÄÜ¡£Ò»°ãÀ´½²£¬¶ÔÓÚ¶Áд Ƶ·±£¬µ«²Ù×÷µÄÊý¾ÝÁ¿½ÏÉÙµÄLinux·þÎñÆ÷£¬ÇÒ¶ÔʵʱÐÔÒªÇó½Ï¸ß£¬ÄÇô¿ÉÒÔ½«²ÎÊýµ÷С¡£·´Ö®Èç¹û¶ÔÓÚ¶Áд²»Æµ·±£¬µ«ÒªÇó¾ßÓнϴóµÄÍÌÍÂÁ¿µÄLinux·þ ÎñÆ÷£¬¿ÉÒÔ½«²ÎÊýµ÷´ó£¬ÒÔ»ñµÃ½Ï´óµÄÍÌÍÂÁ¿¡£



3£® Îļþ¼°Îļþϵͳµ÷г



3.1 ¿é´óС



´´½¨Îļþϵͳʱ£¬¿ÉÒÔÖ¸¶¨¿éµÄ´óС¡£Èç¹û½«À´ÔÚÄãµÄÎļþϵͳÖÐÊÇһЩ±È½Ï´óµÄÎļþµÄ»°£¬Ê¹ÓýϴóµÄ¿é´óС½«µÃµ½½ÏºÃµÄÐÔÄÜ¡£½«ext2ÎļþϵͳµÄ¿é ´óСµ÷ÕûΪ4096byte¶ø²»ÊÇȱʡµÄ1024byte£¬¿ÉÒÔ¼õÉÙÎļþËéƬ£¬¼Ó¿ìfsckɨÃèµÄËٶȺÍÎļþɾ³ýÒÔ¼°¶Á²Ù×÷µÄËٶȡ£ÁíÍ⣬ÔÚext2µÄÎÄ ¼þϵͳÖУ¬Îª¸ùĿ¼±£ÁôÁË5%µÄ¿Õ¼ä£¬¶ÔÒ»¸ö´óµÄÎļþϵͳ£¬³ý·ÇÓÃ×÷ÈÕÖ¾Îļþ£¬5%µÄ±ÈÀýÓÐЩ¹ý¶à¡£¿ÉÒÔʹÓÃÃüÁî"# mke2fs -b 4096 -m 1 /dev/hda6"½«Ëü¸ÄΪ1%²¢ÒÔ¿é´óС4096byte´´½¨Îļþϵͳ¡£



ʹÓöà´óµÄ¿é´óС£¬ÐèÒª¸ù¾ÝÄãµÄϵͳ×ۺϿ¼ÂÇ£¬Èç¹ûϵͳÓÃ×÷Óʼþ»òÕßÐÂÎÅ·þÎñÆ÷£¬Ê¹ÓýϴóµÄ¿é´óС£¬ËäÈ»ÐÔÄÜÓÐËùÌá¸ß£¬µ«»áÔì³É´ÅÅÌ¿Õ¼ä½Ï´óµÄÀË ·Ñ¡£±ÈÈçÎļþϵͳÖеÄÎļþƽ¾ù´óСΪ2145byte£¬Èç¹ûʹÓÃ4096byteµÄ¿é´óС£¬Æ½¾ùÿһ¸öÎļþ¾Í»áÀË·Ñ1951byte¿Õ¼ä¡£Èç¹ûʹÓà 1024byteµÄ¿é´óС£¬Æ½¾ùÿһ¸öÎļþ»áÀË·Ñ927byte¿Õ¼ä¡£ÔÚÐÔÄܺʹÅÅ̵Ĵú¼ÛÉÏÈçºÎƽºâ£¬Òª¿´¾ßÌåÓ¦ÓõÄÐèÒª¡£



3.2 ²»Ê¹ÓÃatimeÊôÐÔ



µ±Îļþ±»´´½¨£¬Ð޸ĺͷÃÎÊʱ£¬ Linuxϵͳ»á¼Ç¼ÕâЩʱ¼äÐÅÏ¢¡£¼Ç¼Îļþ×î½üÒ»´Î±»¶ÁÈ¡µÄʱ¼äÐÅÏ¢£¬µ±ÏµÍ³µÄ¶ÁÎļþ²Ù×÷Ƶ·±Ê±£¬½«ÊÇÒ»±Ê²»ÉٵĿªÏú¡£ËùÒÔ£¬ÎªÁËÌá¸ßϵͳµÄÐÔÄÜ£¬ÎÒÃÇ ¿ÉÒÔÔÚ¶ÁÈ¡Îļþʱ²»ÐÞ¸ÄÎļþµÄatimeÊôÐÔ¡£¿ÉÒÔͨ¹ýÔÚ¼ÓÔØÎļþϵͳʱʹÓÃnotimeÑ¡ÏîÀ´×öµ½ÕâÒ»µã¡£µ±ÒÔnoatimeÑ¡Ïî¼ÓÔØ£¨mount£©ÎÄ ¼þϵͳʱ£¬¶ÔÎļþµÄ¶ÁÈ¡²»»á¸üÐÂÎļþÊôÐÔÖеÄatimeÐÅÏ¢¡£ÉèÖÃnoatimeµÄÖØÒªÐÔÊÇÏû³ýÁËÎļþϵͳ¶ÔÎļþµÄд²Ù×÷£¬ÎļþÖ»ÊǼòµ¥µØ±»ÏµÍ³¶ÁÈ¡¡£ÓÉ ÓÚд²Ù×÷Ïà¶Ô¶ÁÀ´ËµÒª¸üÏûºÄϵͳ×ÊÔ´£¬ËùÒÔÕâÑùÉèÖÿÉÒÔÃ÷ÏÔÌá¸ß·þÎñÆ÷µÄÐÔÄÜ¡£×¢ÒâwtimeÐÅÏ¢ÈÔÈ»ÓÐЧ£¬ÈκÎʱºòÎļþ±»Ð´£¬¸ÃÐÅÏ¢ÈÔ±»¸üС£



±ÈÈçÔÚÄãµÄϵͳÖУ¬ÒªÎª/homeÎļþϵͳÉèÖÃnotimeÑ¡Ï¿ÉÒÔÐÞ¸Ä/etc/fstabÎļþÏàÓ¦µÄÐÐÈçÏ£º




LABEL=/home /home ext2 noatime 1 2



Ҫʹ¸ÃÉèÖÃÁ¢¼´ÉúЧ£¬¿ÉÔËÐÐÃüÁî"#mount -oremount /home"¡£ÕâÑùÒÔºóϵͳ¶ÁÈ¡/homeϵÄÎÄ ¼þʱ½«²»»áÔÙÐÞ¸ÄatimeÊôÐÔ¡£



3.3 µ÷Õû»º³åÇøˢвÎÊý



LinuxÄÚºËÖУ¬°üº¬ÁËһЩ¶ÔÓÚϵͳÔËÐÐ̬µÄ¿ÉÉèÖòÎÊý¡£»º³åˢеIJÎÊý¿ÉÒÔͨ¹ýµ÷Õû /proc/sys/vm/bdflushÎļþÀ´Íê³É£¬Õâ¸öÎļþµÄ¸ñʽÊÇÕâÑùµÄ£º


# cat /proc/sys/vm/bdflush
30 64 64 256 500 3000 60 0 0



ÿһÀ¸ÊÇÒ»¸ö²ÎÊý£¬ÆäÖÐ×îÖØÒªµÄÊÇÇ°Ã漸¸ö²ÎÊý¡£µÚÒ»¸öÊý×ÖÊÇÔÚ"dirty"»º³åÇø ´ïµ½¶àÉÙµÄʱºòÇ¿ÖÆ»½ÐÑbdflush½ø³ÌË¢ÐÂÓ²ÅÌ£¬µÚ¶þ¸öÊý×ÖÊÇÿ´ÎÈÃbdflush½ø³ÌˢР¶àÉÙ¸ödirty¿é¡£Ëùνdirty¿éÊDZØÐëдµ½´ÅÅÌÖеĻº´æ¿é¡£½ÓÏÂÀ´µÄ²ÎÊýÊÇÿ´ÎÔÊÐíbd flush½«¶àÉÙ¸öÄÚ´æ¿éÅÅÈë¿ÕÏеĻº³å¿éÁÐ±í¡£ ÒÔÉÏֵΪRedHat Linux 7.1ÖеÄȱʡֵ¡£ÈçºÎÐÞ¸ÄËüÃÇÄØ£¿¶Ô²»Í¬µÄϵͳÓÐÒÔÏÂÁ½ÖÖ·½·¨


£¨1£©# echo "100 128 128 512 5000 3000 60 0 0">/proc/sys/vm/bdflush ²¢½«ÕâÌõÃüÁî¼Óµ½/etc/rc.d/rc.localÎļþÖÐÈ¥¡£
£¨2£©ÔÚ/etc/sysctl.conf ÎļþÖмÓÈëÈçÏÂÐÐ: vm.bdflush = 100 128 128 512 5000 3000 60 0 0

ÒÔÉϵÄÉèÖüӴóÁË»º³åÇø´óС£¬½µµÍÁËbdflush±»Æô¶¯µÄƵ¶È£¬Í¬Ê±Ò²Ôö¼ÓÁËÍòһϵͳ±ÀÀ£¶ªÊ§Êý¾ÝµÄΣÏÕÐÔ¡£VFSµÄ»º³åË¢ÐÂÊÇLinuxÎļþϵͳ¸ßЧµÄÖØÒªÔ­ÒòÖ®Ò»£¬Èç¹ûÐÔÄܶÔÄãÕæµÄºÜÖØÒª£¬Ó¦¸Ã¿¼Âǵ÷ÕûÕâ¸ö²ÎÊý¡£



3.4 µ÷ÕûÎļþ¾ä±úÊýºÍi-½ÚµãÊý



ÔÚÒ»¸ö´óÐ͵ÄÍøÕ¾·þÎñÆ÷ÆäÖУ¬¿ÉÄÜLinuxĬÈϵÄͬʱ¿É´ò¿ª×î´óÎļþÊý²»ÄÜÂú×ãϵͳÐèÒª£¬ÎÒÃÇ¿ÉÒÔͨ¹ýµ÷ÕûÎļþ¾ä±úÊýºÍi-½ÚµãÊýÀ´Ôö¼ÓϵͳµÄȱʡµÄÏÞÖÆ¡£²»Í¬µÄLinuxÄں˰汾Óв»Í¬µÄµ÷Õû·½·¨¡£



ÔÚLinuxÄÚºË2.2.xÖпÉÒÔÓÃÈçÏÂÃüÁîÐ޸ģº


# echo ´8192´ > /proc/sys/fs/file-max
# echo ´32768´ > /proc/sys/fs/inode-max


²¢½«ÒÔÉÏÃüÁî¼Óµ½/etc/rc.c/rc.localÎļþÖУ¬ÒÔʹϵͳÿ´ÎÖØÐÂÆô¶¯Ê±ÅäÖÃÒÔÉÏÖµ¡£



ÔÚLinuxÄÚºË2.4.xÖÐÐèÒªÐÞ¸ÄÔ´´úÂ룬ȻºóÖØбàÒëÄں˲ÅÉúЧ¡£±à¼­LinuxÄÚºËÔ´´úÂëÖÐµÄ include/linux/fs.hÎļþ£¬½« NR_FILE ÓÉ8192¸ÄΪ 65536£¬½«NR_RESERVED_FILES ÓÉ10 ¸ÄΪ 128¡£±à¼­fs/inode.c Îļþ½« MAX_INODE ÓÉ16384¸ÄΪ262144¡£



Ò»°ãÇé¿öÏ£¬×î´ó´ò¿ªÎļþÊý±È½ÏºÏÀíµÄÉèÖÃΪÿ4MÎïÀíÄÚ´æ256£¬±ÈÈç256MÄÚ´æ¿ÉÒÔÉèΪ16384£¬¶ø×î´óµÄʹÓõÄi½ÚµãµÄÊýÄ¿Ó¦¸ÃÊÇ×î´ó´ò¿ªÎļþÊýÄ¿µÄ3±¶µ½4±¶¡£



3.5 ʹÓÃÄÚ´æÎļþϵͳ



ÔÚLinuxÖпÉÒÔ½«Ò»²¿·ÖÄÚ´æµ±×÷·ÖÇøÀ´Ê¹Óã¬ÎÒÃdzÆ֮ΪRamDisk¡£¶ÔÓÚһЩ¾­³£±»·ÃÎʵÄÎļþ£¬¶øËüÃÇÓÖ²»»á±»¸ü¸Ä£¬¿ÉÒÔ½«ËüÃÇͨ¹ý RamDisk·ÅÔÚÄÚ´æÖУ¬¼´¿ÉÃ÷ÏÔµØÌá¸ßϵͳµÄÐÔÄÜ¡£µ±È»ÄãµÄÄÚ´æ¿ÉÒª×ã¹»´óÁË¡£RamDiskÓÐÁ½ÖÖ£¬Ò»ÖÖ¿ÉÒÔ¸ñʽ»¯£¬¼ÓÔØ£¬ÔÚLinuxÄÚºË 2.0/2.2¾ÍÒѾ­Ö§³Ö£¬Æä²»×ãÖ®´¦ÊÇ´óС¹Ì¶¨¡£ÁíÒ»ÖÖÊÇÄÚºË2.4²ÅÖ§³ÖµÄ£¬Í¨¹ýRamfs»òÕßtmpfsÀ´ÊµÏÖ£¬ËüÃDz»Äܱ»¸ñʽ»¯£¬µ«ÊÇÓÃÆðÀ´Áé »î£¬Æä´óСËæËùÐèÒªµÄ¿Õ¼ä¶øÔö¼Ó»ò¼õÉÙ¡£ÕâÀïÖ÷Òª½éÉÜÒ»ÏÂRamfsºÍTmpfs¡£



Ramfs¹ËÃû˼ÒåÊÇÄÚ´æÎļþϵͳ£¬Ëü¹¤×÷ÓÚÐéÄâÎļþϵͳ£¨VFS£©²ã¡£²»Äܸñʽ»¯£¬¿ÉÒÔ´´½¨¶à¸ö£¬ÔÚ´´½¨Ê±¿ÉÒÔÖ¸¶¨Æä×î´óÄÜʹÓõÄÄÚ´æ´óС¡£Èç¹ûÄãµÄLinuxÒѾ­½«Ramfs±àÒë½øÄںˣ¬Äã¾Í¿ÉÒÔºÜÈÝÒ×µØʹÓÃRamfsÁË¡£´´½¨Ò»¸öĿ¼£¬¼ÓÔØRamfsµ½¸ÃĿ¼¼´¿É¡£


# mkdir -p /RAM1
# mount -t ramfs none /RAM1



ȱʡÇé¿öÏ£¬Ramfs±»ÏÞÖÆ×î¶à¿ÉʹÓÃÄÚ´æ´óСµÄÒ»°ë¡£¿ÉÒÔͨ¹ýmaxsize£¨ÒÔkbyteΪµ¥Î»£©Ñ¡ÏîÀ´¸Ä±ä¡£


# mkdir -p /RAM1
# mount -t ramfs none /RAM1 -o maxsize=10000


ÒÔÉϼ´´´½¨ÁËÒ»¸öÏÞ¶¨ÁË×î´óʹÓÃÄÚ´æ´óСΪ10MµÄramdisk¡£



TmpfsÊÇÒ»¸öÐéÄâÄÚ´æÎļþϵͳ£¬Ëü²»Í¬ÓÚ´«Í³µÄÓÿéÉ豸ÐÎʽÀ´ÊµÏÖµÄramdisk£¬Ò²²»Í¬ÓÚÕë¶ÔÎïÀíÄÚ´æµÄRamfs¡£Tmpfs¿ÉÒÔʹÓÃÎï ÀíÄڴ棬Ҳ¿ÉÒÔʹÓý»»»·ÖÇø¡£ÔÚLinuxÄÚºËÖУ¬ÐéÄâÄÚ´æ×ÊÔ´ÓÉÎïÀíÄڴ棨RAM£©ºÍ½»»»·ÖÇø×é³É£¬ÕâЩ×ÊÔ´ÊÇÓÉÄÚºËÖеÄÐéÄâÄÚ´æ×ÓϵͳÀ´¸ºÔð·ÖÅäºÍ¹Ü Àí¡£Tmpfs¾ÍÊǺÍÐéÄâÄÚ´æ×ÓϵͳÀ´"´ò½»µÀ"µÄ£¬ËüÏòÐéÄâÄÚ´æ×ÓϵͳÇëÇóÒ³À´´æ´¢Îļþ£¬ËüͬLinuxµÄÆäËüÇëÇóÒ³µÄ²¿·ÖÒ»Ñù£¬²»ÖªµÀ·ÖÅä¸ø×Ô¼ºµÄÒ³ ÊÇÔÚÄÚ´æÖл¹ÊÇÔÚ½»»»·ÖÇøÖС£TmpfsͬRamfsÒ»Ñù£¬Æä´óСҲ²»Êǹ̶¨µÄ£¬¶øÊÇËæ×ÅËùÐèÒªµÄ¿Õ¼ä¶ø¶¯Ì¬µÄÔö¼õ¡£Ê¹ÓÃtmpfs£¬Ê×ÏÈÄã±àÒëÄÚºËʱµÃ Ñ¡Ôñ"ÐéÄâÄÚ´æÎļþϵͳ֧³Ö£¨Virtual memory filesystem support£©" £¬È»ºó¾Í¿ÉÒÔ¼ÓÔØtmpfsÎļþϵͳÁË¡£


# mkdir -p /mnt/tmpfs
# mount tmpfs /mnt/tmpfs -t tmpfs


ΪÁË·ÀÖ¹tmpfsʹÓùý¶àµÄÄÚ´æ×ÊÔ´¶øÔì³ÉϵͳµÄÐÔÄÜϽµ»òËÀ»ú£¬¿ÉÒÔÔÚ¼ÓÔØʱָ¶¨tmpfsÎļþϵͳ´óСµÄ×î´óÏÞÖÆ¡£


# mount tmpfs /mnt/tmpfs -t tmpfs -o size=32m



ÒÔÉÏ´´½¨µÄtmpfsÎļþϵͳ¾Í¹æ¶¨ÁËÆä×î´óµÄ´óСΪ32M¡£ ²»¹ÜÊÇʹÓÃramfs»¹ÊÇtmpfs£¬±ØÐëÃ÷°×µÄÊÇ£¬Ò»µ©ÏµÍ³ÖØÆô£¬ËüÃÇÖеÄÄÚÈݽ«»á¶ªÊ§¡£ËùÒÔÄÇЩ¶«Î÷¿ÉÒÔ·ÅÔÚÄÚ´æÎļþϵͳÖеøù¾ÝϵͳµÄ¾ßÌåÇé¿ö¶ø¶¨¡£



3.6 ʹÓÃÈÕÖ¾Îļþϵͳ



Èç¹ûLinuxϵͳÓÉÓÚÒâÍâÇé¿ö¶øûÓÐÕý³£¹Ø»ú£¬Ôò¿ÉÄÜÒýÆðÎļþϵͳÖÐijЩÎļþµÄÔªÊý¾Ý£¨meta-data¼´ºÍÎļþÓйصÄÐÅÏ¢£¬ÀýÈ磺ȨÏÞ¡¢ËùÓÐ ÕßÒÔ¼°´´½¨ºÍ·ÃÎÊʱ¼ä£©Ôâµ½ÆÆ»µ¡£ÎļþϵͳÐèҪά»¤ÎļþµÄÔªÊý¾ÝÀ´±£Ö¤ÎļþµÄ¿É×éÖ¯ºÍ¿É´æÈ¡£¬Èç¹ûÔªÊý¾Ý´¦ÓÚ²»ºÏÀí»ò²»Ò»ÖµÄ״̬£¬ÄÇô¾Í²»ÄÜ·ÃÎʺʹæÈ¡ Îļþ¡£µ±ÏµÍ³ÖØÐÂÆô¶¯Ê±£¬fsck½«É¨Ãè/etc/fstabÎļþÖÐËùÁгöµÄËùÓÐÎļþϵͳ£¬È·±£ËüÃǵÄÔªÊý¾Ý´¦ÓÚ¿ÉÓõÄ״̬¡£Èç¹û·¢ÏÖÔªÊý¾Ý²»Ò»Ö£¬ fsck½«É¨ÃèºÍ¼ì²âÔªÊý¾Ý£¬²¢¾ÀÕý´íÎó¡£Èç¹ûÎļþϵͳºÜ´ó£¬Õâ¸ö¹ý³Ì½«ÐèÒªºÜ³¤µÄʱ¼ä¡£Îª½â¾öÕâ¸öÎÊÌ⣬¿ÉÒÔʹÓÃÈÕÖ¾Îļþϵͳ¡£ÈÕÖ¾ÎļþϵͳÓöÀÁ¢µÄÈÕ Ö¾Îļþ¸ú×Ù´ÅÅÌÄÚÈݵı仯£¬ÔÚдÈëÎļþÄÚÈݵÄͬʱдÈëÎļþµÄÔªÊý¾Ý¡£Ã¿´ÎÐÞ¸ÄÎļþµÄÔªÊý¾Ýʱ£¬¶¼ÒªÏÈÏò³ÆΪ"ÈÕÖ¾"µÄÊý¾Ý½á¹¹µÇ¼ÇÏàÓ¦µÄÌõÄ¿¡£ÕâÑù£¬ÈÕÖ¾ Îļþϵͳ¾Íά»¤ÁË×î½ü¸ü¸ÄµÄÔªÊý¾ÝµÄ¼Ç¼¡£µ±¼ÓÔØÈÕÖ¾Îļþϵͳʱ£¬Èç¹û·¢ÏÖÁË´íÎ󣬲»»áɨÃèÕû¸öÎļþϵͳµÄÔªÊý¾Ý£¬¶øÊǸù¾ÝÈÕÖ¾¼ì²é×î½ü±»¸ü¸ÄµÄÔªÊý¾Ý¡£ ËùÒÔÏà¶ÔÓÚ´«Í³µÄÎļþϵͳ£¨Èçext2£©£¬ÈÕÖ¾Îļþϵͳ´ó´óµØ¼Ó¿ìÁËɨÃèºÍ¼ì²âµÄʱ¼ä¡£



LinuxÏ¿ÉÓõÄÈÕÖ¾ÎļþϵͳºÜ¶à£¬ÈçXFS£¬JFS£¬Reiserfs£¬ext3µÈµÈ¡£ÈÕÖ¾ÎļþϵͳÖ÷Òª±»Éè¼ÆΪ·þÎñÆ÷»·¾³Ìṩ³öÉ«ÐÔÄÜºÍ¸ß¿É ÓÃÐÔ¡£µ±È»£¬ Linux ¹¤×÷Õ¾ºÍ¼ÒÓûúÆ÷Ò²¿É´Ó¾ßÓиßÐÔÄܵĿɿ¿ÈÕÖ¾ÎļþϵͳÖлñÒæ¡£°²×°ÈÕÖ¾Îļþϵͳ£¬Ò»°ãÐèÒªÏÂÔØÏàÓ¦µÄѹËõ°ü¡¢ÎªÄں˴ò²¹¶¡¡¢ÖØÐÂÅäÖúÍÖØбàÒëÄںˡ£ ÏêϸµÄ°²×°¹ý³Ì¿É·ÃÎÊÏàÓ¦ÎļþϵͳµÄ¹Ù·½ÍøÕ¾¡£



4£®ÆäËü·½ÃæµÄµ÷г



4.1 µ÷гbuffermem



ÎļþbuffermenºÍÄÚºËÐéÄâÄÚ´æ×ÓϵͳÃÜÇÐÏà¹Ø¡£Îļþ/proc/sys/vm/buffermem¿ØÖƶà´óÄÚ´æ±»ÓÃÓÚ»º³åÇø£¨°Ù·ÖÊý±íʾ£©¡£ÄÚºË2.4µÄȱʡֵΪ£º: "2 10 60"¡£¿ÉÒÔ°´ÈçÏ·½·¨Ð޸ģº


# echo "70 10 60" >/proc/sys/vm/buffermem



²¢½«Ö®¼Óµ½½Å±¾Îļþ/etc/rc.d/rc.local ÖС£»òÕßÔÚ/etc/sysctl.confÎļþÖмÓÈë


vm.buffermem = 70 10 60



µÚÒ»¸ö²ÎÊý 70Òâζ×ÅÖÁÉÙ·ÖÅä70%µÄÄÚ´æÓÃ×÷»º³åÇø¡£ºóÁ½¸ö²ÎÊý±£³ÖϵͳµÄĬÈÏÖµ¡£µÚÒ»¸ö²ÎÊýÉèÖÃΪ¶à´óºÏÊÊ£¬ÒÀÀµÓÚϵͳµÄÄÚ´æ´óСºÍϵͳ¸ß¸ºÔØʱÄÚ´æµÄʹÓÃÇé¿ö£¨¿ÉÓÃfree¼àÊÓ£©¡£



4.2 ½ø³ÌÏÞÖÆ



Linux¶ÔÓÚÿ¸öÓû§£¬ÏµÍ³ÏÞÖÆÆä×î´ó½ø³ÌÊý¡£ÎªÌá¸ßÐÔÄÜ£¬¿ÉÒÔÉèÖ󬼶Óû§rootµÄ×î´ó½ø³ÌÊýΪÎÞÏÞ¡£±à¼­.bashrcÎļþ£¨vi /root/.bashrc£©Ôö¼ÓÐÐ"ulimit -u unlimited"¼´¿ÉÏû³ý³¬¼¶Óû§µÄ½ø³ÌÏÞÖÆ¡£



ºËÐĺÍϵͳ¶ÔÓû§½ø³ÌÆäËüµÄһЩÏÞÖÆÒ²¿ÉÒÔͨ¹ýulimitÃüÁîÀ´²é¿´ºÍ¸ü¸Ä¡£"ulimit -a" ÓÃÀ´ÏÔʾµ±Ç°µÄ¸÷ÖÖÓû§½ø³ÌÏÞÖÆ¡£Ò»Ð©¸ü¸ÄÓû§ÏÞÖƵÄÀý×ÓÈçÏ£º



ulimit -n 4096 ½«Ã¿¸ö½ø³Ì¿ÉÒÔ´ò¿ªµÄÎļþÊýÄ¿¼Ó´óµ½4096£¬È±Ê¡Îª1024
ulimit -m 4096 ÏÞÖÆÿ¸ö½ø³ÌʹÓõÄÄÚ´æÊý¡£



4.3 ÓÅ»¯gcc±àÒë



½«ÓÅ»¯±êÖ¾·ÅÔÚ/etc/profileÎļþÖС£ÔÚpentium III¼¶µÄ´¦ÀíÆ÷ÉÏʹÓÃÒÔÏÂÓÅ»¯±êÖ¾½«µÃµ½×îÓŵÄÓ¦ÓóÌÐò£º


CFLAGS=-O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions



ÔÙ½«ÈçÏÂÐмӵ½/etc/profile ¸ü¿¿ºóµÄλÖãº


export PATH PS1 HOSTNAME HISTSIZE HISTFILESIZE USER LOGNAME MAIL INPUTRC CFLAGS LANG LESSCHARSET



ʹÓÃÒÔÉϵÄÓÅ»¯£¬gcc»òÕßegcs±àÒëµÄ³ÌÐò½«µÃµ½×î¼ÑµÄÐÔÄÜ¡£



4.4 ±àÒëÄÚºËÓÅ»¯


±à¼­/usr/src/linux/MakefileÎļþ£¬¿ÉÒÔ¸ù¾Ý¾ßÌåµÄcpuÓÅ»¯Äں˱àÒë¡£ÒÔϵIJÎÊýÉèÖý«µÃµ½ÓÅ»¯µÄÄÚºËÐÔÄÜ¡£


¢Ù vi +18 /usr/src/linux/Makefile £¬½«HOSTCC =gcc¸ÄΪ HOSTCC =egcs.
¢Ú vi +25 /usr/src/linux/Makefile
½«CC =$(CROSS_COMPILE)gcc D__KERNEL__ -I$(HPATH)
¸ÄΪ CC =$(CROSS_COMPILE)egcs D__KERNEL__ -I$(HPATH).
¢Û vi +90 /usr/src/linux/Makefile
½«CFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
¸ÄΪCFLAGS = -Wall -Wstrict-prototypes -O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions
¢Ü vi +19 /usr/src/linux/Makefile
½«HOSTCFLAGS =-Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
¸ÄΪHOSTCFLAGS =-Wall -Wstrict-prototypes -O9 -funroll-loops -ffast-math -malign-double -mcpu=pentiumpro -march=pentiumpro -fomit-frame-pointer -fno-exceptions


¸ù¾ÝÒÔÉÏÐ޸ĺóµÄmakefileÎļþÖØбàÒëÄں˽«µÃµ½½ÏÓŵÄÐÔÄÜ¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 4 ÌõÆÀÂÛ

  1. caldo ÓÚ 2006-07-19 15:57:57·¢±í:

    ѧϰ

  2. eoboot ÓÚ 2005-11-06 10:37:28·¢±í:

    ²»´í£¬¶¥

  3. ÐÂРÓÚ 2005-09-22 00:33:45·¢±í:

    ¶¥ÉÏÈ¥

  4. zz123 ÓÚ 2005-07-17 00:40:40·¢±í:

    Ö§³Ö£¬¶¥