{"id":3533,"date":"2021-07-01T10:03:02","date_gmt":"2021-07-01T02:03:02","guid":{"rendered":"https:\/\/wyxxt.org.cn\/?p=3533"},"modified":"2023-12-04T15:18:51","modified_gmt":"2023-12-04T07:18:51","slug":"go%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/wyxxt.org.cn\/?p=3533","title":{"rendered":"go\u5185\u5b58\u7ba1\u7406"},"content":{"rendered":"<h2>\u6307\u9488<\/h2>\n<p>go\u8bed\u8a00\u6ca1\u6709\u6307\u9488\u8fd0\u7b97<\/p>\n<p>&amp; \u53d6\u5730\u5740\u7b26<\/p>\n<p>*\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b \u4ee5\u4e0b\u9762\u4ee3\u7801\u4e3a\u4f8b\uff0c\u6307\u9488\u6307\u5411int\u7c7b\u578b<\/p>\n<pre><code class=\"language-go line-numbers\">var pi *int\nvar i int = 8\npi = &amp;i\n<\/code><\/pre>\n<p>\u6307\u9488\u7684\u4f5c\u7528\uff0c\u4f20\u9012\u53c2\u6570<\/p>\n<h2>GMP\u6a21\u578b<\/h2>\n<p><em>Go Runtime\u5c06Goroutines\uff08<\/em><code>G<\/code><em>\uff09<strong>\u5b89\u6392<\/strong>\u5230\u903b\u8f91\u5904\u7406\u5668\uff08<\/em><code>P<\/code><em>\uff09\u6267\u884c\u3002\u6bcf\u4e2a<\/em><code>P<\/code><em>\u90fd\u6709\u4e00\u53f0\u673a\u5668\uff08<\/em><code>M<\/code><em>\uff09<\/em><\/p>\n<p>Go\u4ece1.5\u7248\u672c\u4e4b\u540e\u5c06\u9ed8\u8ba4\u7684P\u7684\u6570\u91cf\u6539\u4e3a = CPU core\u7684\u6570\u91cf\uff08\u5b9e\u9645\u4e0a\u8fd8\u4e58\u4ee5\u4e86\u6bcf\u4e2acore\u4e0a\u786c\u7ebf\u7a0b\u6570\u91cf\uff09<\/p>\n<h2>\u5185\u5b58\u7ba1\u7406<\/h2>\n<h3>\u5165\u95e8<\/h3>\n<p>\u8f6f\u4ef6\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\u65f6\uff0c\u9700\u8981\u8bbf\u95ee\u8ba1\u7b97\u673aRAM\uff08\u968f\u673a\u8bfb\u53d6\u5185\u5b58\uff09\u4ee5\uff1a<\/p>\n<ul>\n<li>\u52a0\u8f7d\u9700\u8981\u6267\u884c\u7684\u81ea\u5df1\u7684<strong>\u5b57\u8282\u7801<\/strong><\/li>\n<li>\u5b58\u50a8\u88ab\u6267\u884c\u7684\u7a0b\u5e8f\u4f7f\u7528\u7684<strong>\u6570\u636e\u503c\u548c\u6570\u636e\u7ed3\u6784<\/strong><\/li>\n<li>\u52a0\u8f7d\u7a0b\u5e8f\u6267\u884c\u6240\u9700\u7684\u4efb\u4f55<strong>\u8fd0\u884c\u65f6\u7cfb\u7edf<\/strong><\/li>\n<\/ul>\n<p>\u5f53\u8f6f\u4ef6\u4f7f\u7528\u5185\u5b58\u662f\uff0c\u9664\u4e86\u7528\u4e8e\u52a0\u8f7d\u5b57\u8282\u7801\u7684\u7a7a\u95f4\u5916\uff0c\u5b83\u4eec\u4f7f\u7528\u7684\u4e24\u4e2a\u5185\u5b58\u533a\u57df\uff0c\u5373\u5806\u6808\uff08\u6808\uff09\u548c\u5806\u5185\u5b58\uff08\u5806\uff09\u3002<\/p>\n<p>\u6808<\/p>\n<p>\u7528\u4e8e<strong>\u9759\u6001\u5185\u5b58\u5206\u914d<\/strong>\uff0c\u987e\u540d\u601d\u4e49\uff0c\u5b83\u662f\u540e\u8fdb\u540e\u51fa\uff08<strong>LIFO<\/strong>\uff09\u5806\u6808\uff08\u5c06\u5176\u89c6\u4e3a\u4e00\u6808\u6846\uff09<\/p>\n<ul>\n<li>\u7531\u4e8e\u8fd9\u79cd\u6027\u8d28\uff0c\u4ece\u5806\u6808\u4e2d\u5b58\u50a8\u548c\u68c0\u7d22\u6570\u636e\u7684\u8fc7\u7a0b<strong>\u975e\u5e38\u5feb<\/strong>\uff0c\u56e0\u4e3a\u4e0d\u9700\u8981\u67e5\u627e\uff0c\u60a8\u53ea\u9700\u4ece\u5806\u6808\u7684\u6700\u9876\u5c42\u5757\u5b58\u50a8\u548c\u68c0\u7d22\u6570\u636e\u3002<\/li>\n<li>\u4f46\u8fd9\u610f\u5473\u7740\u5b58\u50a8\u5728\u5806\u6808\u4e0a\u7684\u4efb\u4f55\u6570\u636e\u5fc5\u987b\u662f<strong>\u6709\u9650\u548c\u9759\u6001<\/strong>\u7684\uff08\u6570\u636e\u7684\u5927\u5c0f\u5728\u7f16\u8bd1\u65f6\u5df2\u77e5\uff09\u3002<\/li>\n<li>\u8fd9\u91cc\u662f\u51fd\u6570\u7684\u6267\u884c\u6570\u636e\u4ee5<strong>\u6808\u5e27<\/strong>\u7684\u5f62\u5f0f\u5b58\u50a8\uff08\u6240\u4ee5\uff0c\u8fd9\u5c31\u662f\u5b9e\u9645\u7684\u6267\u884c\u6808 \uff09 \u3002\u6bcf\u4e2a\u5e27\u90fd\u662f\u5b58\u50a8\u8be5\u51fd\u6570\u6240\u9700\u6570\u636e\u7684\u4e00\u5757\u7a7a\u95f4\u3002\u4f8b\u5982\uff0c\u6bcf\u6b21\u51fd\u6570\u58f0\u660e\u65b0\u53d8\u91cf\u65f6\uff0c\u5b83\u90fd\u4f1a\u88ab\u201c\u63a8\u9001\u201d\u5230\u5806\u6808\u4e2d\u6700\u9876\u5c42\u7684\u5757\u4e0a\u3002\u7136\u540e\uff0c\u6bcf\u6b21\u51fd\u6570\u9000\u51fa\u65f6\uff0c\u6700\u4e0a\u9762\u7684\u5757\u90fd\u4f1a\u88ab\u6e05\u9664\uff0c\u56e0\u6b64\u8be5\u51fd\u6570\u63a8\u9001\u5230\u5806\u6808\u4e0a\u7684\u6240\u6709\u53d8\u91cf\u90fd\u88ab\u6e05\u9664\u3002\u7531\u4e8e\u5b58\u50a8\u5728\u8fd9\u91cc\u7684\u6570\u636e\u7684\u9759\u6001\u6027\u8d28\uff0c\u8fd9\u4e9b\u53ef\u4ee5\u5728\u7f16\u8bd1\u65f6\u786e\u5b9a\u3002<\/li>\n<li><strong>\u591a\u7ebf\u7a0b\u5e94\u7528<\/strong>\u6bcf\u4e2a\u7ebf\u7a0b<strong>\u53ef\u4ee5\u6709\u4e00\u4e2a<\/strong>\u5806\u6808\u3002<\/li>\n<li>\u5806\u6808\u7684\u5185\u5b58\u7ba1\u7406<strong>\u7b80\u5355\u660e\u4e86<\/strong>\uff0c\u7531\u64cd\u4f5c\u7cfb\u7edf\u5b8c\u6210\u3002<\/li>\n<li>\u5b58\u50a8\u5728\u5806\u6808\u4e0a\u7684\u5178\u578b\u6570\u636e\u662f<strong>\u5c40\u90e8\u53d8\u91cf<\/strong>\uff08\u503c\u7c7b\u578b\u6216\u539f\u8bed\u3001\u539f\u8bed\u5e38\u91cf\uff09\u3001<strong>\u6307\u9488<\/strong>\u548c<strong>\u51fd\u6570\u5e27<\/strong>\u3002<\/li>\n<li>\u5728\u8fd9\u91cc\uff0c\u60a8\u5c06\u9047\u5230<strong>\u5806\u6808\u6ea2\u51fa\u9519\u8bef<\/strong>\uff0c\u56e0\u4e3a\u4e0e\u5806\u76f8\u6bd4\uff0c\u5806\u6808\u7684\u5927\u5c0f\u6709\u9650\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u591a\u6570\u8bed\u8a00<strong>\u6765\u8bf4\uff0c<\/strong>\u53ef\u4ee5\u5b58\u50a8\u5728\u5806\u6808\u4e0a\u7684\u503c<strong>\u5927\u5c0f<\/strong>\u90fd\u6709<strong>\u9650\u5236<\/strong>\u3002<\/li>\n<\/ul>\n<p>\u5806<\/p>\n<p>\u5806\u662f\u7528\u6765\u8fdb\u884c<strong>\u52a8\u6001\u5185\u5b58\u5206\u914d<\/strong>\u7684\uff0c\u4e0e\u6808\u4e0d\u540c\uff0c\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528<strong>\u6307\u9488<\/strong>\u67e5\u627e\u5806\u4e2d\u7684\u6570\u636e\uff08\u628a\u5b83\u60f3\u8c61\u6210\u4e00\u4e2a\u5927\u578b\u591a\u7ea7\u5e93 \uff09 \u3002<\/p>\n<ul>\n<li>\u5b83\u6bd4\u5806\u6808<strong>\u6162<\/strong>\uff0c\u56e0\u4e3a\u67e5\u627e\u6570\u636e\u7684\u8fc7\u7a0b\u66f4\u590d\u6742\uff0c\u4f46\u5b83\u53ef\u4ee5\u5b58\u50a8\u6bd4\u5806\u6808\u66f4\u591a\u7684\u6570\u636e\u3002<\/li>\n<li>\u8fd9\u610f\u5473\u7740<strong>\u52a8\u6001\u5927\u5c0f<\/strong>\u7684\u6570\u636e\u53ef\u4ee5\u5b58\u50a8\u5728\u8fd9\u91cc\u3002<\/li>\n<li>\u5806\u5728\u5e94\u7528\u7a0b\u5e8f\u7684\u7ebf\u7a0b\u4e4b\u95f4<strong>\u5171\u4eab<\/strong>\u3002<\/li>\n<li>\u7531\u4e8e\u5176\u52a8\u6001\u6027\u8d28\uff0c\u5806<strong>\u7ba1\u7406\u8d77\u6765\u66f4\u68d8\u624b<\/strong>\uff0c\u8fd9\u662f\u5927\u591a\u6570\u5185\u5b58\u7ba1\u7406\u95ee\u9898\u7684\u4ea7\u751f\u5730\uff0c\u4e5f\u662f\u8bed\u8a00\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\u89e3\u51b3\u65b9\u6848\u53d1\u6325\u4f5c\u7528\u7684\u5730\u65b9\u3002<\/li>\n<li>\u5b58\u50a8\u5728\u5806\u4e0a\u7684\u5178\u578b\u6570\u636e\u662f<strong>\u5168\u5c40\u53d8\u91cf<\/strong>\u3001<strong>\u5f15\u7528\u7c7b\u578b<\/strong>\uff08\u5982\u5bf9\u8c61\u3001\u5b57\u7b26\u4e32\u3001\u6620\u5c04\u548c\u5176\u4ed6\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff09\u3002<\/li>\n<li>\u5982\u679c\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u8bd5\u56fe\u4f7f\u7528\u6bd4\u5206\u914d<strong>\u7684<\/strong>\u5806\u66f4\u591a\u7684\u5185\u5b58\uff0c\u60a8\u5c06\u9047\u5230<strong>\u5185\u5b58\u9519\u8bef<\/strong>\uff08\u5c3d\u7ba1\u8fd9\u91cc\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u56e0\u7d20\u5728\u8d77\u4f5c\u7528\uff0c\u5982GC\uff0c\u538b\u7f29\uff09\u3002<\/li>\n<li>\u4e00\u822c\u6765\u8bf4\uff0c\u53ef\u4ee5\u5b58\u50a8\u5728\u5806\u4e0a\u7684\u503c\u7684\u5927\u5c0f<strong>\u6ca1\u6709\u9650\u5236<\/strong>\u3002\u5f53\u7136\uff0c\u5206\u914d\u7ed9\u5e94\u7528\u7a0b\u5e8f\u7684\u5185\u5b58\u4e0a\u9650\u662f\u5b58\u5728\u7684\u3002<\/li>\n<\/ul>\n<p>\u4e0e\u786c\u76d8\u9a71\u52a8\u5668\u4e0d\u540c\uff0cRAM\u4e0d\u662f\u65e0\u9650\u7684\u3002\u5982\u679c\u4e00\u4e2a\u7a0b\u5e8f\u5728\u4e0d\u91ca\u653e\u5185\u5b58\u7684\u60c5\u51b5\u4e0b\u7ee7\u7eed\u6d88\u8017\u5185\u5b58\uff0c\u6700\u7ec8\u5b83\u4f1a\u8017\u5c3d\u5185\u5b58\u5e76\u5d29\u6e83\uff0c\u751a\u81f3\u66f4\u7cdf\u5730\u5d29\u6e83\u64cd\u4f5c\u7cfb\u7edf\u3002\u56e0\u6b64\uff0c\u8f6f\u4ef6\u7a0b\u5e8f\u4e0d\u80fd\u968f\u5fc3\u6240\u6b32\u5730\u4f7f\u7528RAM\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u5bfc\u81f4\u5176\u4ed6\u7a0b\u5e8f\u548c\u8fdb\u7a0b\u8017\u5c3d\u5185\u5b58\u3002\u56e0\u6b64\uff0c\u5927\u591a\u6570\u7f16\u7a0b\u8bed\u8a00\u6ca1\u6709\u8ba9\u8f6f\u4ef6\u5f00\u53d1\u4eba\u5458\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u662f\u63d0\u4f9b\u4e86\u81ea\u52a8\u5185\u5b58\u7ba1\u7406\u7684\u65b9\u6cd5\u3002\u5f53\u6211\u4eec\u8c08\u8bba\u5185\u5b58\u7ba1\u7406\u65f6\uff0c\u6211\u4eec\u4e3b\u8981\u8c08\u8bba\u7684\u662f\u7ba1\u7406\u5806\u5185\u5b58\u3002<\/p>\n<p>\u5185\u5b58\u5206\u4e3a\u6808\u5b58\u50a8\u533a\u548c\u5806\u5b58\u50a8\u533a\uff0c\u6bcf\u4e2aGoroutine\uff08G\uff09\u6709\u4e00\u4e2a\u6808\u3002\u5728\u8fd9\u91cc\u5b58\u50a8\u4e86\u9759\u6001\u6570\u636e\uff0c\u5305\u62ec<strong>\u51fd\u6570\u6808\u5e27<\/strong>\uff0c<strong>\u9759\u6001\u7ed3\u6784<\/strong>\uff0c<strong>\u539f\u751f\u7c7b\u578b\u503c<\/strong>\u548c<strong>\u6307\u5411\u52a8\u6001\u7ed3\u6784\u7684\u6307\u9488<\/strong>\u3002\u8fd9\u4e0e\u5206\u914d\u7ed9\u6bcf\u4e2aP\u7684mcache\u4e0d\u662f\u4e00\u56de\u4e8b\u3002<\/p>\n<p>\u5185\u5b58\u7ba1\u7406\u5305\u62ec\u5728\u9700\u8981\u5185\u5b58\u65f6\u81ea\u52a8\u5206\u914d\uff0c\u4e0d\u9700\u8981\u5185\u5b58\u65f6\u8fdb\u884c\u5783\u573e\u56de\u6536\u3002\u8fd9\u662f\u6709\u6807\u51c6\u5e93\u5b8c\u6210\u7684\uff08runtime\u5305\uff09<\/p>\n<h3>\u5185\u5b58\u5206\u914d<\/h3>\n<p>\u6bcf\u4e2aGo\u7a0b\u5e8f\u8fdb\u7a0b\u90fd\u88ab\u64cd\u4f5c\u7cfb\u7edf\uff08OS\uff09\u5206\u914d\u4e86\u4e00\u4e9b\u865a\u62df\u5185\u5b58\uff0c\u8fd9\u662f\u8fdb\u7a0b\u53ef\u4ee5\u8bbf\u95ee\u7684\u603b\u5185\u5b58\u3002\u5728\u865a\u62df\u5185\u5b58\u4e2d\u4f7f\u7528\u7684\u5b9e\u9645\u5185\u5b58\u79f0\u4e3a<strong>\u5e38\u9a7b\u96c6<\/strong>\u3002\u8fd9\u4e2a\u7a7a\u95f4\u7531\u5185\u90e8\u5185\u5b58\u7ed3\u6784\u7ba1\u7406\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/wp_editor_md_d29e17ec6aa87252196e42f6cbb3d39f.jpg\" alt=\"\" \/><\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u57fa\u4e8eGo\u4f7f\u7528\u7684\u5185\u90e8\u5bf9\u8c61\u7684\u7b80\u5316\u89c6\u56fe\uff0c\u5b9e\u9645\u4e0a\uff0cGo\u5c06\u5185\u5b58\u5206\u5272\u548c\u5206\u7ec4\u4e3a\u9875\u9762<\/p>\n<p>\u6b63\u5982\u4f60\u6240\u770b\u5230\u7684\uff0c\u8fd9\u91cc\u6ca1\u6709\u4ee3\u9645\u8bb0\u5fc6\u3002\u9020\u6210\u8fd9\u79cd\u60c5\u51b5\u7684\u4e3b\u8981\u539f\u56e0\u662f<a class=\"wp-editor-md-post-content-link\" href=\"http:\/\/goog-perftools.sourceforge.net\/doc\/tcmalloc.html\"><strong>TCMalloc<\/strong><\/a>\uff08\u7ebf\u7a0b\u7f13\u5b58Maloc\uff09\uff0c\u8fd9\u662fGo\u81ea\u5df1\u7684\u5185\u5b58\u5206\u914d\u5668\u6240\u6a21\u4eff\u7684\u3002<\/p>\n<h4>Page Heap(mheap)<\/h4>\n<p>\u8fd9\u5c31\u662fGo\u5b58\u50a8\u52a8\u6001\u6570\u636e\u7684\u5730\u65b9\uff08\u4efb\u4f55\u5927\u5c0f\u7684\u6570\u636e\u5728\u7f16\u8bd1\u65f6\u65e0\u6cd5\u8ba1\u7b97\uff09\u3002\u8fd9\u662f\u6700\u5927\u7684\u5185\u5b58\u5757\uff0c\u4e5f\u662f<strong>\u5783\u573e\u6536\u96c6\uff08GC\uff09<\/strong>\u53d1\u751f\u7684\u5730\u65b9\u3002<\/p>\n<p>\u5e38\u9a7b\u96c6\u5206\u4e3a\u6bcf\u4e2a8KB\u7684\u9875\u9762\uff0c\u7531\u4e00\u4e2a\u5168\u5c40<code>mheap<\/code>\u5bf9\u8c61\u7ba1\u7406\u3002<\/p>\n<blockquote><p>\n  <em>\u5927\u5bf9\u8c61\uff08\u5927\u5c0f>32kb\u7684\u5bf9\u8c61\uff09\u76f4\u63a5\u4ece<\/em><code>mheap<\/code>*\u5206\u914d<strong>\u3002\u8fd9\u4e9b\u5927\u8bf7\u6c42\u662f\u4ee5\u727a\u7272\u4e2d\u592e\u9501\u4e3a\u4ee3\u4ef7\u7684\uff0c\u56e0\u6b64<\/strong>\u5728\u4efb\u4f55\u7ed9\u5b9a\u7684\u65f6\u95f4\u70b9\u53ea\u80fd\u6ee1\u8db3**\u4e00\u4e2a*<code>P<\/code>*\u7684\u8bf7\u6c42\u3002*\n<\/p><\/blockquote>\n<ul>\n<li><strong>mspan<\/strong>\uff1a<code>mspan<\/code>\u662f\u7ba1\u7406<code>mheap<\/code>\u5185\u5b58\u9875\u7684\u6700\u57fa\u672c\u7ed3\u6784\u3002\u8fd9\u662f\u4e00\u4e2a\u53cc\u94fe\u8868\uff0c\u5305\u542b\u8d77\u59cb\u9875\u9762\u7684\u5730\u5740\u3001\u8de8\u5ea6\u5927\u5c0f\u7c7b\u548c\u8de8\u5ea6\u4e2d\u7684\u9875\u9762\u6570\u91cf\u3002\u4e0eTCMalloc\u4e00\u6837\uff0cGo\u8fd8\u5c06\u5185\u5b58\u9875\u9762\u6309\u5927\u5c0f\u5206\u4e3a67\u4e2a\u4e0d\u540c\u7c7b\uff0c\u4ece8\u5b57\u8282\u523032\u5343\u5b57\u8282\u4e0d\u7b49\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/wp_editor_md_b5e584af3124b6aca7d68ba19fd3d018.jpg\" alt=\"\" \/><\/p>\n<p>\u6bcf\u4e2a\u8de8\u5ea6\u5b58\u5728\u4e24\u6b21\uff0c\u4e00\u4e2a\u7528\u4e8e\u6709\u6307\u9488\u7684\u5bf9\u8c61\uff08<strong>\u626b\u63cf<\/strong>\u7c7b\uff09\uff0c\u4e00\u4e2a\u7528\u4e8e\u6ca1\u6709\u6307\u9488\u7684\u5bf9\u8c61\uff08<strong><code>noscan<\/code><\/strong>\u7c7b\uff09\u3002\u8fd9\u5728GC\u671f\u95f4\u6709\u5e2e\u52a9\uff0c\u56e0\u4e3a<code>noscan<\/code>\u8de8\u5ea6\u4e0d\u9700\u8981\u904d\u5386\u6765\u67e5\u627e\u6d3b\u52a8\u5bf9\u8c61\u3002<\/p>\n<ul>\n<li><strong>mcentral<\/strong>\uff1a<code>mcentral<\/code>\u5c06\u76f8\u540c\u5927\u5c0f\u7c7b\u522b\u7684\u8de8\u5ea6\u7ec4\u5408\u5728\u4e00\u8d77\u3002\u6bcf\u4e2a<code>mcentral<\/code>\u5305\u542b\u4e24\u4e2a<code>mspanList<\/code>\uff1a<\/li>\n<li><strong>\u7a7a<\/strong>\uff1aspan \u7684\u53cc\u94fe\u8868\uff0c\u6ca1\u6709\u7a7a\u95f2\u5bf9\u8c61\u6216\u7f13\u5b58\u5728<code>mcache<\/code>. \u5f53\u8fd9\u91cc\u7684\u4e00\u4e2a\u8de8\u5ea6\u88ab\u91ca\u653e\u65f6\uff0c\u5b83\u88ab\u79fb\u52a8\u5230\u975e\u7a7a\u5217\u8868\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u975e\u7a7a<\/strong>\uff1a\u5177\u6709\u81ea\u7531\u5bf9\u8c61\u7684\u8de8\u5ea6\u53cc\u94fe\u8868\u3002\u5f53\u4ece \u8bf7\u6c42\u65b0\u7684\u8de8\u5ea6\u65f6<code>mcentral<\/code>\uff0c\u5b83\u4f1a\u4ece\u975e\u7a7a\u5217\u8868\u4e2d\u83b7\u53d6\u5b83\u5e76\u5c06\u5176\u79fb\u52a8\u5230\u7a7a\u5217\u8868\u4e2d\u3002<\/p>\n<p>\u5f53<code>mcentral<\/code>\u6ca1\u6709\u4efb\u4f55\u7a7a\u95f2\u8de8\u5ea6\u65f6\uff0c\u5b83\u4f1a\u4ece<code>mheap<\/code>\u83b7\u53d6<\/p>\n<\/li>\n<li>\n<p><strong>arena<\/strong>\uff1a\u5806\u5185\u5b58\u4e2d\u5206\u914d\u7684\u865a\u62df\u5185\u5b58\u4e2d\u6839\u636e\u9700\u8981\u589e\u957f\u548c\u6536\u7f29\u3002\u5f53\u9700\u8981\u66f4\u591a\u5185\u5b58\u65f6\uff0c<code>mheap<\/code>\u5c06\u5b83\u4eec\u4ece\u865a\u62df\u5185\u5b58\u4e2d\u63d0\u53d6\u4e3a 64MB\uff08\u5bf9\u4e8e 64 \u4f4d\u4f53\u7cfb\u7ed3\u6784\uff09\u7684\u5757\uff0c\u79f0\u4e3a<code>arena<\/code>. \u8fd9\u4e9b\u9875\u9762\u5728\u8fd9\u91cc\u6620\u5c04\u5230\u8de8\u5ea6\u3002<\/p>\n<\/li>\n<li><strong>mcache<\/strong>\uff1a\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u8da3\u7684\u6784\u9020\u3002<code>mcache<\/code>\u662f\u63d0\u4f9b\u7ed9<code>P<\/code>\uff08\u903b\u8f91\u5904\u7406\u5668\uff09\u7684\u5185\u5b58\u7f13\u5b58\uff0c\u7528\u4e8e\u5b58\u50a8\u5c0f\u5bf9\u8c61\uff08\u5bf9\u8c61\u5927\u5c0f &lt;= 32Kb\uff09\u3002\u867d\u7136\u8fd9\u7c7b\u4f3c\u4e8e\u7ebf\u7a0b\u5806\u6808\uff0c\u4f46\u5b83\u662f\u5806\u7684\u4e00\u90e8\u5206\uff0c\u7528\u4e8e\u52a8\u6001\u6570\u636e\u3002<code>mcache<\/code>\u5305\u542b<code>scan<\/code>\u548c\u6240\u6709\u7c7b\u5927\u5c0f\u7684<code>noscan<\/code>\u7c7b\u578b<code>mspan<\/code>\u3002Goroutines \u53ef\u4ee5\u5728<code>mcache<\/code>\u6ca1\u6709\u4efb\u4f55\u9501\u7684\u60c5\u51b5\u4e0b\u83b7\u53d6\u5185\u5b58\uff0c\u56e0\u4e3a\u4e00\u6b21<code>P<\/code>\u53ea\u80fd\u6709\u4e00\u4e2a<code>G<\/code>\u5728\u8fd0\u884c\u3002\u56e0\u6b64\uff0c\u8fd9\u66f4\u6709\u6548\u3002<code>mcache<\/code>\u4ece<code>mcentral<\/code>\u9700\u8981\u65f6\u8bf7\u6c42\u65b0\u7684\u8de8\u5ea6\u3002<\/li>\n<\/ul>\n<p><code>&lt;<\/code>16B<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/Kh26oVp.gif\" alt=\"\" \/><\/p>\n<p>16B~32KB<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/PY4pZhq.gif\" alt=\"\" \/><\/p>\n<p><code>&gt;<\/code>32KB<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/uLhLZMm.gif\" alt=\"\" \/><\/p>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.processon.com\/view\/link\/60df0205f346fb04d2d65b50\">\u5c0f\u77e5\u8bc6 tcmalloc\u5206\u914d\u7b97\u6cd5 (Thread Cache Malloc)<\/a><\/p>\n<h3>GC<\/h3>\n<p>gc\u6e05\u7406\u7684\u662f\u5806\u5185<\/p>\n<ol>\n<li>\u6211\u4eec\u6b63\u5728\u67e5\u770b\u5355\u4e2a Goroutine\uff0c\u5b9e\u9645\u8fc7\u7a0b\u4e3a\u6240\u6709\u6d3b\u52a8\u7684 Goroutine \u6267\u884c\u6b64\u64cd\u4f5c\u3002\u9996\u5148\u6253\u5f00\u5199\u5c4f\u969c\u3002<\/li>\n<li>\u6807\u8bb0\u8fc7\u7a0b\u9009\u62e9\u4e00\u4e2a GC \u6839\u5e76\u5c06\u5176\u7740\u8272\u4e3a\u9ed1\u8272\uff0c\u5e76\u4ee5\u6df1\u5ea6\u4f18\u5148\u7684\u6811\u72b6\u65b9\u5f0f\u4ece\u4e2d\u904d\u5386\u6307\u9488\uff0c\u5b83\u5c06\u9047\u5230\u7684\u6bcf\u4e2a\u5bf9\u8c61\u6807\u8bb0\u4e3a\u7070\u8272<\/li>\n<li>\u5f53\u5b83\u5728\u4e00\u4e2a<code>noscan<\/code>\u8303\u56f4\u5185\u5230\u8fbe\u4e00\u4e2a\u5bf9\u8c61\u6216\u8005\u5f53\u4e00\u4e2a\u5bf9\u8c61\u6ca1\u6709\u66f4\u591a\u7684\u6307\u9488\u65f6\uff0c\u5b83\u4f1a\u7ed3\u675f\u6839\u5e76\u62ff\u8d77\u4e0b\u4e00\u4e2a GC \u6839\u5bf9\u8c61<\/li>\n<li>\u4e00\u65e6\u626b\u63cf\u4e86\u6240\u6709 GC \u6839\uff0c\u5b83\u5c31\u4f1a\u9009\u62e9\u4e00\u4e2a\u7070\u8272\u5bf9\u8c61\u5e76\u7ee7\u7eed\u4ee5\u7c7b\u4f3c\u7684\u65b9\u5f0f\u904d\u5386\u5176\u6307\u9488<\/li>\n<li>\u5982\u679c\u5728\u5199\u5c4f\u969c\u6253\u5f00\u65f6\u6709\u4efb\u4f55\u6307\u5411\u5bf9\u8c61\u7684\u6307\u9488\u66f4\u6539\uff0c\u8be5\u5bf9\u8c61\u5c06\u53d8\u4e3a\u7070\u8272\uff0c\u4ee5\u4fbf GC \u91cd\u65b0\u626b\u63cf\u5b83<\/li>\n<li>\u5f53\u6ca1\u6709\u66f4\u591a\u7070\u8272\u5bf9\u8c61\u65f6\uff0c\u6807\u8bb0\u8fc7\u7a0b\u5b8c\u6210\u5e76\u5173\u95ed\u5199\u5c4f\u969c<\/li>\n<li>\u5206\u914d\u5f00\u59cb\u65f6\u5c06\u8fdb\u884c\u6e05\u626b<\/li>\n<\/ol>\n<p><a class=\"wp-editor-md-post-content-link\" href=\"https:\/\/www.processon.com\/view\/link\/60dd5a2ce401fd7e34279faa\">JVM GC<\/a><\/p>\n<h4>\u6839\u5bf9\u8c61<\/h4>\n<p>\u5728\u5783\u573e\u56de\u6536\u7684\u672f\u8bed\u4e2d\uff0c\u7531\u53eb\u505a\u6839\u96c6\u5408\u3002\u4ed6\u662f\u5783\u573e\u56de\u6536\u5668\u5728\u6807\u8bb0\u8fc7\u7a0b\u4e2d\u6700\u5148\u68c0\u67e5\u7684\u5bf9\u8c61\uff0c\u5305\u62ec\uff1a<\/p>\n<ol>\n<li>\u5168\u5c40\u53d8\u91cf\uff1a\u7a0b\u5e8f\u5728\u7f16\u8bd1\u671f\u5c31\u80fd\u786e\u5b9a\u7684\u54ea\u4e9b\u5b58\u5728\u4e8e\u7a0b\u5e8f\u6574\u4e2a\u751f\u547d\u5468\u671f\u7684\u53d8\u91cf<\/li>\n<li>\u6267\u884c\u6808\uff1a\u6bcf\u4e2agoroutine\u90fd\u5305\u542b\u81ea\u5df1\u7684\u6267\u884c\u6808\uff0c\u8fd9\u4e9b\u6267\u884c\u6808\u4e0a\u7684\u53d8\u91cf\u53ca\u6307\u5411\u5206\u914d\u7684\u5806\u5185\u5b58\u5757\u7684\u6307\u9488<\/li>\n<li>\u5bc4\u5b58\u5668\uff1a\u5bc4\u5b58\u5668\u7684\u503c\u53ef\u80fd\u8868\u793a\u4e00\u4e2a\u6307\u9488\uff0c\u53c2\u4e0e\u8ba1\u7b97\u7684\u8fd9\u4e9b\u6307\u9488\u53ef\u80fd\u6307\u5411\u67d0\u4e9b\u8d4b\u503c\u5668\u5206\u914d\u7684\u5806\u5185\u5b58\u533a\u5757<\/li>\n<\/ol>\n<h4>\u4e09\u8272\u6807\u8bb0\u6cd5<\/h4>\n<p>Golang\u7684GC\u7b97\u6cd5\u4e3b\u8981\u662f\u57fa\u4e8e<code>\u6807\u8bb0-\u6e05\u626b(mark and sweep)<\/code>\u7b97\u6cd5\uff0c\u5e76\u5728\u6b64\u57fa\u7840\u4e0a\u505a\u4e86\u6539\u8fdb\u3002<\/p>\n<p>\u6027\u80fd\u63d0\u5347\uff0c\u51cf\u5c11\u4e86STW\u65f6\u95f4\uff08stop the world\uff09<\/p>\n<p>\u975e\u5206\u4ee3\u7684\u3001\u975e\u79fb\u52a8\u7684\u3001\u5e76\u53d1\u7684\u3001\u4e09\u8272\u7684\u6807\u8bb0\u6e05\u9664\u5783\u573e\u6536\u96c6\u5668<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/oss.wyxxt.org.cn\/images\/2021\/09\/18\/2021-2-19T155548.gif\" alt=\"\" \/><\/p>\n<h4>go gc\u6d41\u7a0b<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u9636\u6bb5<\/th>\n<th>\u8bf4\u660e<\/th>\n<th>\u8d4b\u503c\u5668\u72b6\u6001<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>GCMark<\/td>\n<td>\u6807\u8bb0\u51c6\u5907\u9636\u6bb5\uff0c\u4e3a\u5e76\u53d1\u6807\u8bb0\u505a\u51c6\u5907\u5de5\u4f5c\uff0c\u542f\u52a8\u5199\u5c4f\u969c<\/td>\n<td>STW<\/td>\n<\/tr>\n<tr>\n<td>GCMark<\/td>\n<td>\u626b\u63cf\u6807\u8bb0\u9636\u6bb5\uff0c\u4e0e\u8d4b\u503c\u5668\u5e76\u53d1\u6267\u884c\uff0c\u5199\u5c4f\u969c\u5f00\u542f<\/td>\n<td>\u5e76\u53d1<\/td>\n<\/tr>\n<tr>\n<td>GCMark Termination<\/td>\n<td>\u6807\u8bb0\u7ec8\u6b62\u9636\u6bb5\uff0c\u4fdd\u8bc1\u4e00\u4e2a\u5468\u671f\u5185\u6807\u8bb0\u4efb\u52a1\u5b8c\u6210\uff0c\u505c\u6b62\u5199\u5c4f\u969c<\/td>\n<td>STW<\/td>\n<\/tr>\n<tr>\n<td>GCoff<\/td>\n<td>\u5185\u5b58\u6e05\u626b\u9636\u6bb5\uff0c\u5c06\u9700\u8981\u56de\u6536\u7684\u5185\u5b58\u5f52\u8fd8\u5230\u5806\u4e2d\uff0c\u5199\u5c4f\u969c\u5173\u95ed<\/td>\n<td>\u5e76\u53d1<\/td>\n<\/tr>\n<tr>\n<td>GCoff<\/td>\n<td>\u5185\u5b58\u5f52\u8fd8\u9636\u6bb5\uff0c\u5c06\u8fc7\u591a\u7684\u5185\u5b58\u5f52\u8fd8\u7ed9\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5199\u5c4f\u969c\u5173\u95ed<\/td>\n<td>\u5e76\u53d1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u6df7\u5408\u5199\u5c4f\u969c\uff08hybrid write barrier\uff09<\/h4>\n<p>\u7531\u4e8e\u6807\u8bb0\u64cd\u4f5c\u548c\u7528\u6237\u903b\u8f91\u662f\u5e76\u53d1\u6267\u884c\u7684\uff0c\u7528\u6237\u903b\u8f91\u4f1a\u65f6\u5e38\u751f\u6210\u5bf9\u8c61\u6216\u8005\u6539\u53d8\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u4f8b\u5982\u628a\u2f00\u4e2a\u5bf9\u8c61\u6807\u8bb0\u4e3a\u767d\u8272\u51c6\u5907\u56de\u6536\u65f6\uff0c\u7528\u6237\u903b\u8f91\u7a81\u7136\u5f15\u7528\u4e86\u5b83\uff0c\u6216\u8005\u53c8\u521b\u5efa\u4e86\u65b0\u7684\u5bf9\u8c61\u3002\u7531\u4e8e\u5bf9\u8c61\u521d\u59cb\u65f6\u90fd\u770b\u4e3a\u767d\u8272\uff0c\u4f1a\u88ab GC \u56de\u6536\u6389\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u5f15\u5165\u4e86\u5199\u5c4f\u969c\u673a\u5236\u3002<\/p>\n<p>GC \u5bf9\u626b\u63cf\u8fc7\u540e\u7684\u5bf9\u8c61\u4f7f\u2f64\u64cd\u4f5c\u7cfb\u7edf\u5199\u5c4f\u969c\u529f\u80fd\u6765\u76d1\u63a7\u8fd9\u6bb5\u5185\u5b58\u3002\u5982\u679c\u8fd9\u6bb5\u5185\u5b58\u53d1\u2f63\u5f15\u2f64\u6539\u53d8\uff0c\u5199\u5c4f\u969c\u4f1a\u7ed9\u5783\u573e\u56de\u6536\u5668\u53d1\u9001\u2f00\u4e2a\u4fe1\u53f7\uff0c\u5783\u573e\u56de\u6536\u5668\u6355\u83b7\u5230\u4fe1\u53f7\u540e\u5c31\u77e5\u9053\u8fd9\u4e2a\u5bf9\u8c61\u53d1\u2f63\u6539\u53d8\uff0c\u7136\u540e\u91cd\u65b0\u626b\u63cf\u8fd9\u4e2a\u5bf9\u8c61\uff0c\u770b\u770b\u5b83\u7684\u5f15\u2f64\u6216\u8005\u88ab\u5f15\u2f64\u662f\u5426\u6539\u53d8\u3002\u5229\u2f64\u72b6\u6001\u7684\u91cd\u7f6e\u5b9e\u73b0\u5f53\u5bf9\u8c61\u72b6\u6001\u53d1\u2f63\u6539\u53d8\u7684\u65f6\u5019\uff0c\u4f9d\u7136\u53ef\u4ee5\u518d\u6b21\u5176\u5f15\u7528\u7684\u5bf9\u8c61\u3002<\/p>\n<h4>go gc\u603b\u7ed3<\/h4>\n<p>\u65e0\u5206\u4ee3\u3001\u4e0d\u6574\u7406\u3001\u5e76\u53d1\u7684\u4e09\u8272\u6807\u8bb0\u6cd5<\/p>\n<ol>\n<li>\u5bf9\u8c61\u6574\u7406\u76ee\u7684\uff1a\u662f\u89e3\u51b3\u5185\u5b58\u788e\u7247\u95ee\u9898\uff0c\u4f46\u662fGo\u7ed9\u4e88tcmalloc\u5206\u914d\u7b97\u6cd5\uff0c\u57fa\u672c\u6ca1\u6709\u788e\u7247\u95ee\u9898\u3002<br \/>\n\u53e6\u5916\u987a\u5e8f\u5185\u5b58\u5206\u914d\u5668\u5728\u591a\u7ebf\u7a0b\u5e76\u4e0d\u9002\u7528\uff0c\u6574\u7406\u5185\u5b58\u5bf9tcmalloc\u5206\u914d\u6ca1\u6709\u5b9e\u8d28\u63d0\u5347<\/li>\n<li>\u5206\u4ee3GC\u76ee\u6807\u4e3b\u8981\u662f\u9488\u5bf9\u65b0\u521b\u5efa\u5bf9\u8c61\uff0c\u4e0d\u4f1a\u9891\u7e41\u68c0\u67e5\u6240\u6709\u5bf9\u8c61\u3002\u4f46\u662fGo\u4f1a\u901a\u8fc7\u9003\u9038\u5206\u6790\u5c06\u5927\u90e8\u5206\u201c\u65b0\u751f\u201d\u5bf9\u8c61\u5b58\u50a8\u5728\u6808\u4e0a\uff0c\u9700\u8981\u957f\u671f\u4fdd\u5b58\u7684\u5bf9\u8c61\u5b58\u5728\u4e8e\u5806\u4e2d\u3002\u6808\u4f1a\u88ab\u56de\u6536\uff0c\u4e0d\u9700\u8981GC\u3002<br \/>\nGo\u7684GC\u66f4\u4e13\u6ce8\u4e8e\u5982\u4f55\u8ba9GC\u548c\u7528\u6237\u4ee3\u7801\u5e76\u53d1\u6267\u884c\uff0c\u4e13\u6ce8\u4e8e\u51cf\u5c11STW\u65f6\u95f4<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u6307\u9488 go\u8bed\u8a00\u6ca1\u6709\u6307\u9488\u8fd0\u7b97 &amp; \u53d6\u5730\u5740\u7b26 *\u6307\u9488\u53ef\u4ee5\u6307\u5411\u4efb\u4f55\u7c7b\u578b \u4ee5\u4e0b\u9762\u4ee3\u7801\u4e3a\u4f8b\uff0c\u6307\u9488\u6307\u5411int\u7c7b\u578b  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[15],"tags":[398],"class_list":["post-3533","post","type-post","status-publish","format-standard","hentry","category-15","tag-go"],"_links":{"self":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3533"}],"version-history":[{"count":3,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3533\/revisions"}],"predecessor-version":[{"id":3635,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=\/wp\/v2\/posts\/3533\/revisions\/3635"}],"wp:attachment":[{"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wyxxt.org.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}