{"id":608,"date":"2026-07-01T00:45:02","date_gmt":"2026-06-30T16:45:02","guid":{"rendered":"https:\/\/cococat.top\/?p=608"},"modified":"2026-07-01T00:45:02","modified_gmt":"2026-06-30T16:45:02","slug":"rust-%e7%ac%94%e8%ae%b0-10%ef%bc%9aglibc-ptmalloc2-arena-%e7%a2%8e%e7%89%87%e5%8c%96","status":"publish","type":"post","link":"https:\/\/cococat.top\/index.php\/2026\/07\/01\/rust-%e7%ac%94%e8%ae%b0-10%ef%bc%9aglibc-ptmalloc2-arena-%e7%a2%8e%e7%89%87%e5%8c%96\/","title":{"rendered":"Rust \u7b14\u8bb0 10\uff1aglibc ptmalloc2 Arena \u788e\u7247\u5316"},"content":{"rendered":"<h2>\u4e00\u3001\u95ee\u9898\u80cc\u666f<\/h2>\n<p>\u67d0\u957f\u671f\u8fd0\u884c\u7684 Rust \u5f02\u6b65\u670d\u52a1\u5b9e\u4f8b RSS \u8fbe\u5230 9GB\uff0c\u8fdc\u8d85\u6b63\u5e38\u6c34\u4f4d\u3002\u8be5\u670d\u52a1\u57fa\u4e8e Tokio \u5f02\u6b65\u8fd0\u884c\u65f6\uff0c\u90e8\u7f72\u5728\u5bb9\u5668\u73af\u5883\u4e2d\u3002<\/p>\n<h2>\u4e8c\u3001\u6392\u67e5\u8fc7\u7a0b<\/h2>\n<h3>2.1 \u4ee3\u7801\u5c42\u9762\u68b3\u7406<\/h3>\n<p>\u901a\u8fc7\u4ee3\u7801\u5ba1\u67e5\uff0c\u5148\u68b3\u7406\u670d\u52a1\u4e2d\u53ef\u80fd\u5360\u7528\u8f83\u591a\u5185\u5b58\u7684\u5bf9\u8c61\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5168\u5c40\u7f13\u5b58\u4e2d\u7684\u4e1a\u52a1\u6570\u636e<\/li>\n<li>\u6587\u4ef6\u6620\u5c04\u578b\u53ea\u8bfb\u6570\u636e\uff08\u5927\u6570\u636e\u6587\u4ef6 mmap\uff09<\/li>\n<\/ul>\n<p>\u7ecf\u5206\u6790\u8fd9\u4e9b\u90fd\u4e0d\u8db3\u4ee5\u89e3\u91ca 9GB RSS\u3002\u6587\u4ef6\u6620\u5c04\u578b\u53ea\u8bfb\u6570\u636e\u540e\u7eed\u4e5f\u901a\u8fc7 <code>Pss_File<\/code> \u8fdb\u4e00\u6b65\u6392\u9664\u3002<\/p>\n<h3>2.2 smaps_rollup \u5168\u5c40\u6982\u89c8<\/h3>\n<h4>\u547d\u4ee4\u4e0e\u539f\u7406<\/h4>\n<pre><code class=\"language-bash\">cat \/proc\/&lt;pid&gt;\/smaps_rollup<\/code><\/pre>\n<p><code>smaps_rollup<\/code> \u662f <code>\/proc\/&lt;pid&gt;\/smaps<\/code> \u7684\u805a\u5408\u7248\u672c\uff08Linux 4.14+\uff09\uff0c\u5c06\u8fdb\u7a0b\u6240\u6709\u865a\u62df\u5185\u5b58\u533a\u57df\uff08VMA\uff09\u7684\u6307\u6807\u7d2f\u52a0\u6210\u4e00\u4efd\u6c47\u603b\u3002\u76f8\u6bd4\u9010\u6bb5\u904d\u5386 smaps \u7684\u4e0a\u5343\u884c\u8f93\u51fa\uff0crollup \u4e00\u6b21\u8bfb\u53d6\u5373\u53ef\u83b7\u5f97\u8fdb\u7a0b\u5185\u5b58\u5168\u8c8c\uff0c\u6027\u80fd\u5f00\u9500\u6781\u5c0f\uff0c\u9002\u5408\u4f5c\u4e3a\u6392\u67e5\u7684\u7b2c\u4e00\u6b65\u3002<\/p>\n<p>\u6838\u5fc3\u5b57\u6bb5\u542b\u4e49\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b57\u6bb5<\/th>\n<th>\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Rss<\/td>\n<td>\u5e38\u9a7b\u7269\u7406\u5185\u5b58\uff0c\u542b\u5171\u4eab\u90e8\u5206<\/td>\n<\/tr>\n<tr>\n<td>Pss<\/td>\n<td>\u6309\u6bd4\u4f8b\u5747\u644a\u5171\u4eab\u9875\u540e\u7684\u771f\u5b9e\u5360\u7528<\/td>\n<\/tr>\n<tr>\n<td>Pss_Anon<\/td>\n<td>\u533f\u540d\u9875\uff08\u5806\u5206\u914d\uff09\u7684 Pss<\/td>\n<\/tr>\n<tr>\n<td>Pss_File<\/td>\n<td>\u6587\u4ef6\u6620\u5c04\u9875\u7684 Pss\uff08mmap \u7684\u6587\u4ef6\u4f1a\u4f53\u73b0\u5728\u6b64\uff09<\/td>\n<\/tr>\n<tr>\n<td>Private_Dirty<\/td>\n<td>\u79c1\u6709\u810f\u9875\uff0c\u8fdb\u7a0b\u81ea\u5df1\u5199\u5165\u7684\u5806\u5185\u5b58<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u5b9e\u9645\u8f93\u51fa<\/h4>\n<pre><code>Rss:             9256116 kB\nPss_Anon:        9234168 kB\nPss_File:          16698 kB\nPrivate_Dirty:   9234168 kB<\/code><\/pre>\n<h4>\u7ed3\u8bba<\/h4>\n<ul>\n<li>99.7% \u5185\u5b58\u662f <strong>Anonymous Private Dirty<\/strong>\uff08\u533f\u540d\u79c1\u6709\u810f\u9875\uff09 \u2192 \u5168\u90e8\u6765\u81ea\u5806\u5206\u914d\uff08malloc\/alloc\uff09<\/li>\n<li>Pss_File \u4ec5 16MB \u2192 \u6392\u9664\u6587\u4ef6\u6620\u5c04\u578b\u53ea\u8bfb\u6570\u636e<\/li>\n<li>9GB \u7eaf\u5806\u5185\u5b58\u5bf9\u8be5\u670d\u52a1\u4e0d\u6b63\u5e38\uff0c\u6b63\u5e38\u6570\u636e\u7ed3\u6784\u603b\u8ba1\u4e0d\u8d85\u8fc7\u51e0\u767e MB<\/li>\n<\/ul>\n<h3>2.3 smaps \u6bb5\u7ea7\u5b9a\u4f4d<\/h3>\n<h4>\u547d\u4ee4\u4e0e\u539f\u7406<\/h4>\n<pre><code class=\"language-bash\">cat \/proc\/&lt;pid&gt;\/smaps | awk &#039;\/^[0-9a-f]\/{addr=$1} \/Rss\/{if($2&gt;100000) print addr, $2 &quot;kB&quot;}&#039;<\/code><\/pre>\n<p><code>\/proc\/&lt;pid&gt;\/smaps<\/code> \u4e3a\u6bcf\u4e2a VMA \u6bb5\u63d0\u4f9b\u72ec\u7acb\u7684\u6307\u6807\u8282\u3002\u4e0a\u8ff0 awk \u547d\u4ee4\u63d0\u53d6\u6240\u6709 RSS &gt; 100MB \u7684\u6bb5\uff0c\u5e2e\u52a9\u8bc6\u522b\u5927\u5185\u5b58\u5757\u7684\u5206\u5e03\u6a21\u5f0f\u3002<\/p>\n<p>\u6bcf\u6bb5\u9996\u884c\u683c\u5f0f\u4e3a <code>\u8d77\u59cb\u5730\u5740-\u7ed3\u675f\u5730\u5740 \u6743\u9650 \u504f\u79fb \u8bbe\u5907 inode \u8def\u5f84<\/code>\uff0c\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>\u8def\u5f84\u4e3a\u7a7a \u2192 \u533f\u540d\u6620\u5c04\uff08\u5806\u3001mmap(MAP_ANONYMOUS)\uff09<\/li>\n<li>\u8def\u5f84\u4e3a <code>.so<\/code> \u2192 \u5171\u4eab\u5e93<\/li>\n<li>\u8def\u5f84\u4e3a\u6587\u4ef6 \u2192 \u6587\u4ef6\u6620\u5c04<\/li>\n<\/ul>\n<h4>\u5b9e\u9645\u8f93\u51fa\uff08\u8282\u9009\uff09<\/h4>\n<pre><code>558d2284d000-558d2ab32000 125200kB\n7f4204000000-7f420c000000 131072kB\n7f420c000000-7f4214000000 131072kB\n7f4220000000-7f4228000000 131072kB\n...\uff08\u5171 52+ \u4e2a\u7c7b\u4f3c\u6bb5\uff09<\/code><\/pre>\n<h4>\u7ed3\u8bba<\/h4>\n<p><strong>52+ \u4e2a 128MB\uff08131072kB\uff09\u5bf9\u9f50\u7684\u533f\u540d\u6bb5<\/strong>\uff0c\u8fd9\u662f glibc ptmalloc2 arena \u7684\u5178\u578b\u6307\u7eb9\uff1a<\/p>\n<ul>\n<li>\u6bcf\u4e2a arena \u5728 64 \u4f4d\u7cfb\u7edf\u4e0a\u4ee5 128MB \u4e3a\u5355\u4f4d mmap<\/li>\n<li>\u6bb5\u5730\u5740\u5728 <code>7fXX_X000_0000<\/code> \u533a\u95f4\uff0c\u4e3a mmap \u533a\u57df<\/li>\n<li>\u5168\u90e8\u662f\u533f\u540d\u6620\u5c04\uff08\u65e0\u5173\u8054\u6587\u4ef6\u8def\u5f84\uff09<\/li>\n<\/ul>\n<h3>2.4 \u9a8c\u8bc1\uff1agdb + malloc_trim<\/h3>\n<pre><code class=\"language-bash\"># \u8bb0\u5f55\u524d\ngrep -E &#039;^(VmRSS|RssAnon)&#039; \/proc\/&lt;pid&gt;\/status\n\n# \u5f3a\u5236\u5f52\u8fd8\u7a7a\u95f2\u9875\ngdb -p &lt;pid&gt; -batch -ex &#039;call (int)malloc_trim(0)&#039; -ex &#039;detach&#039;\n\n# \u8bb0\u5f55\u540e\ngrep -E &#039;^(VmRSS|RssAnon)&#039; \/proc\/&lt;pid&gt;\/status<\/code><\/pre>\n<p><code>malloc_trim(0)<\/code> \u4f1a\u904d\u5386\u6240\u6709 arena\uff0c\u5bf9\u5df2 free \u4f46\u672a\u5f52\u8fd8 OS \u7684\u9875\u9762\u8c03\u7528 <code>madvise(MADV_DONTNEED)<\/code>\u3002<\/p>\n<p><strong>\u7ed3\u679c\uff1aRSS \u5927\u5e45\u4e0b\u964d<\/strong>\uff0c\u786e\u8ba4\u662f glibc \u4fdd\u7559\u4e86\u5927\u91cf\u5df2\u91ca\u653e\u5185\u5b58\u672a\u5f52\u8fd8\u64cd\u4f5c\u7cfb\u7edf\u3002<\/p>\n<p>\u6ce8\u610f\uff1a<code>gdb -p<\/code> \u4f1a\u77ed\u6682\u505c\u987f\u76ee\u6807\u8fdb\u7a0b\uff0c\u5efa\u8bae\u53ea\u5728\u6d4b\u8bd5\u73af\u5883\u3001\u4f4e\u5cf0\u7a97\u53e3\u6216\u53ef\u63a5\u53d7\u77ed\u6682\u505c\u987f\u7684\u5b9e\u4f8b\u4e0a\u6267\u884c\u3002<\/p>\n<h2>\u4e09\u3001\u6839\u56e0\u5206\u6790<\/h2>\n<h3>3.1 glibc ptmalloc2 Arena \u673a\u5236<\/h3>\n<p>glibc \u7684 malloc \u5b9e\u73b0\uff08ptmalloc2\uff09\u4e3a\u51cf\u5c11\u591a\u7ebf\u7a0b\u9501\u4e89\u7528\uff0c\u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u5206\u914d\u72ec\u7acb\u7684 arena\uff1a<\/p>\n<ul>\n<li><strong>arena \u6570\u91cf<\/strong>\uff1a\u9ed8\u8ba4 <code>MALLOC_ARENA_MAX = 8 \u00d7 get_nprocs()<\/code><\/li>\n<li><strong>arena \u5927\u5c0f<\/strong>\uff1a\u6bcf\u4e2a arena \u901a\u8fc7 <code>mmap(MAP_ANONYMOUS)<\/code> \u5206\u914d 128MB \u865a\u62df\u7a7a\u95f4<\/li>\n<li><strong>\u5185\u5b58\u5f52\u8fd8\u6761\u4ef6<\/strong>\uff1a<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>\u6761\u4ef6<\/th>\n<th>\u662f\u5426\u81ea\u52a8\u89e6\u53d1<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>main arena \u9876\u90e8\u8fde\u7eed\u7a7a\u95f2 &gt; 128KB<\/td>\n<td>\u662f\uff08sbrk \u6536\u7f29\uff09<\/td>\n<\/tr>\n<tr>\n<td>\u67d0\u4e2a mmap'd arena <strong>\u6574\u6bb5 100%<\/strong> \u7a7a\u95f2<\/td>\n<td>\u662f\uff08munmap\uff09<\/td>\n<\/tr>\n<tr>\n<td>arena \u5185\u90e8\u6709\u6563\u843d\u7a7a\u95f2\u9875<\/td>\n<td><strong>\u4e0d\u89e6\u53d1<\/strong><\/td>\n<\/tr>\n<tr>\n<td>\u663e\u5f0f\u8c03\u7528 malloc_trim(0)<\/td>\n<td>\u624b\u52a8\u89e6\u53d1 madvise<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5173\u952e\u70b9\uff1a<strong>glibc \u5728\u6b63\u5e38 free() \u8def\u5f84\u4e2d\u4e0d\u4f1a\u8c03\u7528 madvise<\/strong>\u3002\u7a7a\u95f2\u5185\u5b58\u7559\u5728 arena free list \u4e2d\u7b49\u5f85\u590d\u7528\uff0c\u800c\u975e\u5f52\u8fd8 OS\u3002\u8fd9\u662f\u8bbe\u8ba1\u4e0a\u7684\u53d6\u820d\u2014\u2014\u907f\u514d\u9891\u7e41\u7cfb\u7edf\u8c03\u7528\uff0c\u4f46\u5bf9\u957f\u671f\u8fd0\u884c\u670d\u52a1\u9020\u6210\u5185\u5b58\u81a8\u80c0\u3002<\/p>\n<h3>3.2 Tokio \u5f02\u6b65\u8fd0\u884c\u65f6\u52a0\u5267\u788e\u7247\u5316<\/h3>\n<pre><code>Thread A (worker-1): malloc \u2192 \u5206\u914d\u5230 Arena #3\n         \u2193 task work-stealing\nThread B (worker-4): free \u2192 \u5f52\u8fd8\u5230 Arena #3 \u7684 free list\n         \u2191 \u4f46 Arena #3 \u91cc\u6563\u843d\u7740\u5176\u4ed6\u6d3b\u8dc3\u5bf9\u8c61\n         \u2192 128MB \u6bb5\u65e0\u6cd5 munmap\n         \u2192 \u7a7a\u95f2\u9875\u4e5f\u4e0d\u4f1a madvise \u5f52\u8fd8<\/code><\/pre>\n<p>Tokio \u7684 work-stealing \u8c03\u5ea6\u5668\u4f7f\u5f97\uff1a<\/p>\n<ol>\n<li>Task \u5728\u7ebf\u7a0b A \u5206\u914d\u5185\u5b58\uff0c\u88ab\u5077\u5230\u7ebf\u7a0b B \u540e\u91ca\u653e \u2192 \u8de8 arena \u788e\u7247<\/li>\n<li>\u5404 arena \u5185\u90e8\u4ea4\u9519\u5b58\u5728\u6d3b\u8dc3\u548c\u7a7a\u95f2\u5bf9\u8c61 \u2192 \u6574\u6bb5\u65e0\u6cd5\u56de\u6536<\/li>\n<li>\u957f\u671f\u8fd0\u884c\u540e\uff0c\u6bcf\u4e2a arena \u90fd&quot;\u81a8\u80c0&quot;\u5230 128MB \u4f46\u5b9e\u9645\u5229\u7528\u7387\u5f88\u4f4e<\/li>\n<\/ol>\n<h3>3.3 \u5bb9\u5668\u5316\u573a\u666f\u7684\u989d\u5916\u653e\u5927<\/h3>\n<p>glibc <code>get_nprocs()<\/code> \u7528\u4e8e\u8ba1\u7b97 <code>MALLOC_ARENA_MAX<\/code> \u9ed8\u8ba4\u503c\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>glibc \u7248\u672c<\/th>\n<th>\u884c\u4e3a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>&lt; 2.33<\/td>\n<td>\u8bfb <code>\/proc\/cpuinfo<\/code>\uff08\u5bbf\u4e3b\u673a\uff09\uff0c<strong>\u4e0d\u611f\u77e5 cgroup<\/strong><\/td>\n<\/tr>\n<tr>\n<td>&gt;= 2.33<\/td>\n<td>\u8bfb cgroup v1\/v2 CPU quota\uff1b\u4f46\u4ec5\u8bbe <code>cpuset.cpus<\/code> \u65e0 quota \u65f6\u4ecd\u8bfb\u5bbf\u4e3b\u673a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f8b\uff1a\u5bbf\u4e3b\u673a 64 \u6838\u3001\u5bb9\u5668\u9650 4 \u6838 \u2192 arena max = 8 \u00d7 64 = 512\uff0c\u8fdc\u8d85\u5b9e\u9645\u9700\u8981\u3002<\/p>\n<p>\u9a8c\u8bc1\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-bash\">ldd --version                              # glibc \u7248\u672c\nnproc                                      # \u5bb9\u5668\u611f\u77e5\u7684\u6838\u6570\ncat \/sys\/fs\/cgroup\/cpu\/cpu.cfs_quota_us    # cgroup v1 quota\ncat \/sys\/fs\/cgroup\/cpu.max                 # cgroup v2<\/code><\/pre>\n<h2>\u56db\u3001\u89e3\u51b3\u65b9\u6848<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u65b9\u6848<\/th>\n<th>\u505a\u6cd5<\/th>\n<th>\u4f18\u70b9<\/th>\n<th>\u7f3a\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u5207 jemalloc<\/strong>\uff08\u63a8\u8350\uff09<\/td>\n<td>Cargo.toml \u52a0 <code>tikv-jemallocator<\/code>\uff0cmain.rs \u8bbe <code>#[global_allocator]<\/code><\/td>\n<td>\u6839\u6cbb\uff1b\u81ea\u5e26 decay \u673a\u5236 10s \u81ea\u52a8\u5f52\u8fd8\u7a7a\u95f2\u9875<\/td>\n<td>\u9700\u6539\u4ee3\u7801\u53d1\u7248<\/td>\n<\/tr>\n<tr>\n<td>\u5b9a\u671f malloc_trim<\/td>\n<td>tokio spawn \u540e\u53f0 task \u6bcf\u51e0\u5206\u949f\u8c03\u7528 <code>libc::malloc_trim(0)<\/code><\/td>\n<td>\u4e0d\u6539 allocator<\/td>\n<td>\u6cbb\u6807\uff1btrim \u65f6\u6709\u77ed\u6682 CPU \u5f00\u9500<\/td>\n<\/tr>\n<tr>\n<td>MALLOC_ARENA_MAX \u73af\u5883\u53d8\u91cf<\/td>\n<td>\u542f\u52a8\u65f6 <code>export MALLOC_ARENA_MAX=4<\/code><\/td>\n<td>\u65e0\u9700\u6539\u4ee3\u7801\uff0c\u7acb\u5373\u751f\u6548<\/td>\n<td>\u53ef\u80fd\u5f71\u54cd\u9ad8\u5e76\u53d1\u4e0b malloc \u541e\u5410<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>jemalloc \u63a5\u5165\u793a\u4f8b<\/h3>\n<pre><code class=\"language-toml\"># Cargo.toml\n[dependencies]\ntikv-jemallocator = &quot;0.6&quot;<\/code><\/pre>\n<pre><code class=\"language-rust\">\/\/ main.rs \u9876\u90e8\n#[global_allocator]\nstatic GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;<\/code><\/pre>\n<p>jemalloc \u4f18\u52bf\uff1a<\/p>\n<ul>\n<li><strong>background_thread<\/strong>\uff1a\u540e\u53f0\u7ebf\u7a0b\u81ea\u52a8\u6267\u884c dirty page decay<\/li>\n<li><strong>per-CPU cache<\/strong>\uff1a\u51cf\u5c11\u8de8\u7ebf\u7a0b\u4e89\u7528<\/li>\n<li><strong>page run \u673a\u5236<\/strong>\uff1a\u66f4\u79ef\u6781\u5730\u5408\u5e76\u7a7a\u95f2\u533a\u57df\u5e76\u5f52\u8fd8 OS<\/li>\n<\/ul>\n<p>\u5982\u679c\u77ed\u671f\u5185\u65e0\u6cd5\u53d1\u7248\uff0c\u53ef\u4ee5\u5148\u901a\u8fc7 <code>MALLOC_ARENA_MAX<\/code> \u9650\u5236 arena \u6570\u91cf\uff0c\u6216\u5728\u53ef\u63a7\u7a97\u53e3\u8c03\u7528 <code>malloc_trim(0)<\/code> \u4f5c\u4e3a\u4e34\u65f6\u6b62\u8840\u65b9\u6848\u3002\u957f\u671f\u5efa\u8bae\u5207\u6362\u5230\u66f4\u9002\u5408\u957f\u751f\u547d\u5468\u671f\u670d\u52a1\u7684 allocator\u3002<\/p>\n<h2>\u4e94\u3001\u8bca\u65ad\u5de5\u5177\u901f\u67e5<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u5de5\u5177<\/th>\n<th>\u7528\u9014<\/th>\n<th>\u547d\u4ee4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>smaps_rollup<\/td>\n<td>\u5185\u5b58\u603b\u89c8\uff08\u9996\u9009\uff09<\/td>\n<td><code>cat \/proc\/&lt;pid&gt;\/smaps_rollup<\/code><\/td>\n<\/tr>\n<tr>\n<td>smaps + awk<\/td>\n<td>\u6bb5\u7ea7\u5b9a\u4f4d\u5927\u5185\u5b58\u5757<\/td>\n<td><code>cat \/proc\/&lt;pid&gt;\/smaps \\| awk &#039;...&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td>gdb + malloc_trim<\/td>\n<td>\u9a8c\u8bc1 arena \u4fdd\u7559<\/td>\n<td><code>gdb -p &lt;pid&gt; -batch -ex &#039;call (int)malloc_trim(0)&#039;<\/code><\/td>\n<\/tr>\n<tr>\n<td>glibc \u7248\u672c<\/td>\n<td>\u786e\u8ba4 arena \u884c\u4e3a<\/td>\n<td><code>ldd --version<\/code><\/td>\n<\/tr>\n<tr>\n<td>cgroup \u611f\u77e5\u6838\u6570<\/td>\n<td>\u786e\u8ba4\u5bb9\u5668\u662f\u5426\u6b63\u786e\u9650\u5236<\/td>\n<td><code>nproc<\/code> + cgroup \u6587\u4ef6<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u516d\u3001\u7ed3\u8bba<\/h2>\n<ul>\n<li><strong>\u6839\u56e0<\/strong>\uff1aglibc ptmalloc2 \u5728 Tokio \u591a\u7ebf\u7a0b + \u5bb9\u5668\u5316\u573a\u666f\u4e0b\uff0c\u521b\u5efa\u4e86\u8fc7\u591a arena\uff0852+\uff09\uff0c\u4e14\u7a7a\u95f2\u5185\u5b58\u4e0d\u4e3b\u52a8\u5f52\u8fd8 OS\uff0c\u5bfc\u81f4 RSS \u6301\u7eed\u81a8\u80c0\u5230 9GB<\/li>\n<li><strong>\u9a8c\u8bc1<\/strong>\uff1a<code>malloc_trim(0)<\/code> \u540e RSS \u5927\u5e45\u4e0b\u964d\uff0c\u786e\u8ba4\u5185\u5b58\u5e76\u975e\u771f\u6b63\u6cc4\u6f0f\uff0c\u800c\u662f allocator \u4fdd\u7559<\/li>\n<li><strong>\u65b9\u6848<\/strong>\uff1a\u5207\u6362 jemalloc \u4ece\u6839\u672c\u4e0a\u89e3\u51b3\uff0c\u5176 decay \u673a\u5236\u786e\u4fdd\u7a7a\u95f2\u9875\u81ea\u52a8\u5f52\u8fd8<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u95ee\u9898\u80cc\u666f \u67d0\u957f\u671f\u8fd0\u884c\u7684 Rust \u5f02\u6b65\u670d\u52a1\u5b9e\u4f8b RSS \u8fbe\u5230 9GB\uff0c\u8fdc\u8d85\u6b63\u5e38\u6c34\u4f4d\u3002\u8be5\u670d\u52a1\u57fa\u4e8e Tokio [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38,5,8],"tags":[39,20,24,29],"class_list":["post-608","post","type-post","status-publish","format-standard","hentry","category-cloud-native","category-linux","category-rust","tag-cloud-native","tag-linux","tag-rust","tag-29"],"_links":{"self":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts\/608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/comments?post=608"}],"version-history":[{"count":1,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts\/608\/revisions"}],"predecessor-version":[{"id":609,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/posts\/608\/revisions\/609"}],"wp:attachment":[{"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/media?parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/categories?post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cococat.top\/index.php\/wp-json\/wp\/v2\/tags?post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}