Windows ã®ãã¼ã管ç - Firefox3 ã®ã¡ã¢ãªä½¿ç¨é (2)
ã·ã¢ãã«è¡ãåã«ãjemalloc on Windows - Firefox3 ã®ã¡ã¢ãªä½¿ç¨é - NyaRuRuã®æ¥è¨ã ã®ç¶ããçä»ãã¦ããã¾ããï¼
ã¨ããã¤ã¤ï¼å½åäºå®ã®å
容ã¯ã¨ããããç ´æ£ï¼æ¸ãã¦ãããã¡ã«æ°ã«ãªããã¨ãè²ã
åºã¦ãã¦ï¼ãã®åº¦ã«å®é¨ãããã®ã ããããã¾ãé²ãã§ããªãã¦ï¼ãã®ã¾ã¾ã ã¨æ°¸é ã«çµãããªãããªã®ã§æ¹éãå¤ãã¾ããï¼ã¨ããããã§å¤é¨è³æå¤ãã§ãéããã¾ãï¼
æåã«èªããã®
UNIX 系㮠mmap ã使ã£ãã¡ã¢ãªã¢ãã±ã¼ã·ã§ã³ãªãã ãããåãããï¼ã¨ãã人ãï¼Windows ã®ã¡ã¢ãªç®¡çã«ã¤ãã¦èå³ãæã£ãã¨ãã¦ï¼ãããããªã®ã ã(新)APIから知るWindowsの仕組みãã·ãªã¼ãºã®ã第4回 メモリー管理のキー技術「仮想メモリー」を知るãã¨ããè¨äºã§ãï¼
ã¨ããããã§ããã§ã¾ãä¸ã®ãã¼ã¸ã«é£ãã§ï¼ä¸éãèªãã§ã¿ã¦ä¸ããï¼ä»¥ä¸ã¯ãã®å¾ã§ï¼
ä»®æ³ã¢ãã¬ã¹é åã®äºç´ã«ã¤ãã¦
ãã¤ã³ãã¨ãªãä»®æ³ã¢ãã¬ã¹é åã®äºç´ãå¯è½ã«ããåæ©ã«ã¤ãã¦ã¯ï¼å ã»ã©ã®è¨äºã®ä»¥ä¸ã®é¨åã§èª¬æããã¦ãã¾ãï¼
ãããï¼ãªããããªé¢åãªãã¨ãããã®ã ããããããã¯ï¼ç©çã¡ã¢ãªã¼ã¨åããããï¼ä»®æ³ã¡ã¢ãªã¼ã®ã¢ãã¬ã¹é åãè²´éã ããã§ãããç©çã¡ã¢ãªã¼ãä¸è¶³ããã°ï¼ãã¼ã¸ã³ã°ã»ãã¡ã¤ã«ã«ãã¼ã¿ãéé¿ãããã¨ã§ä½¿ãåããå©ããï¼ä»®æ³ã¡ã¢ãªã¼ã«ã¯4Gãã¤ãã¨ããå¶éãããããããï¼4Gãã¤ãã®ããã»ã¹ã»ã¡ã¢ãªã¼ç©ºéããã¹ã¦ããã°ã©ã ã使ã£ã¦ããããã§ã¯ãªããWindowsã·ã¹ãã ã®ã³ã¼ããåãã¡ã¢ãªã¼ç©ºéã«ç½®ãããããï¼æ大ã§2Gãã¤ãï¼å¾è¿°ããããã«ï¼ããã3Gãã¤ãã«æ¡å¼µãããã¨ãå¯è½ãªãã¼ã¸ã§ã³ã®Windowsãããï¼ã¾ã§ããï¼ããã°ã©ã ã§ã¯ä½¿ç¨ã§ããªãã®ã ã
ããä¸ã¤éè¦ãªãã¤ã³ãã¯ï¼ä»®æ³ã¡ã¢ãªã¼ã®ãã©ã°ã¡ã³ãã¼ã·ã§ã³ï¼æçåï¼ã§ãããããã¤ãã®ã¡ã¢ãªã¼é åãå²ãå½ã¦ããï¼è§£æ¾ããããç¹°ãè¿ãã¦ããã¨ï¼ã¡ã¢ãªã¼ã®ä½¿ç¨ç¶æ³ãå³5ã®ããã«ãªã£ã¦ãã¾ããã¨ãããããã®ããã«ï¼ã¡ã¢ãªã¼ã®æªä½¿ç¨é åãä¸é£ç¶ã«ãªã£ã¦ãã¾ããã¨ãï¼ãã©ã°ã¡ã³ãã¼ã·ã§ã³ã¨å¼ã¶ã
å³5âã¡ã¢ãªã®ãã©ã°ã¡ã³ãã¼ã·ã§ã³
ã¡ã¢ãªã¼ã»ãããã¯ãå²ãå½ã¦ãã«ã¯ï¼å¿ è¦ãªãµã¤ãºä»¥ä¸ã®é£ç¶é åãå¿ è¦ã ããããï¼ãã©ã°ã¡ã³ãã¼ã·ã§ã³ãèµ·ãã£ã¦ããã¨ï¼æªä½¿ç¨é åã®ãµã¤ãºã®åè¨ãååã§ãã£ã¦ãï¼å¿ è¦ãªã¡ã¢ãªã¼ã»ãããã¯ãå²ãå½ã¦ãããªãå¯è½æ§ãåºã¦æ¥ãããã©ã°ã¡ã³ãã¼ã·ã§ã³ãã§ããã ãèµ·ãããªãããã«ããã°ã©ã ãè¨è¿°ãã工夫ãå¿ è¦ãªä¸æ¹ã§ï¼é£ç¶ããã¡ã¢ãªã¼é åãäºç´ãã¦ãããã¨ãéè¦ãªã®ã§ããã
ä¸è¬çãªèª¬æã¯ããã§ååã ã¨æãã®ã§ï¼ä»¥ä¸ç§è¦ã¢ã¼ãï¼
å®éã®ã¨ããï¼ä»®æ³ã¢ãã¬ã¹é åã®äºç´ãæå¹ã«ä½¿ãã®ã¯æ¡å¤ã¨é£ããããããªããã¨æãã¾ãï¼
ä»®æ³ã¢ãã¬ã¹é åãäºç´ã§ãã¦ãï¼ããããå¿
è¦ãªé£ç¶é åã®ä¸éå¤ãåãããªãã¨ããæ ¹æ¬çãªåé¡ã¯è§£æ±ºãã¾ããï¼ä¾ãã°å¿
è¦ãªã¡ã¢ãªãé«ã
300 MB ã¨åãã£ã¦ããã°ï¼æåãã VirtualAlloc 㧠300 MB ã³ãããã¨ããã®ãã²ã¨ã¤ã®æãªã®ã§ãï¼ä»ã®ã¢ãã³ãª OS ã¨åããï¼Windows ãå®éã«ã¡ã¢ãªã¢ã¯ã»ã¹ãèµ·ããã¾ã§ã¯ç©çã¡ã¢ãªãå²ãå½ã¦ã¾ããï¼ãªã®ã§ï¼300 MB ã®ã³ãããé åã®å
é 10 MB ã«ã®ã¿ã¢ã¯ã»ã¹ãã¦çµäºããããã»ã¹ã¯ï¼çµå± 10 MB ããç©çã¡ã¢ãªã«è² è·ãããã¾ããï¼ç¢ºãã«ä»®æ³ã¢ãã¬ã¹é åã 300 MB äºç´ãã¦ï¼é¨åã³ããããã¦ãã£ãæ¹ããã¿ã¼ã§ã¯ããã¾ããï¼ããã¯åã«è§£ããåé¡ãããå¹ççã«è§£ãã¦ããã ããªã®ã§ããï¼
ç¾å®çãªã·ããªãªã¨ãã¦ï¼å¿
è¦ãªé£ç¶é åã®ãµã¤ãºãäºæ³ä¸è½ã ã¨ãã¦ï¼ãã°ãèªãã§ã¢ãã¬ã¹é åãããªã大éã«äºç´ããã¨ã©ããªãã§ããããï¼ä¾ãã° 1 GB ã¨ãï¼
ã¦ã¼ã¶ã©ã³ãã®ã¡ã¢ãªã¢ãã±ã¼ã¿ãã²ã¨ã¤ãããªãã¦ï¼äºç´ãè¡ãã®ããã®å¯ä¸ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ã§ããã°ã¾ãåé¡ã¯ãªãã§ãããï¼ãã ã DLL ã®ãã¼ãçã§è¡ãããæé»ã®ãã¡ã¤ã«ãããã³ã°ãï¼ã¹ã¬ããã¹ã¿ãã¯ãæ¶è²»ããã¢ãã¬ã¹é åãæ®ãã¦ãããã¨ãå¿ããã«ï¼ã¨ï¼
ã§ãç¾å®ã¯ããåç´ãããªãã§ãããï¼Windows ã¯çã¡ã¢ãªããã°ã©ãã³ã°ãå¿
é ã§ãã£ãæ代ã®åæ®ãï¼å
±æã©ã¤ãã©ãª (DLL) ã«ããã¤ã³ããã»ã¹ã³ã³ãã¼ãã³ãæè¡ã好ã¾ãã¾ãï¼å DLL ã¯æ§ã
ãªè¨èªã«ãã£ã¦ããã°ã©ãã³ã°ããã¦ãã¦ï¼ããããã¯ç¬èªã®ã¡ã¢ãªã¢ãã±ã¼ã¿ãæã¤ã§ãããï¼ããã¢ã¸ã¥ã¼ã«ã大éã«ã¢ãã¬ã¹ç©ºéãäºç´ããã°ï¼å¥ã®ã¢ã¸ã¥ã¼ã«ããã¿ããå©ç¨å¯è½é åãã確å®ã«æ¸å°ãã¾ãï¼DLL X ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ã 1 GB ã®é£ç¶é åãäºç´ãã¦ï¼DLL Y ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ããæ¬å½ã«ã 1 GB å¿
è¦ã¨ãããããã§ã¢ãã¬ã¹é åã使ãåã£ã¦ãã¾ãã¾ãï¼ã³ã³ãã¼ãã³ãã®å¯æ¬æ§ãé«ãããã¨ããã°ããã»ã©ï¼ä»ã®ã¢ã¸ã¥ã¼ã«ã«è¿·æãããããããªã¢ãã¬ã¹é åã®äºç´ã¯é£ãããªãã®ã§ãï¼
å®éã®ã¨ãã Windows ã¢ããªã±ã¼ã·ã§ã³ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ãã©ããªã£ã¦ãã®ã調ã¹ã¦ã¿ã
ã¾ãã¯ï¼æ代ãç¾ä»£ã«è¨å®ãï¼ã¡ã¢ãªç®¡çã«ã¯ç¹ã«æãå
¥ãã®ãªãããã°ã©ããï¼Visual C++ 2008 㧠Win32 ã¢ããªã±ã¼ã·ã§ã³ãä½æããå ´åãèãã¾ãããï¼ãã®å ´å㯠MSVCRT ã®ããã©ã«ãã¡ã¢ãªã¢ãã±ã¼ã¿ã使ããã¦ããã¯ãã§ãï¼MSVCRT ã¯éçãªã³ã¯çã¨åçãªã³ã¯çããã£ã¦ï¼éçãªã³ã¯ãé¸ãã§ä½ã£ãã¢ã¸ã¥ã¼ã« (EXE ã¾ã㯠DLL) ã¯ï¼ãã®ã¢ã¸ã¥ã¼ã«å
ã«ç¬ç«ããã¡ã¢ãªã¢ãã±ã¼ã¿ãæã¤ãã¨ã«ãªãã¾ãï¼åçãªã³ã¯ãé¸ãã ã¢ã¸ã¥ã¼ã«ã®å ´åï¼ã¡ã¢ãªå¨ãã®å¦ç㯠MSVCRT DLL ã«ä¸¸æãããã¾ãã®ã§ï¼åä¸ãã¼ã¸ã§ã³ã® CRT ãå©ç¨ããã¢ã¸ã¥ã¼ã«éã§ã¯ã¡ã¢ãªã¢ãã±ã¼ã¿ãå
±æãããã¨ã«ãªãã¾ãï¼
ã¨ï¼ç°¡åã«æ¸ã¾ããããã»ã©åç´ã§ã¯ãªããããªãã§ãããï¼
Visual C++ ã«ã¯ CRT ã½ã¼ã¹ã³ã¼ããä»å±ãã¦ããã®ã§ããï¼ãããèªãã¨ï¼Visual C++ 7.0 (Visual C++.NET 2002) 以éã® MSVCRT ã¯ï¼3 種é¡ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ããç°å¢ãè¨å®ã«å¿ãã¦ã²ã¨ã¤ãé¸ãã§ãããã¨ãåããã¾ãï¼*1ï¼
- Visual C++ 5.0 ä»å± MSVCRT äºæã®ã¡ã¢ãªã¢ãã±ã¼ã¿
- Visual C++ 6.0 ä»å± MSVCRT äºæã®ã¡ã¢ãªã¢ãã±ã¼ã¿
- ã·ã¹ãã ãã¼ãã¢ãã±ã¼ã¿
ã½ã¼ã¹ãèªãã¨ï¼ã©ããã Visual C++ 5.0/6.0 㯠small heap block ã¨å¼ã°ããä»çµã¿ã§å°ããªãµã¤ãºã®ã¡ã¢ãªå²ãå½ã¦ãç¬èªç®¡çãã¦ããããã§ãï¼ä¸æ¹ï¼ã·ã¹ãã ãã¼ãã¢ãã±ã¼ã¿ã¯ï¼Windows 2000 以éã® kernel32.dll ã«åå¨ãããã¼ã管ç API ã§ï¼Visual C++ 7.0 ã¯å°ããªã¡ã¢ãªå²ãå½ã¦ãå
¨ã¦ãã®ãã¼ã API ã«ä¸¸æããªããã§ããã¨ï¼
絡繰ããè¦ãã¦ããæãã§ããï¼
åä¸ãã¼ã¸ã§ã³ã®ã³ã³ãã¤ã©/ãªã³ã«ã使ããã¦ããã®ã§ããã°ï¼ä»®ã«ã¢ã¸ã¥ã¼ã«ãåããã¦ãã¦ã CRT ã®ã¡ã¢ãªã¢ãã±ã¼ã¿ãç¡çç¢ççµ±åãããã¨ã¯ä¸å¯è½ã§ã¯ãªãããã§ããï¼å®é Visual C++ 5.0/6.0 ã¯ãããããã¨ããã£ã¦ããããã§ãï¼
ããã« Windows 2000 㨠Visual C++ 7.0 ã§ã¯ï¼ãããè¨èªéä¾åã«æ¡å¼µããï¼ã¨ï¼ã¤ã¾ã åããã»ã¹ã«ãã¼ã管çã®åä¸ãã¡ãµã¼ãã OS ã¬ãã«ã§æä¾ãï¼å
¨ã¦ã®è¨èªã®ã©ã³ã¿ã¤ã ã©ã¤ãã©ãªããããå©ç¨ããã°çãããã¼è¨ç»ï¼JVM ã CLR ã§ã¯å½ããåã®ãã¡ã¢ãªã¢ãã±ã¼ã¿ã®çµ±åãã§ããï¼Win32 㪠C/C++ ãã®ä»ã®ä¸çã§ã 2002 å¹´é ã«ãªãã¨ãããã¤ãã¦ãããã§ããªãï¼
ããã¦ã¡ã¢ãªã¢ãã±ã¼ã¿ãçµ±ä¸ã§ããã®ã§ããã°ï¼ããï¼ä»®æ³ã¢ãã¬ã¹é åã®äºç´ãæå³ãæã£ã¦ããã¯ãã§ãï¼
ããã¦è§£çç·¨
çµå±ã®ã¨ããæ£è§£ã¯å½äºè ã«ããåããã¾ããã®ã§ï¼ä»¥ä¸ã®è³æã«ã¯ç®ãéããã¨ããå§ããã¾ãï¼å ã»ã©ã®èå¯ã念é ã«ç½®ãã°ï¼ã ãã¶èªã¿ããããªã£ã¦ããã¯ãã§ãï¼
ä¾ãã°æ´å²ã«é¢ãã¦ã¯æ¬¡ã®è³æã«ããã¾ã¨ã¾ã£ã¦ãã¾ãï¼
OS ãæä¾ãããã¼ãããã¼ã¸ã£ã®æ¦è«ã«ã¤ãã¦ã¯æ¬¡ã®è³æãããããã§ãï¼
- ã¤ã³ãµã¤ã Microsoft Windows 第4çãä¸ã 7.2.9 ãã¼ãããã¼ã¸ã£
Windows XP 以éã®ä½æçåãã¼ãã«é¢ããå®è£ 詳細ã«ã¤ãã¦ã¯ä»¥ä¸ã®è³æãããããã§ãï¼
- コンピュータ科学特別講義III (戦略ソフトウェア特論II)
- Ask the Performance Team : MSDN blog
ææ³
Windows ã®ç¹æ®äºæ ã£ã¦ã®ãç解ãã¦ãããã©ããã§ï¼è³æã®èªã¿ããããã ãã¶éãã®ã¯ç¢ºãã«ããã¨æãã¾ãï¼è¦è½ã¨ããã¡ãªè¦ç¹ã¨ãã¦ï¼æ¬¡ã® 2 ã¤ã«æ³¨æããã¨è¯ãããããã¾ããï¼
- Windows ã§ã¯ãã½ã¼ã¹ããåã³ã³ãã¤ã«ããã°ããããããã¯æãç«ããªãï¼è¨å¤§ãªã¢ããªã±ã¼ã·ã§ã³ããã¤ããªã³ã³ãã¼ãã³ãè³ç£ãããããã¨ã³ã·ã¹ãã ã¨æ·±ãçµã³ã¤ãã¦ããï¼ãã¤ããªäºæã¨æ§è½åä¸ã両ç«ãããã¨ããåæ©ã¯ï¼è¤éã§å¤§è¦æ¨¡ãªä»çµã¿ã OS ã«å°å ¥ããã®ã«ååãªçç±ã§ããï¼
- Microsoft ã«ã¨ã£ã¦ã®æã¡é§ã¯ä¸»ã«æ¬¡ã® 2 ã¤ï¼ãã®é§ã§ãã¡ã¢ãªã¢ãã±ã¼ã¿ã®çµ±åã¨æ¹è¯ããè¡ãã«ã¯ã©ããããï¼ ãã ãéå»ã«åºè·ãããã¤ããªã³ã³ãã¼ãã³ãã¯ååçã«å¤æ´ã§ããªããã¨ã«æ³¨æï¼
- æ°ãã OS ãåºè·ãããã¨ï¼
- OS æ¨æºã®ãã¤ããªã³ã³ãã¼ãã³ãã¯æ°ãã¼ã¸ã§ã³ã«å¤æ´å¯è½ï¼
- æ°ãã Visual C++ ãåºè·ãããã¨
- æ§ãã¼ã¸ã§ã³ã® Visual C++ ã§ä½ããããã¤ããªã¢ã¸ã¥ã¼ã«ã¨ãçµã¿åããããããã¨ï¼
- æ°ãã OS ãåºè·ãããã¨ï¼
æ¯ãè¿ã£ã¦ï¼ãFirefox 3 のメモリ使用量ããèªã¿ç´ãã¨ãããã¯ã¢ããªã±ã¼ã·ã§ã³éçºè
ã®è¦ç¹ã ãªããã¨ã¤ãã¥ãæãã¾ãï¼Win32 ã®è¨è¨ã¨é²åãèããã°ï¼å®ã®ã¨ãã足ããªãã®ã¯ãWin32 front-end heap ãç¬èªã¢ã«ã´ãªãºã ã«ç½®ãæããä»çµã¿ãããããã¾ããï¼Windows ã¯ä½å¹´ããã㦠front-end heap ã¸ã®ä¸æ¬åãé²ãã¦ããã®ã§ï¼ããã jemalloc ã®åçç©ã«ç½®ãæããä»çµã¿ããããã°ï¼ã½ã¼ã¹ãå¼ããã¨ããªãï¼Firefox 3 ã®ããã»ã¹å
¨ä½ã§ãã¼ã管çãæ¹åã§ãã¦ããã¯ãã ããªãã¨ï¼
ãã«ãæã«æ¨æº CRT ã® malloc ãç¡çç¢çç½®ãæãã Firefox 3 ã® --enable-jemalloc ãã«ãã¯ï¼ç¢ºãã«ããã ã¢ããã«ããã°ã£ã¦ããã¨ããå°è±¡ãåãã¾ããï¼ä¾ãã° XPCOM ã使ã£ãæ¡å¼µã Visual C++ ã§ä½ãã¨ãã¦ï¼ãã®ã¡ã¢ãªã¢ãã±ã¼ã¿ã jemalloc ã«åãããã¹ãã¨ãã£ãæéçã¯ããã®ã§ããããï¼ å¥ã®ã³ã³ãã¤ã©ã ã£ãå ´åã¯ï¼ ããããæ¡å¼µã®ä½è
éã¸ã®æ
å ±æä¾ã¯ååãªã®ã§ããããï¼ "private bytes" ã«é¢ãã Stuart Parmenter ããã®èª¤è§£ã®ä»¶ã¨ããã©ããè¥å¹²ã®ä¸å®ãæ®ãã¾ãï¼
ãªãã¦ã¼ããã¯ï¼ä¾ã®ãプログラマーは「マシン語」を理解して初めて一人前?ãåé¡ã«ãéããã¨ãããããã®ããï¼ã¯ãã¹ãã©ãããã©ã¼ã ããã¸ã§ã¯ãã¯ï¼åãã©ãããã©ã¼ã ã®ç¹æ®æ§ãç解ãã¦åãã¦ä¸äººåï¼ã¨ã¤ã端ããè¨ããããªãçå群ï¼ããªï¼
ã¾ãå®éãããã話ã¯æ¥½ããã§ããï¼ã¡ã¢ãªã¢ãã±ã¼ã¿ã®æ§è½ã試ãããããã¹ããã³ããã§ããã¨èããã°æ±ºãã¦æªã話ã§ã¯ããã¾ããï¼
ãããã¤ãã¥ãæãã®ã¯ï¼ç¾ä»£ã®ãã©ã¦ã¶ã£ã¦å·¨å¤§ã¢ããªã±ã¼ã·ã§ã³ã ãªãã¨ï¼ããã©ã¦ã¶ã¨ã¡ã¼ã©ã¼ããåãã°ããããªãã¦ãã¤ã®æ代ã®è©±ããï¼ããã©ã¦ã¶ãå¿«é©ã«åãç°å¢ãªãï¼å¤§æµã®ã¢ããªã±ã¼ã·ã§ã³ãå¿«é©ã«åããã®ééããããªãã§ãããããï¼
*1:[http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.kernel/2004-06/0499.html:title=]