{"id":3537,"date":"2018-07-16T10:04:01","date_gmt":"2018-07-16T02:04:01","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=3537"},"modified":"2018-07-16T10:04:01","modified_gmt":"2018-07-16T02:04:01","slug":"linux%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86%e6%9c%ba%e5%88%b6%e7%ae%80%e5%8d%95%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/linux%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86%e6%9c%ba%e5%88%b6%e7%ae%80%e5%8d%95%e5%88%86%e6%9e%90\/","title":{"rendered":"Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u7b80\u5355\u5206\u6790"},"content":{"rendered":"<p>\u672c\u6587\u5bf9Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u5206\u6790\uff0c\u8bd5\u56fe\u8ba9\u4f60\u5feb\u901f\u7406\u89e3Linux\u4e00\u4e9b\u5185\u5b58\u7ba1\u7406\u7684\u6982\u5ff5\u5e76\u6709\u6548\u7684\u5229\u7528\u4e00\u4e9b\u7ba1\u7406\u65b9\u6cd5\u3002<\/p>\n<p><em>NUMA<\/em><\/p>\n<p>Linux 2.6\u5f00\u59cb\u652f\u6301NUMA\uff08 Non-Uniform Memory Access \uff09\u5185\u5b58\u7ba1\u7406\u6a21\u5f0f\u3002\u5728\u591a\u4e2aCPU\u7684\u7cfb\u7edf\u4e2d\uff0c\u5185\u5b58\u6309CPU\u5212\u5206\u4e3a\u4e0d\u540c\u7684Node\uff0c\u6bcf\u4e2aCPU\u6302\u4e00\u4e2aNode\uff0c\u5176\u8bbf\u95ee\u672c\u5730Node\u6bd4\u8bbf\u95ee\u5176\u4ed6CPU\u4e0a\u7684Node\u901f\u5ea6\u8981\u5feb\u5f88\u591a\u3002<br \/>\n\u901a\u8fc7numactl -H\u67e5\u770bNUMA\u786c\u4ef6\u4fe1\u606f\uff0c\u53ef\u4ee5\u770b\u52302\u4e2anode\u7684\u5927\u5c0f\u548c\u5bf9\u5e94\u7684CPU\u6838\uff0c\u4ee5\u53caCPU\u8bbf\u95eenode\u7684distances\u3002\u5982\u4e0b\u6240\u793aCPU\u8bbf\u95ee\u8fdc\u7aefnode\u7684distances\u662f\u672c\u5730node\u76842\u500d\u591a\u3002<\/p>\n<p>[root@localhost ~]# numactl -H<br \/>\navailable: 2 nodes (0-1)<br \/>\nnode 0 cpus: 0 1 2 3 4 5 6 7 16 17 18 19 20 21 22 23<br \/>\nnode 0 size: 15870 MB<br \/>\nnode 0 free: 13780 MB<br \/>\nnode 1 cpus: 8 9 10 11 12 13 14 15 24 25 26 27 28 29 30 31<br \/>\nnode 1 size: 16384 MB<br \/>\nnode 1 free: 15542 MB<br \/>\nnode distances:<br \/>\nnode\u00a0 0\u00a0 1<br \/>\n0:\u00a0 10\u00a0 21<br \/>\n1:\u00a0 21\u00a0 10<\/p>\n<p>\u901a\u8fc7numastat\u67e5\u770bNUMA\u7684\u7edf\u8ba1\u4fe1\u606f\uff0c\u5305\u62ec\u5185\u5b58\u5206\u914d\u7684\u547d\u4e2d\u6b21\u6570\u3001\u672a\u547d\u4e2d\u6b21\u6570\u3001\u672c\u5730\u5206\u914d\u6b21\u6570\u548c\u8fdc\u7aef\u5206\u914d\u6b21\u6570\u7b49\u3002<\/p>\n<p>[root@localhost ~]# numastat<br \/>\nnode0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 node1<br \/>\nnuma_hit\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 2351854045\u00a0 \u00a0 \u00a0 3021228076<br \/>\nnuma_miss\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 22736854\u00a0 \u00a0 \u00a0 \u00a0 2976885<br \/>\nnuma_foreign\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 2976885\u00a0 \u00a0 \u00a0 \u00a0 22736854<br \/>\ninterleave_hit\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 14144\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 14100<br \/>\nlocal_node\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 2351844760\u00a0 \u00a0 \u00a0 3021220020<br \/>\nother_node\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 22746139\u00a0 \u00a0 \u00a0 \u00a0 2984941<\/p>\n<p>Zone<\/p>\n<p>Node\u4e0b\u9762\u5212\u5206\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2aZone\uff0c\u4e3a\u5565\u8981\u6709Zone\uff0c\u4e24\u4e2a\u539f\u56e0\uff1a1.DMA\u8bbe\u5907\u80fd\u591f\u8bbf\u95ee\u7684\u5185\u5b58\u8303\u56f4\u6709\u9650\uff08ISA\u8bbe\u5907\u53ea\u80fd\u8bbf\u95ee16MB\uff09\uff1b2.x86-32bit\u7cfb\u7edf\u5730\u5740\u7a7a\u95f4\u6709\u9650\uff0832\u4f4d\u6700\u591a\u53ea\u80fd4GB\uff09\uff0c\u4e3a\u4e86\u4f7f\u7528\u66f4\u5927\u5185\u5b58\uff0c\u9700\u8981\u4f7f\u7528HIGHMEM\u673a\u5236\u3002<\/p>\n<p>ZONE_DMA<\/p>\n<p>\u5730\u5740\u6bb5\u6700\u4f4e\u7684\u4e00\u5757\u5185\u5b58\u533a\u57df\uff0c\u7528\u4e8eISA(Industry Standard Architecture)\u8bbe\u5907DMA\u8bbf\u95ee\u3002\u5728x86\u67b6\u6784\u4e0b\uff0c\u8be5Zone\u5927\u5c0f\u9650\u5236\u4e3a16MB\u3002<\/p>\n<p>ZONE_DMA32<\/p>\n<p>\u8be5Zone\u7528\u4e8e\u652f\u630132-bits\u5730\u5740\u603b\u7ebf\u7684DMA\u8bbe\u5907\uff0c\u53ea\u572864-bits\u7cfb\u7edf\u91cc\u624d\u6709\u6548\u3002<\/p>\n<p>ZONE_NORMAL<\/p>\n<p>\u8be5Zone\u7684\u5185\u5b58\u88ab\u5185\u6838\u76f4\u63a5\u6620\u5c04\u4e3a\u7ebf\u6027\u5730\u5740\u5e76\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u3002\u5728X86-32\u67b6\u6784\u4e0b\uff0c\u8be5Zone\u5bf9\u5e94\u7684\u5730\u5740\u8303\u56f4\u4e3a16MB~896MB\u3002\u5728X86-64\u67b6\u6784\u4e0b\uff0cDMA\u548cDMA32\u4e4b\u5916\u7684\u5185\u5b58\u5168\u90e8\u5728NORMAL\u7684Zone\u91cc\u7ba1\u7406\u3002<\/p>\n<p>ZONE_HIGHMEM<\/p>\n<p>\u8be5Zone\u53ea\u572832\u4f4d\u7cfb\u7edf\u624d\u6709\uff0c\u901a\u8fc7\u5efa\u7acb\u4e34\u65f6\u9875\u8868\u7684\u65b9\u5f0f\u6620\u5c04\u8d85\u8fc7896MB\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u5373\u5728\u9700\u8981\u8bbf\u95ee\u7684\u65f6\u5019\u5efa\u7acb\u5730\u5740\u7a7a\u95f4\u548c\u5185\u5b58\u7684\u6620\u5c04\u5173\u7cfb\uff0c\u5728\u8bbf\u95ee\u7ed3\u675f\u540e\u62c6\u6389\u6620\u5c04\u5173\u7cfb\u91ca\u653e\u5730\u5740\u7a7a\u95f4\uff0c\u8be5\u5730\u5740\u7a7a\u95f4\u53ef\u4ee5\u7528\u4e8e\u5176\u4ed6HIGHMEM\u7684\u5185\u5b58\u6620\u5c04\u3002<\/p>\n<p>\u901a\u8fc7\/proc\/zoneinfo\u53ef\u4ee5\u67e5\u770bZone\u76f8\u5173\u7684\u4fe1\u606f\u3002\u5982\u4e0b\u6240\u793aX86-64\u7cfb\u7edf\u4e0a\u4e24\u4e2aNode\uff0cNode0\u4e0a\u6709DMA\u3001DMA32\u548cNormal\u4e09\u4e2aZone\uff0cNode1\u4e0a\u53ea\u6709\u4e00\u4e2aNormal Zone\u3002<\/p>\n<p>[root@localhost ~]# cat \/proc\/zoneinfo |grep -E &#8220;zone| free|managed&#8221;<br \/>\nNode 0, zone\u00a0 \u00a0 \u00a0 DMA<br \/>\npages free\u00a0 \u00a0 3700<br \/>\nmanaged\u00a0 3975<br \/>\nNode 0, zone\u00a0 \u00a0 DMA32<br \/>\npages free\u00a0 \u00a0 291250<br \/>\nmanaged\u00a0 326897<br \/>\nNode 0, zone\u00a0 Normal<br \/>\npages free\u00a0 \u00a0 3232166<br \/>\nmanaged\u00a0 3604347<br \/>\nNode 1, zone\u00a0 Normal<br \/>\npages free\u00a0 \u00a0 3980110<br \/>\nmanaged\u00a0 4128056<\/p>\n<p>Page<\/p>\n<p>Page\u662fLinux\u5e95\u5c42\u5185\u5b58\u7ba1\u7406\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u5927\u5c0f\u4e3a4KB\u3002\u4e00\u4e2aPage\u6620\u5c04\u4e3a\u4e00\u6bb5\u8fde\u7eed\u7684\u7269\u7406\u5185\u5b58\uff0c\u5185\u5b58\u7684\u5206\u914d\u548c\u91ca\u653e\u90fd\u8981\u4ee5Page\u4e3a\u5355\u4f4d\u8fdb\u884c\u3002\u8fdb\u7a0b\u865a\u62df\u5730\u5740\u5230\u7269\u7406\u5730\u5740\u7684\u6620\u5c04\u4e5f\u662f\u901a\u8fc7Page Table\u9875\u8868\u8fdb\u884c\uff0c\u9875\u8868\u7684\u6bcf\u4e00\u9879\u8bb0\u5f55\u4e00\u4e2aPage\u7684\u865a\u62df\u5730\u5740\u5bf9\u5e94\u7684\u7269\u7406\u5730\u5740\u3002<\/p>\n<p>TLB<\/p>\n<p>\u5185\u5b58\u8bbf\u95ee\u65f6\u9700\u8981\u67e5\u627e\u5730\u5740\u5bf9\u5e94\u7684Page\u7ed3\u6784\uff0c\u8fd9\u4e2a\u6570\u636e\u8bb0\u5f55\u5728\u9875\u8868\u91cc\u3002\u6240\u6709\u5bf9\u5185\u5b58\u5730\u5740\u7684\u8bbf\u95ee\u90fd\u8981\u5148\u67e5\u8be2\u9875\u8868\uff0c\u56e0\u6b64\u9875\u8868\u7684\u8bbf\u95ee\u6b21\u6570\u662f\u9891\u7387\u6700\u9ad8\u7684\u3002\u4e3a\u4e86\u63d0\u9ad8\u5bf9\u9875\u8868\u7684\u8bbf\u95ee\u901f\u5ea6\uff0c\u5f15\u5165\u4e86TLB\uff08Translation Lookaside Buffer\uff09\u673a\u5236\uff0c\u5c06\u8bbf\u95ee\u8f83\u591a\u9875\u8868\u7f13\u5b58\u5728CPU\u7684cache\u91cc\u3002\u56e0\u6b64CPU\u7684\u6027\u80fd\u7edf\u8ba1\u91cc\u5f88\u91cd\u8981\u7684\u4e00\u9879\u5c31\u662fL1\/L2 cache\u7684TLB miss\u7edf\u8ba1\u9879\u3002\u5728\u5185\u5b58\u8f83\u5927\u7684\u7cfb\u7edf\u91cc\uff0c\u5982256GB\u5185\u5b58\u5168\u91cf\u7684\u9875\u8868\u9879\u6709256GB\/4KB=67108864\u6761\uff0c\u6bcf\u4e2a\u6761\u76ee\u5360\u752816\u5b57\u8282\u7684\u8bdd\uff0c\u9700\u89811GB\uff0c\u663e\u7136\u662fCPU cache\u65e0\u6cd5\u5168\u91cf\u7f13\u5b58\u7684\u3002\u8fd9\u65f6\u5019\u5982\u679c\u8bbf\u95ee\u7684\u5185\u5b58\u8303\u56f4\u8f83\u5e7f\u5f88\u5bb9\u6613\u51fa\u73b0TLB miss\u5bfc\u81f4\u8bbf\u95ee\u5ef6\u65f6\u7684\u589e\u52a0\u3002<\/p>\n<p>Hugepages<\/p>\n<p>\u4e3a\u4e86\u964d\u4f4eTLB miss\u7684\u6982\u7387\uff0cLinux\u5f15\u5165\u4e86Hugepages\u673a\u5236\uff0c\u53ef\u4ee5\u8bbe\u5b9aPage\u5927\u5c0f\u4e3a2MB\u6216\u80051GB\u30022MB\u7684Hugepages\u673a\u5236\u4e0b\uff0c\u540c\u6837256GB\u5185\u5b58\u9700\u8981\u7684\u9875\u8868\u9879\u964d\u4f4e\u4e3a256GB\/2MB=131072\uff0c\u4ec5\u9700\u89812MB\u3002\u56e0\u6b64Hugepages\u7684\u9875\u8868\u53ef\u4ee5\u5168\u91cf\u7f13\u5b58\u5728CPU cache\u4e2d\u3002<br \/>\n\u901a\u8fc7sysctl -w vm.nr_hugepages=1024\u53ef\u4ee5\u8bbe\u7f6ehugepages\u7684\u4e2a\u6570\u4e3a1024\uff0c\u603b\u5927\u5c0f\u4e3a4GB\u3002\u9700\u8981\u6ce8\u610f\u662f\uff0c\u8bbe\u7f6ehuagepages\u4f1a\u4ece\u7cfb\u7edf\u7533\u8bf7\u8fde\u7eed2MB\u7684\u5185\u5b58\u5757\u5e76\u8fdb\u884c\u4fdd\u7559\uff08\u4e0d\u80fd\u7528\u4e8e\u6b63\u5e38\u5185\u5b58\u7533\u8bf7\uff09\uff0c\u5982\u679c\u7cfb\u7edf\u8fd0\u884c\u4e00\u6bb5\u65f6\u95f4\u5bfc\u81f4\u5185\u5b58\u788e\u7247\u8f83\u591a\u65f6\uff0c\u518d\u7533\u8bf7hugepages\u4f1a\u5931\u8d25\u3002<br \/>\n\u5982\u4e0b\u6240\u793a\u4e3ahugepages\u7684\u8bbe\u7f6e\u548cmount\u65b9\u6cd5\uff0cmount\u4e4b\u540e\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u5728mount\u8def\u5f84\u4e0b\u901a\u8fc7mmap\u8fdb\u884c\u6587\u4ef6\u6620\u5c04\u6765\u4f7f\u7528\u8fd9\u4e9bhugepages\u3002<\/p>\n<p>sysctl -w vm.nr_hugepages=1024<br \/>\nmkdir -p \/mnt\/hugepages<br \/>\nmount -t hugetlbfs hugetlbfs \/mnt\/hugepages<\/p>\n<p>Buddy System<\/p>\n<p>Linux Buddy System\u662f\u4e3a\u4e86\u89e3\u51b3\u4ee5Page\u4e3a\u5355\u4f4d\u7684\u5185\u5b58\u5206\u914d\u5bfc\u81f4\u5916\u5185\u5b58\u788e\u7247\u95ee\u9898\uff1a\u5373\u7cfb\u7edf\u7f3a\u5c11\u8fde\u7eed\u7684Page\u9875\u5bfc\u81f4\u9700\u8981\u8fde\u7eedPage\u9875\u7684\u5185\u5b58\u7533\u8bf7\u65e0\u6cd5\u5f97\u5230\u6ee1\u8db3\u3002\u539f\u7406\u5f88\u7b80\u5355\uff0c\u5c06\u4e0d\u540c\u4e2a\u6570\u7684\u8fde\u7eedPages\u7ec4\u5408\u6210Block\u8fdb\u884c\u5206\u914d\uff0cBlock\u63092\u7684\u5e42\u6b21\u65b9\u4e2aPages\u5212\u5206\u4e3a11\u4e2aBlock\u94fe\u8868\uff0c\u5206\u522b\u5bf9\u5e941\uff0c2\uff0c4\uff0c8\uff0c16\uff0c32\uff0c64\uff0c128\uff0c256\uff0c512\u548c1024\u4e2a\u8fde\u7eed\u7684Pages\u3002\u8c03\u7528Buddy System\u8fdb\u884c\u5185\u5b58\u5206\u914d\u65f6\uff0c\u6839\u636e\u7533\u8bf7\u7684\u5927\u5c0f\u627e\u6700\u5408\u9002\u7684Block\u3002<br \/>\n\u5982\u4e0b\u6240\u793a\u4e3a\u5404\u4e2aZone\u4e0a\u7684Buddy System\u57fa\u672c\u4fe1\u606f\uff0c\u540e\u976211\u5217\u4e3a11\u4e2aBlock\u94fe\u8868\u91cc\u53ef\u7528\u7684Block\u4e2a\u6570\u3002<\/p>\n<p>[root@localhost ~]# cat \/proc\/buddyinfo<br \/>\nNode 0, zone\u00a0 \u00a0 \u00a0 DMA\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 1\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 1\u00a0 \u00a0 \u00a0 1\u00a0 \u00a0 \u00a0 1\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 1\u00a0 \u00a0 \u00a0 3<br \/>\nNode 0, zone\u00a0 \u00a0 DMA32\u00a0 \u00a0 102\u00a0 \u00a0 79\u00a0 \u00a0 179\u00a0 \u00a0 229\u00a0 \u00a0 230\u00a0 \u00a0 166\u00a0 \u00a0 251\u00a0 \u00a0 168\u00a0 \u00a0 107\u00a0 \u00a0 78\u00a0 \u00a0 169<br \/>\nNode 0, zone\u00a0 Normal\u00a0 1328\u00a0 \u00a0 900\u00a0 1985\u00a0 1920\u00a0 2261\u00a0 1388\u00a0 \u00a0 798\u00a0 \u00a0 972\u00a0 \u00a0 539\u00a0 \u00a0 324\u00a0 2578<br \/>\nNode 1, zone\u00a0 Normal\u00a0 \u00a0 466\u00a0 1476\u00a0 2133\u00a0 7715\u00a0 6026\u00a0 4737\u00a0 2883\u00a0 1532\u00a0 \u00a0 778\u00a0 \u00a0 490\u00a0 2760<\/p>\n<p>Slab<\/p>\n<p>Buddy System\u7684\u5185\u5b58\u90fd\u662f\u5927\u5757\u7533\u8bf7\uff0c\u4f46\u662f\u5927\u591a\u6570\u5e94\u7528\u9700\u8981\u7684\u5185\u5b58\u90fd\u5f88\u5c0f\uff0c\u6bd4\u5982\u5e38\u89c1\u7684\u51e0\u767e\u4e2aBytes\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5982\u679c\u4e5f\u7533\u8bf7\u4e00\u4e2aPage\uff0c\u5c06\u4f1a\u975e\u5e38\u6d6a\u8d39\u3002\u4e3a\u4e86\u6ee1\u8db3\u5c0f\u800c\u4e0d\u89c4\u5219\u7684\u5185\u5b58\u5206\u914d\u9700\u6c42\uff0cLinux\u8bbe\u8ba1\u4e86Slab\u5206\u914d\u5668\u3002\u539f\u7406\u7b80\u5355\u8bf4\u5c31\u662f\u4e3a\u7279\u5b9a\u7684\u6570\u636e\u7ed3\u6784\u5efa\u7acbmemcache\uff0c\u4eceBuddy System\u91cc\u7533\u8bf7Pages\uff0c\u5c06\u6bcf\u4e2aPage\u6309\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u5212\u5206\u4e3a\u591a\u4e2aObjects\uff0c\u4f7f\u7528\u8005\u4ecememcache\u91cc\u7533\u8bf7\u6570\u636e\u7ed3\u6784\u65f6\u5206\u914d\u4e00\u4e2aObject\u3002<br \/>\n\u5982\u4e0b\u6240\u793a\u4e3aLinux\u67e5\u770bslab\u4fe1\u606f\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>[root@localhost ~]# cat \/proc\/slabinfo<br \/>\nslabinfo &#8211; version: 2.1<br \/>\n# name\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;active_objs&gt; &lt;num_objs&gt; &lt;objsize&gt; &lt;objperslab&gt; &lt;pagesperslab&gt; : tunables &lt;limit&gt; &lt;batchcount&gt; &lt;sharedfactor&gt; : slabdata &lt;active_slabs&gt; &lt;num_slabs&gt; &lt;sharedavail&gt;<br \/>\nfat_inode_cache\u00a0 \u00a0 \u00a0 90\u00a0 \u00a0 90\u00a0 \u00a0 720\u00a0 45\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 \u00a0 2\u00a0 \u00a0 \u00a0 2\u00a0 \u00a0 \u00a0 0<br \/>\nfat_cache\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 40\u00a0 102\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0<br \/>\nkvm_vcpu\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 16576\u00a0 \u00a0 1\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0<br \/>\nkvm_mmu_page_header\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 168\u00a0 48\u00a0 \u00a0 2 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0\u00a0 \u00a0 \u00a0 0<br \/>\next4_groupinfo_4k\u00a0 4440\u00a0 4440\u00a0 \u00a0 136\u00a0 30\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 148\u00a0 \u00a0 148\u00a0 \u00a0 \u00a0 0<br \/>\next4_inode_cache\u00a0 63816\u00a0 65100\u00a0 1032\u00a0 31\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 2100\u00a0 2100\u00a0 \u00a0 \u00a0 0<br \/>\next4_xattr\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 1012\u00a0 1012\u00a0 \u00a0 88\u00a0 46\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 22\u00a0 \u00a0 22\u00a0 \u00a0 \u00a0 0<br \/>\next4_free_data\u00a0 \u00a0 16896\u00a0 17600\u00a0 \u00a0 64\u00a0 64\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 275\u00a0 \u00a0 275\u00a0 \u00a0 \u00a0 0<\/p>\n<p>\u901a\u5e38\u6211\u4eec\u90fd\u662f\u901a\u8fc7slabtop\u547d\u4ee4\u67e5\u770b\u6392\u5e8f\u540e\u7684slab\u4fe1\u606f\uff1a<\/p>\n<p>OBJS ACTIVE\u00a0 USE OBJ SIZE\u00a0 SLABS OBJ\/SLAB CACHE SIZE NAME<br \/>\n352014 352014 100%\u00a0 \u00a0 0.10K\u00a0 9026\u00a0 39\u00a0 \u00a0 36104K buffer_head<br \/>\n93492\u00a0 93435\u00a0 99%\u00a0 \u00a0 0.19K\u00a0 2226\u00a0 42\u00a0 \u00a0 17808K dentry<br \/>\n65100\u00a0 63816\u00a0 98%\u00a0 \u00a0 1.01K\u00a0 2100\u00a0 31\u00a0 \u00a0 67200K ext4_inode_cache<br \/>\n48128\u00a0 47638\u00a0 98%\u00a0 \u00a0 0.06K\u00a0 \u00a0 752\u00a0 64\u00a0 3008K kmalloc-64<br \/>\n47090\u00a0 43684\u00a0 92%\u00a0 \u00a0 0.05K\u00a0 \u00a0 554\u00a0 85\u00a0 2216K shared_policy_node<br \/>\n44892\u00a0 44892 100%\u00a0 \u00a0 0.11K\u00a0 1247\u00a0 36\u00a0 4988K sysfs_dir_cache<br \/>\n43624\u00a0 43177\u00a0 98%\u00a0 \u00a0 0.07K\u00a0 \u00a0 779\u00a0 56\u00a0 3116K Acpi-ParseExt<br \/>\n43146\u00a0 42842\u00a0 99%\u00a0 \u00a0 0.04K\u00a0 \u00a0 423\u00a0 102\u00a0 1692K ext4_extent_status<\/p>\n<p>kmalloc<\/p>\n<p>\u548cglibc\u7684malloc()\u4e00\u6837\uff0c\u5185\u6838\u4e5f\u63d0\u4f9bkmalloc()\u7528\u4e8e\u5206\u914d\u4efb\u610f\u5927\u5c0f\u7684\u5185\u5b58\u7a7a\u95f4\u3002\u540c\u6837\uff0c\u5982\u679c\u653e\u4efb\u5e94\u7528\u7a0b\u5e8f\u968f\u610f\u4ecePage\u91cc\u7533\u8bf7\u4efb\u610f\u5927\u5c0f\u7684\u5185\u5b58\u4e5f\u4f1a\u5bfc\u81f4Page\u5185\ufffd\ufffd\ufffd\u5185\u5b58\u788e\u7247\u5316\u3002\u4e3a\u4e86\u89e3\u51b3\u5185\u90e8\u788e\u7247\u95ee\u9898\uff0cLinux\u4f7f\u7528Slab\u673a\u5236\u6765\u5b9e\u73b0kmalloc\u5185\u5b58\u5206\u914d\u3002\u539f\u7406\u548cBuddy System\u7c7b\u4f3c\uff0c\u5373\u521b\u5efa2\u7684\u5e42\u6b21\u65b9\u7684Slab\u6c60\u7528\u4e8ekmalloc\u6839\u636e\u5927\u5c0f\u9002\u914d\u6700\u4f73\u7684Slab\u8fdb\u884c\u5206\u914d\u3002<br \/>\n\u5982\u4e0b\u6240\u793a\u4e3a\u7528\u4e8ekmalloc\u5206\u914d\u7684Slabs\uff1a<\/p>\n<p>[root@localhost ~]# cat \/proc\/slabinfo<br \/>\nslabinfo &#8211; version: 2.1<br \/>\n# name\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 &lt;active_objs&gt; &lt;num_objs&gt; &lt;objsize&gt; &lt;objperslab&gt; &lt;pagesperslab&gt; : tunables &lt;limit&gt; &lt;batchcount&gt; &lt;sharedfactor&gt; : slabdata &lt;active_slabs&gt; &lt;num_slabs&gt; &lt;sharedavail&gt;<br \/>\nkmalloc-8192\u00a0 \u00a0 \u00a0 \u00a0 196\u00a0 \u00a0 200\u00a0 8192\u00a0 \u00a0 4\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 50\u00a0 \u00a0 50\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-4096\u00a0 \u00a0 \u00a0 \u00a0 1214\u00a0 1288\u00a0 4096\u00a0 \u00a0 8\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 161\u00a0 \u00a0 161\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-2048\u00a0 \u00a0 \u00a0 \u00a0 2861\u00a0 2928\u00a0 2048\u00a0 16\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 183\u00a0 \u00a0 183\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-1024\u00a0 \u00a0 \u00a0 \u00a0 7993\u00a0 8320\u00a0 1024\u00a0 32\u00a0 \u00a0 8 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 260\u00a0 \u00a0 260\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-512\u00a0 \u00a0 \u00a0 \u00a0 6030\u00a0 6144\u00a0 \u00a0 512\u00a0 32\u00a0 \u00a0 4 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 192\u00a0 \u00a0 192\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-256\u00a0 \u00a0 \u00a0 \u00a0 7813\u00a0 8576\u00a0 \u00a0 256\u00a0 32\u00a0 \u00a0 2 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 268\u00a0 \u00a0 268\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-192\u00a0 \u00a0 \u00a0 \u00a0 15542\u00a0 15750\u00a0 \u00a0 192\u00a0 42\u00a0 \u00a0 2 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 375\u00a0 \u00a0 375\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-128\u00a0 \u00a0 \u00a0 \u00a0 16814\u00a0 16896\u00a0 \u00a0 128\u00a0 32\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 528\u00a0 \u00a0 528\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-96\u00a0 \u00a0 \u00a0 \u00a0 17507\u00a0 17934\u00a0 \u00a0 96\u00a0 42\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 427\u00a0 \u00a0 427\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-64\u00a0 \u00a0 \u00a0 \u00a0 48590\u00a0 48704\u00a0 \u00a0 64\u00a0 64\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 761\u00a0 \u00a0 761\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-32\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 7296\u00a0 7296\u00a0 \u00a0 32\u00a0 128\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 57\u00a0 \u00a0 57\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-16\u00a0 \u00a0 \u00a0 \u00a0 14336\u00a0 14336\u00a0 \u00a0 16\u00a0 256\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 56\u00a0 \u00a0 56\u00a0 \u00a0 \u00a0 0<br \/>\nkmalloc-8\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 21504\u00a0 21504\u00a0 \u00a0 \u00a0 8\u00a0 512\u00a0 \u00a0 1 : tunables\u00a0 \u00a0 0\u00a0 \u00a0 0\u00a0 \u00a0 0 : slabdata\u00a0 \u00a0 42\u00a0 \u00a0 42\u00a0 \u00a0 \u00a0 0<\/p>\n<p>\u5185\u6838\u53c2\u6570<\/p>\n<p>Linux\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u5b58\u7ba1\u7406\u76f8\u5173\u7684\u5185\u6838\u53c2\u6570\uff0c\u5728\/proc\/sys\/vm\u76ee\u5f55\u4e0b\u53ef\u4ee5\u67e5\u770b\u6216\u8005\u901a\u8fc7sysctl -a |grep vm\u67e5\u770b\uff1a<\/p>\n<p>[root@localhost vm]# sysctl -a |grep vm<br \/>\nvm.admin_reserve_kbytes = 8192<br \/>\nvm.block_dump = 0<br \/>\nvm.dirty_background_bytes = 0<br \/>\nvm.dirty_background_ratio = 10<br \/>\nvm.dirty_bytes = 0<br \/>\nvm.dirty_expire_centisecs = 3000<br \/>\nvm.dirty_ratio = 20<br \/>\nvm.dirty_writeback_centisecs = 500<br \/>\nvm.drop_caches = 1<br \/>\nvm.extfrag_threshold = 500<br \/>\nvm.hugepages_treat_as_movable = 0<br \/>\nvm.hugetlb_shm_group = 0<br \/>\nvm.laptop_mode = 0<br \/>\nvm.legacy_va_layout = 0<br \/>\nvm.lowmem_reserve_ratio = 256\u00a0 256 32<br \/>\nvm.max_map_count = 65530<br \/>\nvm.memory_failure_early_kill = 0<br \/>\nvm.memory_failure_recovery = 1<br \/>\nvm.min_free_kbytes = 1024000<br \/>\nvm.min_slab_ratio = 1<br \/>\nvm.min_unmapped_ratio = 1<br \/>\nvm.mmap_min_addr = 4096<br \/>\nvm.nr_hugepages = 0<br \/>\nvm.nr_hugepages_mempolicy = 0<br \/>\nvm.nr_overcommit_hugepages = 0<br \/>\nvm.nr_pdflush_threads = 0<br \/>\nvm.numa_zonelist_order = default<br \/>\nvm.oom_dump_tasks = 1<br \/>\nvm.oom_kill_allocating_task = 0<br \/>\nvm.overcommit_kbytes = 0<br \/>\nvm.overcommit_memory = 0<br \/>\nvm.overcommit_ratio = 50<br \/>\nvm.page-cluster = 3<br \/>\nvm.panic_on_oom = 0<br \/>\nvm.percpu_pagelist_fraction = 0<br \/>\nvm.stat_interval = 1<br \/>\nvm.swappiness = 60<br \/>\nvm.user_reserve_kbytes = 131072<br \/>\nvm.vfs_cache_pressure = 100<br \/>\nvm.zone_reclaim_mode = 0<\/p>\n<p>vm.drop_caches<\/p>\n<p>vm.drop_caches\u662f\u6700\u5e38\u7528\u5230\u7684\u53c2\u6570\uff0c\u56e0\u4e3aLinux\u7684Page cache\uff08\u6587\u4ef6\u7cfb\u7edf\u7f13\u5b58\uff09\u673a\u5236\u4f1a\u5bfc\u81f4\u5927\u91cf\u7684\u5185\u5b58\u88ab\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u7f13\u5b58\uff0c\u5305\u62ec\u6570\u636e\u7f13\u5b58\u548c\u5143\u6570\u636e\uff08dentry\u3001inode\uff09\u7f13\u5b58\u3002\u5f53\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u6211\u4eec\u901a\u8fc7\u8be5\u53c2\u6570\u53ef\u4ee5\u5feb\u901f\u91ca\u653e\u6587\u4ef6\u7cfb\u7edf\u7f13\u5b58\uff1a<\/p>\n<p>To free pagecache:<br \/>\necho 1 &gt; \/proc\/sys\/vm\/drop_caches<br \/>\nTo free reclaimable slab objects (includes dentries and inodes):<br \/>\necho 2 &gt; \/proc\/sys\/vm\/drop_caches<br \/>\nTo free slab objects and pagecache:<br \/>\necho 3 &gt; \/proc\/sys\/vm\/drop_caches<\/p>\n<p>vm.min_free_kbytes<\/p>\n<p>vm.min_free_kbytes\u7528\u4e8e\u51b3\u5b9a\u5185\u5b58\u4f4e\u4e8e\u591a\u5c11\u65f6\u542f\u52a8\u5185\u5b58\u56de\u6536\u673a\u5236\uff08\u5305\u62ec\u4e0a\u9762\u63d0\u5230\u7684\u6587\u4ef6\u7cfb\u7edf\u7f13\u5b58\u548c\u4e0b\u9762\u4f1a\u63d0\u5230\u7684\u53ef\u56de\u6536\u7684Slab\uff09\uff0c\u8be5\u503c\u9ed8\u8ba4\u503c\u8f83\u5c0f\uff0c\u5728\u5185\u5b58\u8f83\u591a\u7684\u7cfb\u7edf\u8bbe\u7f6e\u4e3a\u4e00\u4e2a\u8f83\u5927\u7684\u503c\uff08\u59821GB\uff09\u53ef\u4ee5\u5728\u5185\u5b58\u8fd8\u4e0d\u4f1a\u592a\u5c11\u65f6\u81ea\u52a8\u89e6\u53d1\u5185\u5b58\u56de\u6536\u3002\u4f46\u4e5f\u4e0d\u80fd\u8bbe\u7f6e\u592a\u5927\uff0c\u5bfc\u81f4\u9891\u7e41\u5e94\u7528\u7a0b\u5e8f\u7ecf\u5e38\u88abOOM killed\u3002<\/p>\n<p>sysctl -w vm.min_free_kbytes=1024000<\/p>\n<p>vm.min_slab_ratio<\/p>\n<p>vm.min_slab_ratio\u7528\u4e8e\u51b3\u5b9aSlab\u6c60\u91cc\u53ef\u56de\u6536\u7684Slab\u7a7a\u95f4\u5728\u8be5Zone\u91cc\u7684\u5360\u6bd4\u8fbe\u5230\u591a\u5c11\u65f6\u8fdb\u884c\u56de\u6536\uff0c\u9ed8\u8ba4\u662f5%\u3002\u4f46\u7ecf\u8fc7\u7b14\u8005\u8bd5\u9a8c\uff0c\u5f53\u5185\u5b58\u5145\u8db3\u65f6\u6839\u672c\u4e0d\u4f1a\u89e6\u53d1Slab\u56de\u6536\uff0c\u4e5f\u53ea\u6709\u5728\u5185\u5b58\u6c34\u4f4d\u7ebf\u8fbe\u5230\u4e0a\u9762min_free_kbytes\u65f6\u624d\u4f1a\u89e6\u53d1Slab\u56de\u6536\u3002\u8be5\u503c\u6700\u5c0f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a1%\uff1a<\/p>\n<p>sysctl -w vm.min_slab_ratio=1<\/p>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<p>\u4ee5\u4e0a\u7b80\u5355\u63cf\u8ff0\u4e86Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u548c\u51e0\u4e2a\u5e38\u7528\u7684\u5185\u5b58\u7ba1\u7406\u5185\u6838\u53c2\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5bf9Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u505a\u4e00\u4e2a\u7b80\u5355\u7684\u5206\u6790\uff0c\u8bd5\u56fe\u8ba9\u4f60\u5feb\u901f\u7406\u89e3Linux\u4e00\u4e9b\u5185\u5b58\u7ba1\u7406\u7684\u6982\u5ff5\u5e76\u6709\u6548\u7684\u5229\u7528\u4e00\u4e9b\u7ba1\u7406 &#8230; <a title=\"Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u7b80\u5355\u5206\u6790\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/jishu\/linux\/linux%e5%86%85%e5%ad%98%e7%ae%a1%e7%90%86%e6%9c%ba%e5%88%b6%e7%ae%80%e5%8d%95%e5%88%86%e6%9e%90\/\" aria-label=\"\u9605\u8bfb Linux\u5185\u5b58\u7ba1\u7406\u673a\u5236\u7b80\u5355\u5206\u6790\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49],"tags":[],"class_list":["post-3537","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3537","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=3537"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3537\/revisions"}],"predecessor-version":[{"id":3539,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/3537\/revisions\/3539"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=3537"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=3537"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=3537"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}