{"id":15466,"date":"2024-11-18T18:12:59","date_gmt":"2024-11-18T10:12:59","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15466"},"modified":"2024-11-18T18:12:59","modified_gmt":"2024-11-18T10:12:59","slug":"docker%e8%b5%84%e6%ba%90%e7%ae%a1%e7%90%86%e6%8e%a2%e7%a7%98%ef%bc%8dcgroups%e6%9c%ba%e5%88%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15466\/","title":{"rendered":"Docker\u8d44\u6e90\u7ba1\u7406\u63a2\u79d8\uff0dCgroups\u673a\u5236"},"content":{"rendered":"<p>\u968f\u7740Docker\u6280\u672f\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u4e2a\u4eba\u3001\u4f01\u4e1a\u6240\u63a5\u53d7\uff0c\u5176\u7528\u9014\u4e5f\u8d8a\u6765\u8d8a\u5e7f\u6cdb\u3002Docker\u8d44\u6e90\u7ba1\u7406\u5305\u542b\u5bf9CPU\u3001\u5185\u5b58\u3001IO\u7b49\u8d44\u6e90\u7684\u9650\u5236\uff0c\u4f46\u5927\u90e8\u5206Docker\u4f7f\u7528\u8005\u5728\u4f7f\u7528\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u65f6\u5f80\u5f80\u53ea\u77e5\u5176\u7136\u800c\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ecb\u7ecdDocker\u8d44\u6e90\u7ba1\u7406\u80cc\u540e\u7684Cgroups\u673a\u5236\uff0c\u5e76\u4e14\u5217\u4e3e\u6bcf\u4e00\u4e2a\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u5bf9\u5e94\u7684Cgroups\u63a5\u53e3\uff0c\u8ba9Docker\u4f7f\u7528\u8005\u5bf9\u8d44\u6e90\u7ba1\u7406\u77e5\u5176\u7136\u5e76\u4e14\u77e5\u5176\u6240\u4ee5\u7136\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u4e00\u3001Docker\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u6982\u89c8<\/h2>\n<table cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"27%\"><strong>\u683c\u5f0f<\/strong><\/td>\n<td valign=\"top\"><strong>\u63cf\u8ff0<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">-m, \u2013memory bytes<\/td>\n<td valign=\"top\">\u5185\u5b58\u4f7f\u7528\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002\u6700\u5c0f\u53d6\u503c\u662f4M\u3002<br \/>\n-m, \u2013memory=\u201d &lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013memory-swap bytes<\/td>\n<td valign=\"top\">\u603b\u5185\u5b58\u4f7f\u7528\u9650\u5236 (\u7269\u7406\u5185\u5b58 + \u4ea4\u6362\u5206\u533a\uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002<br \/>\n\u2013memory-swap=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013memory-reservation bytes<\/td>\n<td valign=\"top\">\u5185\u5b58\u8f6f\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002<br \/>\n\u2013memory-reservation=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013kernel-memory bytes<\/td>\n<td valign=\"top\">\u5185\u6838\u5185\u5b58\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002\u6700\u5c0f\u53d6\u503c\u662f4M\u3002<br \/>\n\u2013kernel-memory=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013oom-kill-disable<\/td>\n<td valign=\"top\">\u5185\u5b58\u8017\u5c3d\u65f6\u662f\u5426\u6740\u6389\u5bb9\u5668<br \/>\n\u2013oom-kill-disable=false<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013memory-swappiness int<\/td>\n<td valign=\"top\">\u8c03\u8282\u5bb9\u5668\u5185\u5b58\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u7684\u9009\u9879\uff0c\u53d6\u503c\u4e3a0\u548c100\u4e4b\u95f4\u7684\u6574\u6570(\u542b0\u548c100)\u3002<br \/>\n\u2013memory-swappiness=\u201d\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">-c, \u2013cpu-shares int<\/td>\n<td valign=\"top\">CPU\u4efd\u989d (\u76f8\u5bf9\u6743\u91cd)<br \/>\n-c, \u2013cpu-shares=0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013cpu-period int<\/td>\n<td valign=\"top\">\u5b8c\u5168\u516c\u5e73\u7b97\u6cd5\u4e2d\u7684period\u503c<br \/>\n\u2013cpu-period=0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013cpu-quota int<\/td>\n<td valign=\"top\">\u5b8c\u5168\u516c\u5e73\u7b97\u6cd5\u4e2d\u7684quota\u503c<br \/>\n\u2013cpu-quota=0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013cpuset-cpus string<\/td>\n<td valign=\"top\">\u9650\u5236\u5bb9\u5668\u4f7f\u7528\u7684cpu\u6838(0-3, 0,1)<br \/>\n\u2013cpuset-cpus=\u201d&lt;\u6570\u5b57&gt;\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013cpuset-mems string<\/td>\n<td valign=\"top\">\u9650\u5236\u5bb9\u5668\u4f7f\u7528\u7684\u5185\u5b58\u8282\u70b9\uff0c\u8be5\u9650\u5236\u4ec5\u4ec5\u5728NUMA\u7cfb\u7edf\u4e2d\u751f\u6548\u3002<br \/>\n\u2013cpuset-mems=\u201d\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013blkio-weight uint16<\/td>\n<td valign=\"top\">\u5757\u8bbe\u5907IO\u76f8\u5bf9\u6743\u91cd\uff0c\u53d6\u503c\u572810\u503c1000\u4e4b\u95f4\u7684\u6574\u6570\uff08\u5305\u542b10\u548c1000\uff09<br \/>\n\u2013blkio-weight=0<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2014blkio-weight-device list<\/td>\n<td valign=\"top\">\u6307\u5b9a\u7684\u5757\u8bbe\u5907\u7684IO\u76f8\u5bf9\u6743\u91cd<br \/>\n\u2013blkio-weight-device=\u201d\u8bbe\u5907\u540d\u79f0:\u6743\u91cd\u503c\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013device-read-bps list<\/td>\n<td valign=\"top\">\u9650\u5236\u5bf9\u67d0\u4e2a\u8bbe\u5907\u7684\u8bfb\u53d6\u901f\u7387 \uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5355\u4f4d\u662fkb, mb, or gb\u4e2d\u7684\u4e00\u4e2a\u3002<br \/>\n\u2013device-read-bps=\u201d&lt;\u8bbe\u5907\u8def\u5f84&gt;:&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013device-write-bps list<\/td>\n<td valign=\"top\">\u9650\u5236\u5bf9\u67d0\u4e2a\u8bbe\u5907\u7684\u5199\u901f\u7387 \uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5355\u4f4d\u662fkb, mb, or gb\u4e2d\u7684\u4e00\u4e2a\u3002<br \/>\n\u2013device-write-bps=\u201d&lt;\u8bbe\u5907\u8def\u5f84&gt;:&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013device-read-iops list<\/td>\n<td valign=\"top\">\u9650\u5236\u5bf9\u67d0\u4e2a\u8bbe\u5907\u6bcf\u79d2IO\u7684\u8bfb\u53d6\u901f\u7387\uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\u3002<br \/>\n\u2013device-read-iops=\u201d&lt;\u8bbe\u5907\u8def\u5f84&gt;:&lt;\u6570\u5b57&gt;\u201d<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\u2013device-write-iops list<\/td>\n<td valign=\"top\">\u9650\u5236\u5bf9\u67d0\u4e2a\u8bbe\u5907\u6bcf\u79d2IO\u7684\u5199\u901f\u7387\uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\u3002<br \/>\n\u2013device-write-iops=\u201d&lt;\u8bbe\u5907\u8def\u5f84&gt;:&lt;\u6570\u5b57&gt;\u201d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e8c\u3001Docker\u8d44\u6e90\u7ba1\u7406\u539f\u7406\u2014\u2014Cgroups\u5b50\u7cfb\u7edf\u4ecb\u7ecd<\/h2>\n<p>Cgroups\u662fcontrol groups\u7684\u7f29\u5199\uff0c\u6700\u521d\u7531google\u7684\u5de5\u7a0b\u5e08\u63d0\u51fa\uff0c\u540e\u6765\u88ab\u6574\u5408\u8fdbLinux\u5185\u6838\u3002Cgroups\u662fLinux\u5185\u6838\u63d0\u4f9b\u7684\u4e00\u79cd\u53ef\u4ee5\u9650\u5236\u3001\u8bb0\u5f55\u3001\u9694\u79bb\u8fdb\u7a0b\u7ec4\uff08process groups\uff09\u6240\u4f7f\u7528\u7684\u7269\u7406\u8d44\u6e90\uff08\u5982\uff1aCPU\u3001\u5185\u5b58\u3001IO\u7b49\uff09\u7684\u673a\u5236\u3002Cgroups\u75317\u4e2a\u5b50\u7cfb\u7edf\u7ec4\u6210\uff1a\u5206\u522b\u662fcpuset\u3001cpu\u3001cpuacct\u3001blkio\u3001devices\u3001freezer\u3001memory\u3002\u4e0d\u540c\u7c7b\u578b\u8d44\u6e90\u7684\u5206\u914d\u548c\u7ba1\u7406\u662f\u7531\u5404\u4e2acgroup\u5b50\u7cfb\u7edf\u8d1f\u8d23\u5b8c\u6210\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u4ecb\u7ecd\u4e0edocker\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u76f8\u5173\u76844\u4e2a\u5b50\u7cfb\u7edf\u3002<\/p>\n<h3>2.1 memory \u2014 \u7528\u6765\u9650\u5236cgroup\u4e2d\u7684\u4efb\u52a1\u6240\u80fd\u4f7f\u7528\u7684\u5185\u5b58\u4e0a\u9650<\/h3>\n<table border=\"1\" width=\"569\" cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"22%\"><strong>\u5b50\u7cfb\u7edf\u5e38\u7528cgroups\u63a5\u53e3<\/strong><\/td>\n<td valign=\"top\"><strong>\u63cf\u8ff0<\/strong><\/td>\n<td valign=\"top\" width=\"22%\"><strong>\u5bf9\u5e94\u7684docker\u63a5\u53e3<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes<\/td>\n<td valign=\"top\">\u8bbe\u5b9a\u5185\u5b58\u4e0a\u9650\uff0c\u5355\u4f4d\u662f\u5b57\u8282\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528k\/K\u3001m\/M\u6216\u8005g\/G\u8868\u793a\u8981\u8bbe\u7f6e\u6570\u503c\u7684\u5355\u4f4d\u3002<\/td>\n<td valign=\"top\">-m, \u2013memory bytes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes<\/td>\n<td valign=\"top\">\u8bbe\u5b9a\u5185\u5b58\u52a0\u4e0a\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u603b\u91cf\u3002\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e2a\u503c\uff0c\u53ef\u4ee5\u9632\u6b62\u8fdb\u7a0b\u628a\u4ea4\u6362\u5206\u533a\u7528\u5149\u3002<\/td>\n<td valign=\"top\">\u2013memory-swap bytes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.soft_limit_in_bytes<\/td>\n<td valign=\"top\">\u8bbe\u5b9a\u5185\u5b58\u9650\u5236\uff0c\u4f46\u8fd9\u4e2a\u9650\u5236\u5e76\u4e0d\u4f1a\u963b\u6b62\u8fdb\u7a0b\u4f7f\u7528\u8d85\u8fc7\u9650\u989d\u7684\u5185\u5b58\uff0c\u53ea\u662f\u5728\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u4f1a\u4f18\u5148\u56de\u6536\u8d85\u8fc7\u9650\u989d\u7684\u8fdb\u7a0b\u5360\u7528\u7684\u5185\u5b58\uff0c\u4f7f\u4e4b\u5411\u9650\u5b9a\u503c\u9760\u62e2\u3002<\/td>\n<td valign=\"top\">\u2013memory-reservation bytes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.kmem.limit_in_bytes<\/td>\n<td valign=\"top\">\u8bbe\u5b9a\u5185\u6838\u5185\u5b58\u4e0a\u9650\u3002<\/td>\n<td valign=\"top\">\u2013kernel-memory bytes<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.oom_control<\/td>\n<td valign=\"top\">\u5982\u679c\u8bbe\u7f6e\u4e3a0\uff0c\u90a3\u4e48\u5728\u5185\u5b58\u4f7f\u7528\u91cf\u8d85\u8fc7\u4e0a\u9650\u65f6\uff0c\u7cfb\u7edf\u4e0d\u4f1a\u6740\u6b7b\u8fdb\u7a0b\uff0c\u800c\u662f\u963b\u585e\u8fdb\u7a0b\u76f4\u5230\u6709\u5185\u5b58\u88ab\u91ca\u653e\u53ef\u4f9b\u4f7f\u7528\u65f6\uff0c\u53e6\u4e00\u65b9\u9762\uff0c\u7cfb\u7edf\u4f1a\u5411\u7528\u6237\u6001\u53d1\u9001\u4e8b\u4ef6\u901a\u77e5\uff0c\u7528\u6237\u6001\u7684\u76d1\u63a7\u7a0b\u5e8f\u53ef\u4ee5\u6839\u636e\u8be5\u4e8b\u4ef6\u6765\u505a\u76f8\u5e94\u7684\u5904\u7406\uff0c\u4f8b\u5982\u63d0\u9ad8\u5185\u5b58\u4e0a\u9650\u7b49\u3002<\/td>\n<td valign=\"top\">\u2013oom-kill-disable<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/memory\/memory.swappiness<\/td>\n<td valign=\"top\">\u63a7\u5236\u5185\u6838\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u7684\u503e\u5411\u3002\u53d6\u503c\u8303\u56f4\u662f0\u81f3100\u4e4b\u95f4\u7684\u6574\u6570\uff08\u5305\u542b0\u548c100\uff09\u3002\u503c\u8d8a\u5c0f\uff0c\u8d8a\u503e\u5411\u4f7f\u7528\u7269\u7406\u5185\u5b58\u3002<\/td>\n<td valign=\"top\">\u2013memory-swappiness int<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.2 cpu \u2014 \u4f7f\u7528\u8c03\u5ea6\u7a0b\u5e8f\u63d0\u4f9b\u5bf9 CPU \u7684 cgroup \u4efb\u52a1\u8bbf\u95ee<\/h3>\n<table border=\"1\" width=\"569\" cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"22%\"><strong>\u5b50\u7cfb\u7edf\u5e38\u7528cgroups\u63a5\u53e3<\/strong><\/td>\n<td valign=\"top\"><strong>\u63cf\u8ff0<\/strong><\/td>\n<td valign=\"top\" width=\"22%\"><strong>\u5bf9\u5e94\u7684docker\u63a5\u53e3<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/cpu\/cpu.<br \/>\nshares<\/td>\n<td valign=\"top\">\u8d1f\u8d23CPU\u6bd4\u91cd\u5206\u914d\u7684\u63a5\u53e3\u3002\u5047\u8bbe\u6211\u4eec\u5728cgroupfs\u7684\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e86\u4e24\u4e2acgroup\uff08C1\u548cC2\uff09\uff0c\u5e76\u4e14\u5c06cpu.shares\u5206\u522b\u914d\u7f6e\u4e3a512\u548c1024\uff0c\u90a3\u4e48\u5f53C1\u548cC2\u4e89\u7528CPU\u65f6\uff0cC2\u5c06\u4f1a\u6bd4C1\u5f97\u5230\u591a\u4e00\u500d\u7684CPU\u5360\u7528\u7387\u3002\u8981\u6ce8\u610f\u7684\u662f\uff0c\u53ea\u6709\u5f53\u5b83\u4eec\u4e89\u7528CPU\u65f6CPU share\u624d\u4f1a\u8d77\u4f5c\u7528\uff0c\u5982\u679cC2\u662f\u7a7a\u95f2\u7684\uff0c\u90a3\u4e48C1\u53ef\u4ee5\u5f97\u5230\u5168\u90e8\u7684CPU\u8d44\u6e90\u3002<\/td>\n<td valign=\"top\">-c, \u2013cpu-shares int<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/cpu\/cpu.<br \/>\ncfs_period_us<\/td>\n<td valign=\"top\">\u8d1f\u8d23CPU\u5e26\u5bbd\u9650\u5236\uff0c\u9700\u8981\u4e0ecpu.cfs_quota_us\u642d\u914d\u4f7f\u7528\u3002\u6211\u4eec\u53ef\u4ee5\u5c06period\u8bbe\u7f6e\u4e3a1\u79d2\uff0c\u5c06quota\u8bbe\u7f6e\u4e3a0.5\u79d2\uff0c\u90a3\u4e48cgroup\u4e2d\u7684\u8fdb\u7a0b\u57281\u79d2\u5185\u6700\u591a\u53ea\u80fd\u8fd0\u884c0.5\u79d2\uff0c\u7136\u540e\u5c31\u4f1a\u88ab\u5f3a\u5236\u7761\u7720\uff0c\u76f4\u5230\u4e0b\u4e00\u4e2a1\u79d2\u624d\u80fd\u7ee7\u7eed\u8fd0\u884c\u3002<\/td>\n<td valign=\"top\">\u2013cpu-period int<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/cpu\/cpu.<br \/>\ncfs_quota_us<\/td>\n<td valign=\"top\">\u8d1f\u8d23CPU\u5e26\u5bbd\u9650\u5236\uff0c\u9700\u8981\u4e0ecpu.cfs_period_us\u642d\u914d\u4f7f\u7528\u3002<\/td>\n<td valign=\"top\">\u2013cpu-quota<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.3 cpuset \u2014 \u4e3a cgroup \u4e2d\u7684\u4efb\u52a1\u5206\u914d\u72ec\u7acb CPU\uff08\u5728\u591a\u6838\u7cfb\u7edf\uff09\u548c\u5185\u5b58\u8282\u70b9<\/h3>\n<table border=\"1\" width=\"569\" cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"22%\"><strong>\u5b50\u7cfb\u7edf\u5e38\u7528cgroups\u63a5\u53e3<\/strong><\/td>\n<td valign=\"top\"><strong>\u63cf\u8ff0<\/strong><\/td>\n<td valign=\"top\" width=\"22%\"><strong>\u5bf9\u5e94\u7684docker\u63a5\u53e3<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/cpuset\/cpuset.cpus<\/td>\n<td valign=\"top\">\u5141\u8bb8\u8fdb\u7a0b\u4f7f\u7528\u7684CPU\u5217\u8868\uff08\u4f8b\u5982\uff1a0-4,9\uff09\u3002<\/td>\n<td valign=\"top\">\u2013cpuset-cpus string<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/cpuset\/cpuset.mems<\/td>\n<td valign=\"top\">\u5141\u8bb8\u8fdb\u7a0b\u4f7f\u7528\u7684\u5185\u5b58\u8282\u70b9\u5217\u8868\uff08\u4f8b\u5982\uff1a0-1\uff09\u3002<\/td>\n<td valign=\"top\">\u2013cpuset-mems string<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.4 blkio \u2014 \u4e3a\u5757\u8bbe\u5907\u8bbe\u5b9a\u8f93\u5165\/\u8f93\u51fa\u9650\u5236\uff0c\u6bd4\u5982\u7269\u7406\u8bbe\u5907\uff08\u78c1\u76d8\u3001\u56fa\u6001\u786c\u76d8\u3001USB\u7b49\uff09<\/h3>\n<table border=\"1\" width=\"569\" cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"22%\"><strong>\u5b50\u7cfb\u7edf\u5e38\u7528cgroups\u63a5\u53e3<\/strong><\/td>\n<td valign=\"top\"><strong>\u63cf\u8ff0<\/strong><\/td>\n<td valign=\"top\" width=\"22%\"><strong>\u5bf9\u5e94\u7684docker\u63a5\u53e3<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nweight<\/td>\n<td valign=\"top\">\u8bbe\u7f6e\u6743\u91cd\u503c\uff0c\u53d6\u503c\u8303\u56f4\u662f10\u81f31000\u4e4b\u95f4\u7684\u6574\u6570\uff08\u5305\u542b10\u548c1000\uff09\u3002\u8fd9\u8ddfcpu.shares\u7c7b\u4f3c\uff0c\u662f\u6bd4\u91cd\u5206\u914d\uff0c\u800c\u4e0d\u662f\u7edd\u5bf9\u5e26\u5bbd\u7684\u9650\u5236\uff0c\u56e0\u6b64\u53ea\u6709\u5f53\u4e0d\u540c\u7684cgroup\u5728\u4e89\u7528\u540c\u4e00\u4e2a\u5757\u8bbe\u5907\u7684\u5e26\u5bbd\u65f6\uff0c\u624d\u4f1a\u8d77\u4f5c\u7528\u3002<\/td>\n<td valign=\"top\">\u2013blkio-weight uint16<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nweight_device<\/td>\n<td valign=\"top\">\u5bf9\u5177\u4f53\u7684\u8bbe\u5907\u8bbe\u7f6e\u6743\u91cd\u503c\uff0c\u8fd9\u4e2a\u503c\u4f1a\u8986\u76d6\u4e0a\u8ff0\u7684blkio.weight\u3002<\/td>\n<td valign=\"top\">\u2013blkio-weight-device list<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nthrottle.read_bps_device<\/td>\n<td valign=\"top\">\u5bf9\u5177\u4f53\u7684\u8bbe\u5907\uff0c\u8bbe\u7f6e\u6bcf\u79d2\u8bfb\u5757\u8bbe\u5907\u7684\u5e26\u5bbd\u4e0a\u9650\u3002<\/td>\n<td valign=\"top\">\u2013device-read-bps list<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nthrottle.write_bps_device<\/td>\n<td valign=\"top\">\u8bbe\u7f6e\u6bcf\u79d2\u5199\u5757\u8bbe\u5907\u7684\u5e26\u5bbd\u4e0a\u9650\u3002\u540c\u6837\u9700\u8981\u6307\u5b9a\u8bbe\u5907\u3002<\/td>\n<td valign=\"top\">\u2013device-write-bps list<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nthrottle.read_iops_device<\/td>\n<td valign=\"top\">\u8bbe\u7f6e\u6bcf\u79d2\u8bfb\u5757\u8bbe\u5907\u7684IO\u6b21\u6570\u7684\u4e0a\u9650\u3002\u540c\u6837\u9700\u8981\u6307\u5b9a\u8bbe\u5907\u3002<\/td>\n<td valign=\"top\">\u2013device-read-iops list<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">\/sys\/fs\/cgroup\/blkio\/blkio.<br \/>\nthrottle.write_iops_device<\/td>\n<td valign=\"top\">\u8bbe\u7f6e\u6bcf\u79d2\u5199\u5757\u8bbe\u5907\u7684IO\u6b21\u6570\u7684\u4e0a\u9650\u3002\u540c\u6837\u9700\u8981\u6307\u5b9a\u8bbe\u5907\u3002<\/td>\n<td valign=\"top\">\u2013device-write-iops list<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e09\u3001Docker\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u8be6\u89e3\u53ca\u5e94\u7528\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u5185\u5bb9\u9488\u5bf9\u5404\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u505a\u4e86\u8be6\u5c3d\u7684\u8bf4\u660e\u3002\u4e3a\u4e86\u52a0\u6df1\u8bfb\u8005\u7406\u89e3\uff0c\u90e8\u5206\u63a5\u53e3\u9644\u6709\u6d4b\u8bd5\u7528\u4f8b\u3002\u7528\u4f8b\u4e2d\u7684Docker\u7248\u672c\u4e3a1.11.0\u3002\u5982\u679c\u5728\u4f60\u7684\u955c\u50cf\u4e2dstress\u547d\u4ee4\u4e0d\u53ef\u7528\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7sudo apt-get install stress\u6765\u5b89\u88c5stress\u5de5\u5177\u3002<\/p>\n<p><strong>Tips01\uff1acentos\u5b89\u88c5stress<\/strong><\/p>\n<pre>\u4e0b\u8f7d\uff1a<a title=\"http:\/\/www.hangdaowangluo.com\/downs\/stress-1.0.4.tar.gz\" href=\"http:\/\/www.hangdaowangluo.com\/downs\/stress-1.0.4.tar.gz\" target=\"_blank\" rel=\"noopener\">stress-1.0.4.tar.gz\r\n<\/a># tar xzf stress-1.0.4.tar.gz \r\n# cd stress-1.0.4\r\n# .\/configure --prefix=\/usr\/local\/stress\r\n# make &amp;&amp; make install<\/pre>\n<h3>3.1 memory\u5b50\u7cfb\u7edf<\/h3>\n<h4>3.1.1 -m, \u2013memory bytes<\/h4>\n<p>\u53ef\u4ee5\u9650\u5236\u5bb9\u5668\u4f7f\u7528\u7684\u5185\u5b58\u91cf\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes\u3002<br \/>\n\u53d6\u503c\u8303\u56f4:\u5927\u4e8e\u7b49\u4e8e4M\uff0c\u5355\u4f4d\uff1ab,k,m,g<\/p>\n<p>\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u53ef\u4ee5\u5360\u7528\u65e0\u9650\u91cf\u7684\u5185\u5b58\uff0c\u76f4\u81f3\u4e3b\u673a\u5185\u5b58\u8d44\u6e90\u8017\u5c3d\u3002\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\u6765\u786e\u8ba4\u5bb9\u5668\u5185\u5b58\u7684\u8d44\u6e90\u7ba1\u7406\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u3002<\/p>\n<pre>docker run -it --name=ins01 --memory=100m stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes\"\r\n\r\n# 104857600<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5f53\u5185\u5b58\u9650\u5b9a\u4e3a100M\u65f6\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u6570\u503c\u4e3a104857600\uff0c\u8be5\u6570\u503c\u7684\u5355\u4f4d\u4e3a\u5b57\u8282\uff0c\u5373104857600\u5b57\u8282\u7b49\u4e8e100M\u3002<\/p>\n<p>\u672c\u673a\u5185\u5b58\u73af\u5883\u4e3a\uff1a<\/p>\n<pre>$ free -m\r\n          total        used        free      shared  buff\/cache   available\r\nMem:\u00a0\u00a0\u00a0\u00a0\u00a0 992\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0  105\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 481\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 6\u00a0\u00a0\u00a0\u00a0\u00a0 405\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 711\r\nSwap:\u00a0\u00a0\u00a0\u00a0 1023\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0    1023\r\n<\/pre>\n<p>\u6211\u4eec\u4f7f\u7528stress\u5de5\u5177\u6765\u8bc1\u660e\u5185\u5b58\u9650\u5b9a\u5df2\u7ecf\u751f\u6548\u3002stress\u662f\u4e00\u4e2a\u538b\u529b\u5de5\u5177\uff0c\u5982\u4e0b\u547d\u4ee4\u5c06\u8981\u5728\u5bb9\u5668\u5185\u521b\u5efa\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u5728\u8be5\u8fdb\u7a0b\u4e2d\u4e0d\u65ad\u7684\u6267\u884c\u5360\u7528\u5185\u5b58(malloc)\u548c\u91ca\u653e\u5185\u5b58(free)\u7684\u64cd\u4f5c\u3002\u5728\u7406\u8bba\u4e0a\u5982\u679c\u5360\u7528\u7684\u5185\u5b58\u5c11\u4e8e\u9650\u5b9a\u503c\uff0c\u5bb9\u5668\u4f1a\u5de5\u4f5c\u6b63\u5e38\u3002\u6ce8\u610f\uff0c\u5982\u679c\u8bd5\u56fe\u4f7f\u7528\u8fb9\u754c\u503c\uff0c\u5373\u8bd5\u56fe\u5728\u5bb9\u5668\u4e2d\u4f7f\u7528stress\u5de5\u5177\u5360\u7528100M\u5185\u5b58\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u901a\u5e38\u4f1a\u5931\u8d25\uff0c\u56e0\u4e3a\u5bb9\u5668\u4e2d\u8fd8\u6709\u5176\u4ed6\u8fdb\u7a0b\u5728\u8fd0\u884c\u3002<\/p>\n<pre># docker run -it --name=ins01 --memory=100m stress stress --vm 1 --vm-bytes 50M\r\nstress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd\r\n<\/pre>\n<p>\u5f53\u5728\u9650\u5b9a\u5185\u5b58\u4e3a100M\u7684\u5bb9\u5668\u4e2d\uff0c\u8bd5\u56fe\u5360\u752850M\u7684\u5185\u5b58\u65f6\uff0c\u5bb9\u5668\u5de5\u4f5c\u6b63\u5e38\u3002\u5982\u4e0b\u6240\u793a\uff0c\u5f53\u8bd5\u56fe\u5360\u7528\u8d85\u8fc7100M\u5185\u5b58\u65f6\uff0c\u5bb9\u5668\u662f\u5426\u4f1a\u53d1\u751f\u5f02\u5e38\u5462\uff1f<\/p>\n<pre>$ docker run -it --name=ins01 --memory=100m stress stress --vm 1 --vm-bytes 101M\r\nstress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd\r\n<\/pre>\n<p>\u5bb9\u5668\u4f9d\u7136\u8fd0\u884c\u6b63\u5e38\uff0c\u8fd9\u662f\u539f\u56e0\u5462\uff1f\uff1f\u539f\u6765\u5728\u521b\u5efa\u5bb9\u5668ins01\u65f6\uff0c\u7cfb\u7edf\u9ed8\u8ba4\u5206\u914d\u4e86\u548c\u5185\u5b58\u7b49\u540c\u5927\u5c0f\u7684\u4ea4\u6362\u5206\u533aswap\uff0c\u53ef\u4ee5\u8fdb\u5165\u5bb9\u5668ins01\u540e\u67e5\u770b\uff1a<\/p>\n<pre>cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\r\n209715200 \/\/200M<\/pre>\n<p>\u6211\u4eec\u518d\u4f7f\u7528200M\u6d4b\u8bd5\uff0c\u5bb9\u5668\u62a5\u5f02\u5e38\u9000\u51fa\u3002<\/p>\n<pre>$ docker run -it --name=ins01 --memory=100m stress stress --vm 1 --vm-bytes 200M\r\nstress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd\r\nstress: FAIL: [1] (415) &lt;-- worker 6 got signal 9\r\nstress: WARN: [1] (417) now reaping child worker processes\r\nstress: FAIL: [1] (421) kill error: No such process\r\nstress: FAIL: [1] (451) failed run completed in 1s\r\n<\/pre>\n<p>\u6ce8\u610f\uff0c\u5728\u5b9e\u9645\u5bb9\u5668\u4f7f\u7528\u573a\u666f\u4e2d\uff0c\u5982\u679c\u4e0d\u5bf9\u5bb9\u5668\u4f7f\u7528\u5185\u5b58\u91cf\u52a0\u4ee5\u9650\u5236\u7684\u8bdd\uff0c\u53ef\u80fd\u5bfc\u81f4\u4e00\u4e2a\u5bb9\u5668\u4f1a\u8017\u5c3d\u6574\u4e2a\u4e3b\u673a\u5185\u5b58\uff0c\u4ece\u800c\u5bfc\u81f4\u7cfb\u7edf\u4e0d\u7a33\u5b9a\u3002\u6240\u4ee5\u5728\u4f7f\u7528\u5bb9\u5668\u65f6\u52a1\u5fc5\u5bf9\u5bb9\u5668\u5185\u5b58\u52a0\u4ee5\u9650\u5236\u3002<\/p>\n<h4>3.1.2 \u2013memory-swap bytes<\/h4>\n<p>\u53ef\u4ee5\u9650\u5236\u5bb9\u5668\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u548c\u5185\u5b58\u7684\u603b\u548c\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\u3002\u53d6\u503c\u8303\u56f4:\u5927\u4e8e\u5185\u5b58\u9650\u5b9a\u503c\uff08\u2013memory\u7684\u503c\uff09\uff0c\u5355\u4f4d\uff1ab,k,m,g\u3002\u8fd0\u884c\u5982\u4e0b\u547d\u4ee4\u6765\u786e\u8ba4\u5bb9\u5668\u4ea4\u6362\u5206\u533a\u7684\u8d44\u6e90\u7ba1\u7406\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u3002<\/p>\n<pre>docker run -it --name=ins01 --memory=100m --memory-swap=1G stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\n1073741824\r\n<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5f53memory-swap\u9650\u5b9a\u4e3a1G\u65f6\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u6570\u503c\u4e3a1073741824\uff0c\u8be5\u6570\u503c\u7684\u5355\u4f4d\u4e3a\u5b57\u8282\uff0c\u53731073741824B\u7b49\u4e8e1G\u3002<\/p>\n<table border=\"1\" width=\"569\" cellspacing=\"5\" cellpadding=\"5\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"40%\">\u6761\u4ef6<\/td>\n<td valign=\"top\">\u7ed3\u679c<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>\u2013memory=\u65e0\u7a77\u5927<br \/>\n\u2013memory-swap=\u65e0\u7a77\u5927<\/strong>\u00a0(\u9ed8\u8ba4\u6761\u4ef6\u4e0b)<\/td>\n<td valign=\"top\">\u7cfb\u7edf\u4e0d\u9650\u5b9a\u5bb9\u5668\u5bf9\u5185\u5b58\u548c\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u91cf\uff0c\u5bb9\u5668\u80fd\u591f\u4f7f\u7528\u4e3b\u673a\u6240\u80fd\u63d0\u4f9b\u7684\u6240\u6709\u5185\u5b58\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>\u2013memory=L&lt;\u65e0\u7a77\u5927<br \/>\n\u2013memory-swap=\u65e0\u7a77\u5927<\/strong><\/td>\n<td valign=\"top\">(\u8bbe\u5b9amemory\u9650\u5b9a\u503c\uff0c\u540c\u65f6\u5c06memory-swap\u8bbe\u7f6e\u4e3a-1) \u5bb9\u5668\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u4e0d\u80fd\u8d85\u8fc7L\uff0c\u4f46\u662f\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u91cf\u4e0d\u53d7\u9650\u5236(\u524d\u63d0\u662f\u4e3b\u673a\u652f\u6301\u4ea4\u6362\u5206\u533a)\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>\u2013memory=L&lt;\u65e0\u7a77\u5927<br \/>\n\u2013memory-swap=2*L<\/strong><\/td>\n<td valign=\"top\">(\u8bbe\u5b9amemory\u9650\u5b9a\u503c\uff0c\u800c\u4e0d\u8bbe\u7f6ememory-swap\u503c) \u5bb9\u5668\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u4e0d\u80fd\u8d85\u8fc7L\uff0c\u800c\u5185\u5b58\u4f7f\u7528\u91cf\u548c\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u91cf\u4e0d\u80fd\u8d85\u8fc7\u4e24\u500d\u7684L\u3002<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\"><strong>memory=L&lt;\u65e0\u7a77\u5927<br \/>\nmemory-swap=S&lt;\u65e0\u7a77\u5927, L&lt;=S<\/strong><\/td>\n<td valign=\"top\">(\u8bbe\u5b9a\u4e86memory\u548cmemory-swap\u7684\u9650\u5b9a\u503c) \u5bb9\u5668\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u4e0d\u80fd\u8d85\u8fc7L\uff0c\u800c\u5185\u5b58\u4f7f\u7528\u91cf\u548c\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u91cf\u4e0d\u80fd\u8d85\u8fc7S\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4f8b\u5b50\uff1a\u4ee5\u4e0b\u547d\u4ee4\u6ca1\u6709\u5bf9\u5185\u5b58\u548c\u4ea4\u6362\u5206\u533a\u8fdb\u884c\u9650\u5236\uff0c\u8fd9\u610f\u5473\u7740\u5bb9\u5668\u53ef\u4ee5\u4f7f\u7528\u65e0\u9650\u591a\u7684\u5185\u5b58\u548c\u4ea4\u6362\u5206\u533a\u3002<\/p>\n<pre>\uff03 docker run -it --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes &amp;&amp; cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\n9223372036854775807\r\n9223372036854775807\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u53ea\u9650\u5b9a\u4e86\u5185\u5b58\u4f7f\u7528\u91cf300M\uff0c\u800c\u6ca1\u6709\u9650\u5236\u4ea4\u6362\u5206\u533a\u4f7f\u7528\u91cf(-1\u610f\u5473\u7740\u4e0d\u505a\u9650\u5236)\u3002<\/p>\n<pre># docker run -it --memory=300m --memory-swap=-1 --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes &amp;&amp; cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\n314572800\r\n9223372036854775807\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u4ec5\u4ec5\u9650\u5b9a\u4e86\u5185\u5b58\u4f7f\u7528\u91cf\uff0c\u8fd9\u610f\u5473\u7740\u5bb9\u5668\u80fd\u591f\u4f7f\u7528300M\u7684\u5185\u5b58\u548c300M\u7684\u4ea4\u6362\u5206\u533a\u3002\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u603b\u7684\u5185\u5b58\u9650\u5b9a\u503c(\u5185\u5b58+\u4ea4\u6362\u5206\u533a)\u88ab\u8bbe\u7f6e\u4e3a\u4e86\u5185\u5b58\u9650\u5b9a\u503c\u7684\u4e24\u500d\u3002<\/p>\n<pre># docker run -it --memory=300m --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes &amp;&amp; cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\n314572800\r\n629145600\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u9650\u5b9a\u4e86\u5185\u5b58\u548c\u4ea4\u6362\u5206\u533a\u7684\u4f7f\u7528\u91cf\uff0c\u5bb9\u5668\u53ef\u4ee5\u4f7f\u7528300M\u7684\u5185\u5b58\u548c700M\u7684\u4ea4\u6362\u5206\u533a\u3002<\/p>\n<pre># docker run -it --memory=300m --memory-swap=1g --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes &amp;&amp; cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\n314572800\r\n1073741824\r\n<\/pre>\n<p>\u5f53memory-swap\u9650\u5b9a\u503c\u4f4e\u4e8ememory\u9650\u5b9a\u503c\u65f6\uff0c\u7cfb\u7edf\u63d0\u793a\u201dMinimum memoryswap limit should be larger than memory limit\u201d\u9519\u8bef\u3002<\/p>\n<pre># docker run -it --memory=300m --memory-swap=299m --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.limit_in_bytes &amp;&amp; cat \/sys\/fs\/cgroup\/memory\/memory.memsw.limit_in_bytes\"\r\ndocker: Error response from daemon: Minimum memoryswap limit should be larger than memory limit, see usage.\r\nSee 'docker run --help'.\r\n<\/pre>\n<p>\u5982\u4e0b\u6240\u793a\uff0c\u5f53\u5c1d\u8bd5\u5360\u7528\u7684\u5185\u5b58\u6570\u91cf\u8d85\u8fc7memory-swap\u503c\u65f6\uff0c\u5bb9\u5668\u51fa\u73b0\u5f02\u5e38\u3002<\/p>\n<pre># docker run -it --memory=100m --memory-swap=300m --name=ins01 stress stress --vm 1 --vm-bytes 301M\u00a0\r\n\r\nstress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd\r\nstress: FAIL: [1] (416) &lt;-- worker 7 got signal 9\r\nstress: WARN: [1] (418) now reaping child worker processes\r\nstress: FAIL: [1] (422) kill error: No such process\r\nstress: FAIL: [1] (452) failed run completed in 0s\r\n<\/pre>\n<p>\u5982\u4e0b\u6240\u793a\uff0c\u5f53\u5360\u7528\u5185\u5b58\u503c\u5927\u4e8ememory\u9650\u5b9a\u503c\u4f46\u5c0f\u4e8ememory-swap\u65f6\uff0c\u5bb9\u5668\u8fd0\u884c\u6b63\u5e38\u3002<\/p>\n<pre># docker run -it --memory=100m --memory-swap=300m --name=ins01 stress stress --vm 1 --vm-bytes 299M\u00a0\r\nstress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd\r\n<\/pre>\n<h4>3.1.3 \u2013memory-reservation bytes<\/h4>\n<p>\u53d6\u503c\u8303\u56f4:\u5927\u4e8e\u7b49\u4e8e0\u7684\u6574\u6570\uff0c\u5355\u4f4d\uff1ab,k,m,g\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.soft_limit_in_bytes\u3002<\/p>\n<pre># docker run -it --memory-reservation=100m --name=ins01 stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.soft_limit_in_bytes\"\r\n104857600\r\n<\/pre>\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5bb9\u5668\u80fd\u591f\u4f7f\u7528\u7684\u5185\u5b58\u91cf\u4ec5\u4ec5\u7531-m\/\u2013memory\u9009\u9879\u9650\u5b9a\u3002\u5982\u679c\u8bbe\u7f6e\u4e86\u2013memory-reservation\u9009\u9879\uff0c\u5f53\u5185\u5b58\u4f7f\u7528\u91cf\u8d85\u8fc7\u2013memory-reservation\u9009\u9879\u6240\u8bbe\u5b9a\u7684\u503c\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5f3a\u5236\u5bb9\u5668\u6267\u884c\u56de\u6536\u5185\u5b58\u7684\u64cd\u4f5c\uff0c\u4f7f\u5f97\u5bb9\u5668\u5185\u5b58\u6d88\u8017\u4e0d\u4f1a\u957f\u65f6\u95f4\u8d85\u8fc7\u2013memory-reservation\u7684\u9650\u5b9a\u503c\u3002\u8fd9\u4e2a\u9650\u5236\u5e76\u4e0d\u4f1a\u963b\u6b62\u8fdb\u7a0b\u4f7f\u7528\u8d85\u8fc7\u9650\u989d\u7684\u5185\u5b58\uff0c\u53ea\u662f\u5728\u7cfb\u7edf\u5185\u5b58\u4e0d\u8db3\u65f6\uff0c\u4f1a\u56de\u6536\u90e8\u5206\u5185\u5b58\uff0c\u4f7f\u5185\u5b58\u4f7f\u7528\u91cf\u5411\u9650\u5b9a\u503c\u9760\u62e2\u3002<\/p>\n<p>\u5728\u4ee5\u4e0b\u547d\u4ee4\u4e2d\uff0c\u5bb9\u5668\u5bf9\u5185\u5b58\u7684\u4f7f\u7528\u91cf\u4e0d\u4f1a\u8d85\u8fc7500M\uff0c\u8fd9\u662f\u786c\u6027\u9650\u5236\u3002\u5f53\u5185\u5b58\u4f7f\u7528\u91cf\u5927\u4e8e200M\u800c\u5c0f\u4e8e500M\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c1d\u8bd5\u56de\u6536\u90e8\u5206\u5185\u5b58\uff0c\u4f7f\u5f97\u5185\u5b58\u4f7f\u7528\u91cf\u4f4e\u4e8e200M\u3002<\/p>\n<pre># docker run -it -m 500M --memory-reservation 200M stress bash\r\n<\/pre>\n<p>\u5728\u5982\u4e0b\u547d\u4ee4\u4e2d\uff0c\u5bb9\u5668\u4f7f\u7528\u7684\u5185\u5b58\u91cf\u4e0d\u53d7\u9650\u5236\uff0c\u4f46\u5bb9\u5668\u6d88\u8017\u7684\u5185\u5b58\u91cf\u4e0d\u4f1a\u957f\u65f6\u95f4\u8d85\u8fc71G\uff0c\u56e0\u4e3a\u5f53\u5bb9\u5668\u5185\u5b58\u4f7f\u7528\u91cf\u8d85\u8fc71G\u65f6\uff0c\u7cfb\u7edf\u4f1a\u5c1d\u8bd5\u56de\u6536\u5185\u5b58\u4f7f\u5185\u5b58\u4f7f\u7528\u91cf\u4f4e\u4e8e1G\u3002<\/p>\n<pre># docker run -it --memory-reservation 1G stress bash\r\n<\/pre>\n<h4>3.1.4 \u2013kernel-memory bytes<\/h4>\n<p>\u8be5\u63a5\u53e3\u9650\u5236\u4e86\u5bb9\u5668\u5bf9\u5185\u6838\u5185\u5b58\u7684\u4f7f\u7528\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.kmem.limit_in_bytes\u3002<\/p>\n<pre># docker run -ti --kernel-memory 50M stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.kmem.limit_in_bytes\"\r\n52428800\r\n<\/pre>\n<p>\u5982\u4e0b\u547d\u4ee4\u53ef\u4ee5\u9650\u5b9a\u5bb9\u5668\u6700\u591a\u53ef\u4ee5\u4f7f\u7528500M\u7684\u5185\u5b58\u3002\u5728500M\u5185\u5b58\u4e2d\uff0c\u5185\u6838\u5185\u5b58\u6700\u591a\u53ef\u4ee5\u5360\u752850M\u3002<\/p>\n<pre># docker run -it -m 500M --kernel-memory 50M stress bash\r\n<\/pre>\n<p>\u5982\u4e0b\u547d\u4ee4\u53ef\u4ee5\u9650\u5b9a\u5bb9\u5668\u6700\u591a\u53ef\u4ee5\u4f7f\u752850M\u7684\u5185\u6838\u5185\u5b58\uff0c\u800c\u7528\u6237\u7a7a\u95f4\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u4e0d\u53d7\u9650\u5236\u3002<\/p>\n<pre># docker run -it --kernel-memory 50M stress bash\r\n<\/pre>\n<h4>3.1.5 \u2013oom-kill-disable=false<\/h4>\n<p>\u5f53out-of-memory (OOM)\u53d1\u751f\u65f6\uff0c\u7cfb\u7edf\u4f1a\u9ed8\u8ba4\u6740\u6389\u5bb9\u5668\u8fdb\u7a0b\uff0c\u5982\u679c\u4f60\u4e0d\u60f3\u8ba9\u5bb9\u5668\u8fdb\u7a0b\u88ab\u6740\u6389\uff0c\u53ef\u4ee5\u4f7f\u7528\u8be5\u63a5\u53e3\u3002\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.oom_control\u3002<\/p>\n<p>\u5f53\u5bb9\u5668\u8bd5\u56fe\u4f7f\u7528\u8d85\u8fc7\u9650\u5b9a\u5927\u5c0f\u7684\u5185\u5b58\u503c\u65f6\uff0c\u5c31\u4f1a\u89e6\u53d1OOM\u3002\u6b64\u65f6\u4f1a\u6709\u4e24\u79cd\u60c5\u51b5\uff0c\u7b2c\u4e00\u79cd\u60c5\u51b5\u662f\u5f53\u63a5\u53e3\u2013oom-kill-disable=false\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u4f1a\u88ab\u6740\u6389\uff1b\u7b2c\u4e8c\u79cd\u60c5\u51b5\u662f\u5f53\u63a5\u53e3\u2013oom-kill-disable=true\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u4f1a\u88ab\u6302\u8d77\u3002<\/p>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u8bbe\u7f6e\u4e86\u5bb9\u5668\u7684\u7684\u5185\u5b58\u4f7f\u7528\u9650\u5236\u4e3a20M\uff0c\u5c06\u2013oom-kill-disable\u63a5\u53e3\u7684\u503c\u8bbe\u7f6e\u4e3atrue\u3002\u67e5\u770b\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\uff0coom_kill_disable\u7684\u503c\u4e3a1\u3002<\/p>\n<pre># docker run -it --name=ins01 --oom-kill-disable stress bash -c \"cat \/sys\/fs\/cgroup\/memory\/memory.oom_control\"\r\noom_kill_disable 1\r\nunder_oom 0\r\n<\/pre>\n<ul>\n<li><strong>oom_kill_disable\uff1a<\/strong>\u53d6\u503c\u4e3a0\u62161\uff0c\u5f53\u503c\u4e3a1\u7684\u65f6\u5019\u8868\u793a\u5f53\u5bb9\u5668\u8bd5\u56fe\u4f7f\u7528\u8d85\u51fa\u5185\u5b58\u9650\u5236\u65f6\uff08\u537320M\uff09\uff0c\u5bb9\u5668\u4f1a\u6302\u8d77\u3002<\/li>\n<li><strong>under_oom\uff1a<\/strong>\u53d6\u503c\u4e3a0\u62161\uff0c\u5f53\u503c\u4e3a1\u7684\u65f6\u5019\uff0cOOM\u5df2\u7ecf\u51fa\u73b0\u5728\u5bb9\u5668\u4e2d\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7x=a; while true; do x=xx; done\u547d\u4ee4\u6765\u8017\u5c3d\u5185\u5b58\u5e76\u5f3a\u5236\u89e6\u53d1OOM\uff0clog\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>$ docker run -m 20m --oom-kill-disable=false stress bash -c 'x=a; while true; do x=$x$x$x$x; done'\r\n$ echo $?\r\n137\r\n<\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684log\u53ef\u4ee5\u770b\u51fa,\u5f53\u5bb9\u5668\u7684\u5185\u5b58\u8017\u5c3d\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u9000\u51fa\uff0c\u9000\u51fa\u7801\u4e3a137\u3002\u56e0\u4e3a\u5bb9\u5668\u8bd5\u56fe\u4f7f\u7528\u8d85\u51fa\u9650\u5b9a\u7684\u5185\u5b58\u91cf\uff0c\u7cfb\u7edf\u4f1a\u89e6\u53d1OOM\uff0c\u5bb9\u5668\u4f1a\u88ab\u6740\u6389\uff0c\u6b64\u65f6under_oom\u7684\u503c\u4e3a1\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u4e2dcgroup\u6587\u4ef6(\/sys\/fs\/cgroup\/memory\/docker\/${container_id}\/memory.oom_control)\u67e5\u770bunder_oom\u7684\u503c\uff08oom_kill_disable 1\uff0cunder_oom 1\uff09\u3002<\/p>\n<p>\u5f53\u2013oom-kill-disable=true\u7684\u65f6\u5019\uff0c\u5bb9\u5668\u4e0d\u4f1a\u88ab\u6740\u6389\uff0c\u800c\u662f\u88ab\u7cfb\u7edf\u6302\u8d77\u3002<\/p>\n<pre>$ docker run -m 20m --oom-kill-disable=true stress bash -c 'x=a; while true; do x=$x$x$x$x; done'\r\n<\/pre>\n<h4>3.1.6 \u2013memory-swappiness int<\/h4>\n<p>\u8be5\u63a5\u53e3\u53ef\u4ee5\u8bbe\u5b9a\u5bb9\u5668\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u7684\u8d8b\u52bf\uff0c\u53d6\u503c\u8303\u56f4\u4e3a0\u81f3100\u7684\u6574\u6570\uff08\u5305\u542b0\u548c100\uff09\u30020\u8868\u793a\u5bb9\u5668\u4e0d\u4f7f\u7528\u4ea4\u6362\u5206\u533a\uff0c100\u8868\u793a\u5bb9\u5668\u5c3d\u53ef\u80fd\u591a\u7684\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u3002\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/memory\/memory.swappiness\u3002<\/p>\n<pre>$ docker run --memory-swappiness=100 stress bash -c 'cat \/sys\/fs\/cgroup\/memory\/memory.swappiness'\r\n100\r\n<\/pre>\n<h3>3.2 cpu\u5b50\u7cfb\u7edf<\/h3>\n<h4>3.2.1 -c, \u2013cpu-shares int<\/h4>\n<p>\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/cpu\/cpu.shares\u3002<\/p>\n<pre>$ docker run --rm --cpu-shares 1600 stress bash -c \"cat \/sys\/fs\/cgroup\/cpu\/cpu.shares\"\r\n1600\r\n<\/pre>\n<p>\u901a\u8fc7\u2013cpu-shares\u53ef\u4ee5\u8bbe\u7f6e\u5bb9\u5668\u4f7f\u7528CPU\u7684\u6743\u91cd\uff0c\u8fd9\u4e2a\u6743\u91cd\u8bbe\u7f6e\u662f\u9488\u5bf9CPU\u5bc6\u96c6\u578b\u7684\u8fdb\u7a0b\u7684\u3002\u5982\u679c\u67d0\u4e2a\u5bb9\u5668\u4e2d\u7684\u8fdb\u7a0b\u662f\u7a7a\u95f2\u72b6\u6001\uff0c\u90a3\u4e48\u5176\u5b83\u5bb9\u5668\u5c31\u80fd\u591f\u4f7f\u7528\u672c\u8be5\u7531\u7a7a\u95f2\u5bb9\u5668\u5360\u7528\u7684CPU\u8d44\u6e90\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ea\u6709\u5f53\u4e24\u4e2a\u6216\u591a\u4e2a\u5bb9\u5668\u90fd\u8bd5\u56fe\u5360\u7528\u6574\u4e2aCPU\u8d44\u6e90\u65f6\uff0c\u2013cpu-shares\u8bbe\u7f6e\u624d\u4f1a\u6709\u6548\u3002<br \/>\n\u6211\u4eec\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u6765\u521b\u5efa\u4e24\u4e2a\u5bb9\u5668\uff0c\u5b83\u4eec\u7684\u6743\u91cd\u5206\u522b\u4e3a1024\u548c512\u3002<\/p>\n<pre>$ docker run -ti --cpu-shares 1024 --cpuset-cpus=0 stress stress -c 1\r\nstress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd\r\n\r\n$ docker run -ti --cpu-shares 512 --cpuset-cpus=0 stress stress -c 1\r\nstress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd\r\n<\/pre>\n<p>\u4ece\u5982\u4e0btop\u547d\u4ee4\u7684log\u53ef\u4ee5\u770b\u5230\uff0c\u7b2c\u4e00\u4e2a\u5bb9\u5668\u4ea7\u751f\u7684\u8fdb\u7a0bPID\u4e3a13281\uff0cCPU\u5360\u7528\u7387\u4e3a66.9%\uff0c\u7b2c\u4e8c\u4e2a\u5bb9\u5668\u4ea7\u751f\u8fdb\u7a0bPID\u4e3a13372\uff0cCPU\u5360\u7528\u7387\u4e3a33.1%\u3002\u4e24\u4e2a\u5bb9\u5668CPU\u5360\u7528\u7387\u7ea6\u4e3a2:1\u7684\u5173\u7cfb\uff0c\u6d4b\u8bd5\u7ed3\u679c\u4e0e\u9884\u671f\u76f8\u7b26\u3002<\/p>\n<pre>top - 08:02:20 up\u00a0 4:50,\u00a0 3 users,\u00a0 load average: 1.97, 1.21, 0.54\r\nTasks: 126 total,\u00a0\u00a0 3 running, 123 sleeping,\u00a0\u00a0 0 stopped,\u00a0\u00a0 0 zombie\r\n%Cpu(s): 18.7 us,\u00a0 0.1 sy,\u00a0 0.0 ni, 81.2 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\nKiB Mem :\u00a0 1016488 total,\u00a0\u00a0 730628 free,\u00a0\u00a0\u00a0 81788 used,\u00a0\u00a0 204072 buff\/cache\r\nKiB Swap:\u00a0 1048572 total,\u00a0\u00a0 985112 free,\u00a0\u00a0\u00a0 63460 used.\u00a0\u00a0 772316 avail Mem \r\n\r\n\u00a0 PID USER\u00a0\u00a0\u00a0\u00a0\u00a0 PR\u00a0 NI\u00a0\u00a0\u00a0 VIRT\u00a0\u00a0\u00a0 RES\u00a0\u00a0\u00a0 SHR S\u00a0 %CPU %MEM\u00a0\u00a0\u00a0\u00a0 TIME+ COMMAND\r\n13281 root\u00a0\u00a0\u00a0\u00a0\u00a0 20\u00a0\u00a0 0\u00a0\u00a0\u00a0 7256\u00a0\u00a0\u00a0\u00a0 96\u00a0\u00a0\u00a0\u00a0\u00a0 0 R\u00a0 66.9\u00a0 0.0\u00a0\u00a0 2:40.10 stress\r\n13372 root\u00a0\u00a0\u00a0\u00a0\u00a0 20\u00a0\u00a0 0\u00a0\u00a0\u00a0 7256\u00a0\u00a0\u00a0\u00a0 96\u00a0\u00a0\u00a0\u00a0\u00a0 0 R\u00a0 33.1\u00a0 0.0\u00a0\u00a0 1:13.13 stress\r\n<\/pre>\n<h4>3.2.2 \u2013cpu-period int<\/h4>\n<p>\u5185\u6838\u9ed8\u8ba4\u7684Linux \u8c03\u5ea6CFS\uff08\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\u5668\uff09\u5468\u671f\u4e3a100ms,\u6211\u4eec\u901a\u8fc7\u2013cpu-period\u6765\u8bbe\u7f6e\u5bb9\u5668\u5bf9CPU\u7684\u4f7f\u7528\u5468\u671f\uff0c\u540c\u65f6\u2013cpu-period\u63a5\u53e3\u9700\u8981\u548c\u2013cpu-quota\u63a5\u53e3\u4e00\u8d77\u6765\u4f7f\u7528\u3002\u2013cpu-quota\u63a5\u53e3\u8bbe\u7f6e\u4e86CPU\u7684\u4f7f\u7528\u503c\u3002CFS(\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\u5668) \u662f\u5185\u6838\u9ed8\u8ba4\u4f7f\u7528\u7684\u8c03\u5ea6\u65b9\u5f0f\uff0c\u4e3a\u8fd0\u884c\u7684\u8fdb\u7a0b\u5206\u914dCPU\u8d44\u6e90\u3002\u5bf9\u4e8e\u591a\u6838CPU\uff0c\u6839\u636e\u9700\u8981\u8c03\u6574\u2013cpu-quota\u7684\u503c\u3002<\/p>\n<p>\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/sf\/cgroup\/cpu\/cpu.cfs_period_us\u3002\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u4e86\u4e00\u4e2a\u5bb9\u5668\uff0c\u540c\u65f6\u8bbe\u7f6e\u4e86\u8be5\u5bb9\u5668\u5bf9CPU\u7684\u4f7f\u7528\u65f6\u95f4\u4e3a50000\uff08\u5355\u4f4d\u4e3a\u5fae\u79d2\uff09\uff0c\u5e76\u9a8c\u8bc1\u4e86\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<pre># docker run -it --cpu-period 50000 --cpuset-cpus=0 stress bash -c \"cat \/sys\/fs\/cgroup\/cpu\/cpu.cfs_period_us\"\r\n50000\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u5c06\u2013cpu-period\u7684\u503c\u8bbe\u7f6e\u4e3a50000,\u2013cpu-quota\u7684\u503c\u8bbe\u7f6e\u4e3a25000\u3002\u8be5\u5bb9\u5668\u5728\u8fd0\u884c\u65f6\u53ef\u4ee5\u83b7\u53d650%\u7684cpu\u8d44\u6e90\u3002<\/p>\n<pre>$ docker run -it --cpu-period 50000 --cpu-quota=25000 --cpuset-cpus=0 stress stress -c 1\r\nstress: info: [1] dispatching hogs: 1 cpu, 0 io, 0 vm, 0 hdd\r\n<\/pre>\n<p>\u4ecelog\u7684\u6700\u540e\u4e00\u884c\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u8be5\u5bb9\u5668\u7684cpu\u4f7f\u7528\u7387\u7ea6\u4e3a50.0%\u3002<\/p>\n<pre>top - 08:14:31 up\u00a0 5:02,\u00a0 3 users,\u00a0 load average: 0.83, 0.96, 0.89\r\nTasks: 121 total,\u00a0\u00a0 3 running, 118 sleeping,\u00a0\u00a0 0 stopped,\u00a0\u00a0 0 zombie\r\n%Cpu(s):\u00a0 8.7 us,\u00a0 0.1 sy,\u00a0 0.0 ni, 91.3 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\nKiB Mem :\u00a0 1016488 total,\u00a0\u00a0 737152 free,\u00a0\u00a0\u00a0 74696 used,\u00a0\u00a0 204640 buff\/cache\r\nKiB Swap:\u00a0 1048572 total,\u00a0\u00a0 985196 free,\u00a0\u00a0\u00a0 63376 used.\u00a0\u00a0 779352 avail Mem \r\n\r\n\u00a0 PID USER\u00a0\u00a0\u00a0\u00a0\u00a0 PR\u00a0 NI\u00a0\u00a0\u00a0 VIRT\u00a0\u00a0\u00a0 RES\u00a0\u00a0\u00a0 SHR S\u00a0 %CPU %MEM\u00a0\u00a0\u00a0\u00a0 TIME+ COMMAND\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n13871 root\u00a0\u00a0\u00a0\u00a0\u00a0 20\u00a0\u00a0 0\u00a0\u00a0\u00a0 7256\u00a0\u00a0\u00a0\u00a0 96\u00a0\u00a0\u00a0\u00a0\u00a0 0 R\u00a0 48.8\u00a0 0.0\u00a0\u00a0 0:59.16 stress\r\n<\/pre>\n<h4>3.2.3 \u2013cpu-quota int<\/h4>\n<p>\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/cpu\/cpu.cfs_quota_us\u3002<\/p>\n<pre>$ docker run --cpu-quota 1600 --cpuset-cpus=0 stress bash -c \"cat \/sys\/fs\/cgroup\/cpu\/cpu.cfs_quota_us\"\r\n1600\r\n<\/pre>\n<p>\u2013cpu-quota\u63a5\u53e3\u8bbe\u7f6e\u4e86CPU\u7684\u4f7f\u7528\u503c\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u5b83\u9700\u8981\u548c\u2013cpu-period\u63a5\u53e3\u4e00\u8d77\u6765\u4f7f\u7528\u3002\u5177\u4f53\u4f7f\u7528\u65b9\u6cd5\u8bf7\u53c2\u8003\u2013cpu-period\u9009\u9879\u3002<\/p>\n<h3>3.3 cpuset\u5b50\u7cfb\u7edf<\/h3>\n<h4>3.3.1 \u2013cpuset-cpus<\/h4>\n<p>\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/sf\/cgroup\/cpuset\/cpuset.cpus\u3002<\/p>\n<p>\u5728\u591a\u6838CPU\u7684\u865a\u62df\u673a\u4e2d\uff0c\u542f\u52a8\u4e00\u4e2a\u5bb9\u5668\uff0c\u8bbe\u7f6e\u5bb9\u5668\u53ea\u4f7f\u7528CPU\u68381\uff0c\u5e76\u67e5\u770b\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u4f1a\u88ab\u4fee\u6539\u4e3a1\uff0clog\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>$ docker run -ti --cpuset-cpus 1 stress bash -c \"cat \/sys\/fs\/cgroup\/cpuset\/cpuset.cpus\"\r\n1\r\n<\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6307\u5b9a\u5bb9\u5668\u4f7f\u7528cpu\u68381\uff0c\u5e76\u901a\u8fc7stress\u547d\u4ee4\u52a0\u538b\u3002<\/p>\n<pre>$ docker run -ti --cpuset-cpus 1 stress stress -c 1\r\n<\/pre>\n<p>\u67e5\u770bCPU\u8d44\u6e90\u7684top\u547d\u4ee4\u7684log\u5982\u4e0b\u6240\u793a\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<strong>\u8f93\u5165top\u547d\u4ee4\u5e76\u6309\u56de\u8f66\u952e\u540e\uff0c\u518d\u6309\u6570\u5b57\u952e1<\/strong>\uff0c\u7ec8\u7aef\u624d\u80fd\u663e\u793a\u6bcf\u4e2aCPU\u7684\u72b6\u6001\u3002<\/p>\n<pre>top - 08:19:14 up\u00a0 5:07,\u00a0 3 users,\u00a0 load average: 0.17, 0.44, 0.68\r\nTasks: 126 total,\u00a0\u00a0 2 running, 124 sleeping,\u00a0\u00a0 0 stopped,\u00a0\u00a0 0 zombie\r\n%Cpu0\u00a0 :\u00a0 0.3 us,\u00a0 0.0 sy,\u00a0 0.0 ni, 99.7 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\n%Cpu1\u00a0 :100.0 us,\u00a0 0.0 sy,\u00a0 0.0 ni,\u00a0 0.0 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\n%Cpu2\u00a0 :\u00a0 0.0 us,\u00a0 0.0 sy,\u00a0 0.0 ni,100.0 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\n%Cpu3\u00a0 :\u00a0 0.0 us,\u00a0 0.0 sy,\u00a0 0.0 ni,100.0 id,\u00a0 0.0 wa,\u00a0 0.0 hi,\u00a0 0.0 si,\u00a0 0.0 st\r\nKiB Mem :\u00a0 1016488 total,\u00a0\u00a0 736128 free,\u00a0\u00a0\u00a0 75164 used,\u00a0\u00a0 205196 buff\/cache\r\nKiB Swap:\u00a0 1048572 total,\u00a0\u00a0 985224 free,\u00a0\u00a0\u00a0 63348 used.\u00a0\u00a0 778680 avail Mem \r\n\r\n\u00a0 PID USER\u00a0\u00a0\u00a0\u00a0\u00a0 PR\u00a0 NI\u00a0\u00a0\u00a0 VIRT\u00a0\u00a0\u00a0 RES\u00a0\u00a0\u00a0 SHR S\u00a0 %CPU %MEM\u00a0\u00a0\u00a0\u00a0 TIME+ COMMAND\r\n14108 root\u00a0\u00a0\u00a0\u00a0\u00a0 20\u00a0\u00a0 0\u00a0\u00a0\u00a0 7256\u00a0\u00a0\u00a0\u00a0 96\u00a0\u00a0\u00a0\u00a0\u00a0 0 R\u00a0 99.7\u00a0 0.0\u00a0\u00a0 0:12.43 stress \r\n<\/pre>\n<p>\u4ece\u4ee5\u4e0alog\u5f97\u77e5\uff0c\u53ea\u6709CPU\u68381\u7684\u8d1f\u8f7d\u4e3a100%\uff0c\u800c\u5176\u5b83CPU\u6838\u5904\u4e8e\u7a7a\u95f2\u72b6\u6001\uff0c\u7ed3\u679c\u4e0e\u9884\u671f\u7ed3\u679c\u76f8\u7b26\u3002<\/p>\n<h4>3.3.2 \u2013cpuset-mems<\/h4>\n<p>\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/sf\/cgroup\/cpuset\/cpuset.mems<\/p>\n<pre>$ docker run -ti --cpuset-mems=0 stress bash -c \"cat \/sys\/fs\/cgroup\/cpuset\/cpuset.mems\"\r\n0\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u5c06\u9650\u5236\u5bb9\u5668\u8fdb\u7a0b\u4f7f\u7528\u5185\u5b58\u8282\u70b91\u30013\u7684\u5185\u5b58\u3002<\/p>\n<pre>$ docker run -it --cpuset-mems=\"1,3\" stress bash\r\n<\/pre>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u5c06\u9650\u5236\u5bb9\u5668\u8fdb\u7a0b\u4f7f\u7528\u5185\u5b58\u8282\u70b90\u30011\u30012\u7684\u5185\u5b58\u3002<\/p>\n<pre>$ docker run -it --cpuset-mems=\"0-2\" stress bash\r\n<\/pre>\n<h3>3.4 blkio\u5b50\u7cfb\u7edf<\/h3>\n<h4>3.4.1 \u2013blkio-weight uint16<\/h4>\n<p>\u901a\u8fc7\u2013blkio-weight\u63a5\u53e3\u53ef\u4ee5\u8bbe\u7f6e\u5bb9\u5668\u5757\u8bbe\u5907IO\u7684\u6743\u91cd\uff0c\u6709\u6548\u503c\u8303\u56f4\u4e3a10\u81f31000\u7684\u6574\u6570(\u5305\u542b10\u548c1000)\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u5bb9\u5668\u90fd\u4f1a\u5f97\u5230\u76f8\u540c\u7684\u6743\u91cd\u503c(500)\u3002\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u4e3a\/sys\/fs\/cgroup\/blkio\/blkio.weight\u3002\u4ee5\u4e0b\u547d\u4ee4\u8bbe\u7f6e\u4e86\u5bb9\u5668\u5757\u8bbe\u5907IO\u6743\u91cd\u4e3a10\uff0c\u5728log\u4e2d\u53ef\u4ee5\u770b\u5230\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u7684\u503c\u4e3a10\u3002<\/p>\n<pre>$ docker run -ti --rm --blkio-weight 10 stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.weight\"\r\n10\r\n<\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0b\u4e24\u4e2a\u547d\u4ee4\u6765\u521b\u5efa\u4e0d\u540c\u5757\u8bbe\u5907IO\u6743\u91cd\u503c\u7684\u5bb9\u5668\u3002<\/p>\n<pre>$ docker run -it --name c1 --blkio-weight 300 stress \/bin\/bash\r\n$ docker run -it --name c2 --blkio-weight 600 stress \/bin\/bash\r\n<\/pre>\n<p>\u5982\u679c\u5728\u4e24\u4e2a\u5bb9\u5668\u4e2d\u540c\u65f6\u8fdb\u884c\u5757\u8bbe\u5907\u64cd\u4f5c\uff08\u4f8b\u5982\u4ee5\u4e0b\u547d\u4ee4\uff09\u7684\u8bdd\uff0c\u4f60\u4f1a\u53d1\u73b0\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u548c\u5bb9\u5668\u6240\u62e5\u6709\u7684\u5757\u8bbe\u5907IO\u6743\u91cd\u6210\u53cd\u6bd4\u3002<\/p>\n<pre>$ time dd if=\/mnt\/zerofile of=test.out bs=1M count=1024 oflag=direct\r\n<\/pre>\n<h4>3.4.2 \u2013blkio-weight-device<\/h4>\n<p>\u901a\u8fc7\u2013blkio-weight-device=\u201d\u8bbe\u5907\u540d:\u6743\u91cd\u201d\u63a5\u53e3\u53ef\u4ee5\u8bbe\u7f6e\u5bb9\u5668\u5bf9\u7279\u5b9a\u5757\u8bbe\u5907IO\u7684\u6743\u91cd\uff0c\u6709\u6548\u503c\u8303\u56f4\u4e3a10\u81f31000\u7684\u6574\u6570(\u5305\u542b10\u548c1000)\u3002<br \/>\n\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u4e3a\/sys\/fs\/cgroup\/blkio\/blkio.weight_device\u3002<\/p>\n<pre>$ docker run --blkio-weight-device \"\/dev\/sda:1000\" stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.weight_device\"\r\n8:0 1000\r\n<\/pre>\n<p>\u4ee5\u4e0alog\u4e2d\u7684\u201d8:0\u2033\u8868\u793asda\u7684\u8bbe\u5907\u53f7\uff0c\u53ef\u4ee5\u901a\u8fc7stat\u547d\u4ee4\u6765\u83b7\u53d6\u67d0\u4e2a\u8bbe\u5907\u7684\u8bbe\u5907\u53f7\u3002\u4ece\u4ee5\u4e0blog\u4e2d\u53ef\u4ee5\u67e5\u770b\u5230\/dev\/sda\u5bf9\u5e94\u7684\u4e3b\u8bbe\u5907\u53f7\u4e3a8\uff0c\u6b21\u8bbe\u5907\u53f7\u4e3a0\u3002<\/p>\n<pre>$ stat -c %t:%T \/dev\/sda\r\n8:0\r\n<\/pre>\n<p>\u5982\u679c\u2013blkio-weight-device\u63a5\u53e3\u548c\u2013blkio-weight\u63a5\u53e3\u4e00\u8d77\u4f7f\u7528\uff0c\u90a3\u4e48Docker\u4f1a\u4f7f\u7528\u2013blkio-weight\u503c\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u6743\u91cd\u503c\uff0c\u7136\u540e\u4f7f\u7528\u2013blkio-weight-device\u503c\u6765\u8bbe\u5b9a\u6307\u5b9a\u8bbe\u5907\u7684\u6743\u91cd\u503c\uff0c\u800c\u65e9\u5148\u8bbe\u7f6e\u7684\u9ed8\u8ba4\u6743\u91cd\u503c\u5c06\u4e0d\u5728\u8fd9\u4e2a\u7279\u5b9a\u8bbe\u5907\u4e2d\u751f\u6548\u3002<\/p>\n<pre>$ docker run --blkio-weight 300 --blkio-weight-device \"\/dev\/sda:500\" stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.weight_device\"\r\n8:0 500\r\n<\/pre>\n<p>\u901a\u8fc7\u4ee5\u4e0alog\u53ef\u4ee5\u770b\u51fa\uff0c\u5f53\u2013blkio-weight\u63a5\u53e3\u548c\u2013blkio-weight-device\u63a5\u53e3\u4e00\u8d77\u4f7f\u7528\u7684\u65f6\u5019\uff0c\/dev\/sda\u8bbe\u5907\u7684\u6743\u91cd\u503c\u7531\u2013blkio-weight-device\u8bbe\u5b9a\u7684\u503c\u6765\u51b3\u5b9a\u3002<\/p>\n<h4>3.4.3 \u2013device-read-bps<\/h4>\n<p>\u8be5\u63a5\u53e3\u7528\u6765\u9650\u5236\u6307\u5b9a\u8bbe\u5907\u7684\u8bfb\u53d6\u901f\u7387\uff0c\u5355\u4f4d\u53ef\u4ee5\u662fkb\u3001mb\u6216\u8005gb\u3002\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/blkio\/blkio.throttle.read_bps_device\u3002<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-read-bps \/dev\/sda:1mb stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.throttle.read_bps_device\"\r\n8:0 1048576\r\n<\/pre>\n<p>\u4ee5\u4e0alog\u4e2d\u663e\u793a8:0 1000,8:0\u8868\u793a\/dev\/sda, \u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u7684\u503c\u4e3a1048576\uff0c\u662f1MB\u6240\u5bf9\u5e94\u7684\u5b57\u8282\u6570\uff0c\u53731024\u7684\u5e73\u65b9\u3002<\/p>\n<p>\u521b\u5efa\u5bb9\u5668\u65f6\u901a\u8fc7\u2013device-read-bps\u63a5\u53e3\u8bbe\u7f6e\u8bbe\u5907\u8bfb\u53d6\u901f\u5ea6\u4e3a1MB\/s\u3002\u4ece\u4ee5\u4e0blog\u4e2d\u53ef\u4ee5\u770b\u51fa,\u8bfb\u53d6\u901f\u5ea6\u88ab\u9650\u5b9a\u4e3a1.0MB\/s,\u4e0e\u9884\u671f\u7ed3\u679c\u76f8\u7b26\u5408\u3002<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-read-bps \/dev\/sda:1mB stress bash\r\n\r\n# \u8fdb\u5165\u5bb9\u5668\r\n[root@29d953b8ad60 \/]# dd iflag=direct,nonblock if=\/dev\/sda of=\/dev\/null bs=10M count=1\r\n1+0 records in\r\n1+0 records out\r\n10485760 bytes (10 MB) copied, 10.0098 s, 1.0 MB\/s\r\n<\/pre>\n<h4>3.4.4 \u2013device-write-bps<\/h4>\n<p>\u8be5\u63a5\u53e3\u7528\u6765\u9650\u5236\u6307\u5b9a\u8bbe\u5907\u7684\u5199\u901f\u7387\uff0c\u5355\u4f4d\u53ef\u4ee5\u662fkb\u3001mb\u6216\u8005gb\u3002\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/blkio\/blkio.throttle.write_bps_device\u3002<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-write-bps \/dev\/sda:1mB stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.throttle.write_bps_device\"\r\n8:0 1048576\r\n<\/pre>\n<p>\u4ee5\u4e0alog\u4e2d\u663e\u793a8:0 1000\uff0c8:0\u8868\u793a\/dev\/sda, \u8be5\u63a5\u53e3\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u7684\u503c\u4e3a1048576\uff0c\u662f1MB\u6240\u5bf9\u5e94\u7684\u5b57\u8282\u6570\uff0c\u53731024\u7684\u5e73\u65b9\u3002<\/p>\n<p>\u521b\u5efa\u5bb9\u5668\u65f6\u901a\u8fc7\u2013device-write-bps\u63a5\u53e3\u8bbe\u7f6e\u8bbe\u5907\u5199\u901f\u5ea6\u4e3a1MB\/s\u3002\u4ece\u4ee5\u4e0blog\u4e2d\u53ef\u4ee5\u770b\u51fa,\u8bfb\u53d6\u901f\u5ea6\u88ab\u9650\u5b9a\u4e3a1.0MB\/s,\u4e0e\u9884\u671f\u7ed3\u679c\u76f8\u7b26\u5408\u3002\u9650\u901f\u64cd\u4f5c\uff1a<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-write-bps \/dev\/sda:1mb stress bash\r\n\r\n#\u8fdb\u5165\u5bb9\u5668\r\n[root@61e6b704da5c \/]# dd oflag=direct,nonblock of=\/dev\/sda if=\/dev\/urandom bs=10K count=1000\r\n1000+0 records in\r\n1000+0 records out\r\n10240000 bytes (10 MB) copied, 9.79776 s, 1.0 MB\/s\r\n<\/pre>\n<h4>3.4.5 \u2013device-read-iops<\/h4>\n<p>\u8be5\u63a5\u53e3\u8bbe\u7f6e\u4e86\u8bbe\u5907\u7684IO\u8bfb\u53d6\u901f\u7387\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662f\/sys\/fs\/cgroup\/blkio\/blkio.throttle.read_iops_device\u3002<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-read-iops \/dev\/sda:400 stress bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.throttle.read_iops_device\"\r\n8:0 400\r\n<\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u201d\u2013device-read-iops \/dev\/sda:400\u2033\u6765\u9650\u5b9asda\u7684IO\u8bfb\u53d6\u901f\u7387(400\u6b21\/\u79d2)\uff0clog\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>$ docker run -ti --device \/dev\/sda:\/dev\/sda  --device-read-iops \/dev\/sda:400 stress bash\r\n\r\n[root@7b505be8d935 \/]# dd iflag=direct,nonblock if=\/dev\/sda of=\/dev\/null bs=1k count=1000\r\n1000+0 records in\r\n1000+0 records out\r\n1024000 bytes (1.0 MB) copied, 2.41321 s, 424 kB\/s\r\n<\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684log\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c\u5bb9\u5668\u6bcf\u79d2IO\u7684\u8bfb\u53d6\u6b21\u6570\u4e3a400\uff0c\u5171\u9700\u8981\u8bfb\u53d61000\u6b21\uff08log\u7b2c\u4e8c\u884c\uff1acount=1000\uff09\uff0c\u6d4b\u8bd5\u7ed3\u679c\u663e\u793a\u6267\u884c\u65f6\u95f4\u4e3a2.42874\u79d2\uff0c\u7ea6\u4e3a2.5(1000\/400)\u79d2\uff0c \u4e0e\u9884\u671f\u7ed3\u679c\u76f8\u7b26\u3002<\/p>\n<h4>3.4.6 \u2013device-write-iops<\/h4>\n<p>\u8be5\u63a5\u53e3\u8bbe\u7f6e\u4e86\u8bbe\u5907\u7684IO\u5199\u901f\u7387\uff0c\u5bf9\u5e94\u7684cgroup\u6587\u4ef6\u662fcgroup\/blkio\/blkio.throttle.write_iops_device\u3002<\/p>\n<pre>$ docker run -it --device \/dev\/sda:\/dev\/sda --device-write-iops \/dev\/sda:400 ubuntu:14.04 bash -c \"cat \/sys\/fs\/cgroup\/blkio\/blkio.throttle.write_iops_device\"\r\n8:0 400\r\n<\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7\u201d\u2013device-write-iops \/dev\/sda:400\u2033\u6765\u9650\u5b9asda\u7684IO\u5199\u901f\u7387(400\u6b21\/\u79d2)\uff0clog\u5982\u4e0b\u6240\u793a\u3002<\/p>\n<pre>$ docker run -ti --device \/dev\/sda:\/dev\/sda --device-write-iops \/dev\/sda:400 ubuntu:14.04\r\nroot@ef88a516d6ed:\/# dd oflag=direct,nonblock of=\/dev\/sda if=\/dev\/urandom bs=1K count=1000\r\n1000+0 records in\r\n1000+0 records out\r\n1024000 bytes (1.0 MB) copied, 2.4584 s, 417 kB\/s\r\n<\/pre>\n<p>\u901a\u8fc7\u4e0a\u9762\u7684log\u4fe1\u606f\u53ef\u4ee5\u770b\u51fa\uff0c\u5bb9\u5668\u6bcf\u79d2IO\u7684\u5199\u5165\u6b21\u6570\u4e3a400\uff0c\u5171\u9700\u8981\u51991000\u6b21\uff08log\u7b2c\u4e8c\u884c\uff1acount=1000\uff09\uff0c\u6d4b\u8bd5\u7ed3\u679c\u663e\u793a\u6267\u884c\u65f6\u95f4\u4e3a2.4584\u79d2\uff0c\u7ea6\u4e3a2.5(1000\/400)\u79d2\uff0c \u4e0e\u9884\u671f\u7ed3\u679c\u76f8\u7b26\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740Docker\u6280\u672f\u88ab\u8d8a\u6765\u8d8a\u591a\u7684\u4e2a\u4eba\u3001\u4f01\u4e1a\u6240\u63a5\u53d7\uff0c\u5176\u7528\u9014\u4e5f\u8d8a\u6765\u8d8a\u5e7f\u6cdb\u3002Docker\u8d44\u6e90\u7ba1\u7406\u5305\u542b\u5bf9CPU\u3001\u5185\u5b58\u3001IO\u7b49\u8d44\u6e90\u7684\u9650\u5236\uff0c\u4f46\u5927\u90e8\u5206Docker\u4f7f\u7528\u8005\u5728\u4f7f\u7528\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u65f6\u5f80\u5f80\u53ea\u77e5\u5176\u7136\u800c\u4e0d\u77e5\u5176\u6240\u4ee5\u7136\u3002 \u672c\u6587\u5c06\u4ecb\u7ecdDocker\u8d44\u6e90\u7ba1\u7406\u80cc\u540e\u7684Cgroups\u673a\u5236\uff0c\u5e76\u4e14\u5217\u4e3e\u6bcf\u4e00\u4e2a\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u5bf9\u5e94\u7684Cgroups\u63a5\u53e3\uff0c\u8ba9Docker\u4f7f\u7528\u8005\u5bf9\u8d44\u6e90\u7ba1\u7406\u77e5\u5176\u7136\u5e76\u4e14\u77e5\u5176\u6240\u4ee5\u7136\u3002 &nbsp; \u4e00\u3001Docker\u8d44\u6e90\u7ba1\u7406\u63a5\u53e3\u6982\u89c8 \u683c\u5f0f \u63cf\u8ff0 -m, \u2013memory bytes \u5185\u5b58\u4f7f\u7528\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002\u6700\u5c0f\u53d6\u503c\u662f4M\u3002 -m, \u2013memory=\u201d &lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d \u2013memory-swap bytes \u603b\u5185\u5b58\u4f7f\u7528\u9650\u5236 (\u7269\u7406\u5185\u5b58 + \u4ea4\u6362\u5206\u533a\uff0c\u6570\u5b57\u9700\u8981\u4f7f\u7528\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002 \u2013memory-swap=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d \u2013memory-reservation bytes \u5185\u5b58\u8f6f\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002 \u2013memory-reservation=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d \u2013kernel-memory bytes \u5185\u6838\u5185\u5b58\u9650\u5236\u3002 \u6570\u5b57\u9700\u8981\u4f7f\u7528\u6b63\u6574\u6570\uff0c\u5bf9\u5e94\u7684\u5355\u4f4d\u662fb, k, m, g\u4e2d\u7684\u4e00\u4e2a\u3002\u6700\u5c0f\u53d6\u503c\u662f4M\u3002 \u2013kernel-memory=\u201d&lt;\u6570\u5b57&gt;[&lt;\u5355\u4f4d&gt;]\u201d \u2013oom-kill-disable \u5185\u5b58\u8017\u5c3d\u65f6\u662f\u5426\u6740\u6389\u5bb9\u5668 \u2013oom-kill-disable=false \u2013memory-swappiness int \u8c03\u8282\u5bb9\u5668\u5185\u5b58\u4f7f\u7528\u4ea4\u6362\u5206\u533a\u7684\u9009\u9879\uff0c\u53d6\u503c\u4e3a0\u548c100\u4e4b\u95f4\u7684\u6574\u6570(\u542b0\u548c100)\u3002 \u2013memory-swappiness=\u201d\u201d -c, \u2013cpu-shares int CPU\u4efd\u989d (\u76f8\u5bf9\u6743\u91cd) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15466","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15466"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15466\/revisions"}],"predecessor-version":[{"id":15467,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15466\/revisions\/15467"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}