{"id":4331,"date":"2013-04-28T21:01:12","date_gmt":"2013-04-28T13:01:12","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=4331"},"modified":"2013-04-28T21:01:12","modified_gmt":"2013-04-28T13:01:12","slug":"cfs%e4%b8%ad%e7%9a%84%e8%99%9a%e6%8b%9f%e8%bf%90%e8%a1%8c%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/4331","title":{"rendered":"CFS\u4e2d\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4"},"content":{"rendered":"<p>\u4e00\u76f4\u5bf9CFS\uff08Completely Fair Scheduling\uff0c\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\uff09\u4e2d\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\uff08vruntime\uff09\u4e0d\u592a\u7406\u89e3\uff0c\u6700\u8fd1\u5728\u770bcgroup\u4e2d\u7684cpu\u5b50\u7cfb\u7edf\u7b97\u662f\u641e\u6e05\u695a\u4e86\u5b83\u662f\u600e\u4e48\u56de\u4e8b\u3002<\/p>\n<p><span style=\"font-size: 13px;\">\u5148\u7b80\u5355\u8bf4\u4e00\u4e0bCFS\u8c03\u5ea6\u7b97\u6cd5\u7684\u601d\u60f3\uff1a\u7406\u60f3\u72b6\u6001\u4e0b\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u80fd\u83b7\u5f97\u76f8\u540c\u7684\u65f6\u95f4\u7247\uff0c\u5e76\u4e14\u540c\u65f6\u8fd0\u884c\u5728CPU\u4e0a\uff0c\u4f46\u5b9e\u9645\u4e0a\u4e00\u4e2aCPU\u540c\u4e00\u65f6\u523b\u8fd0\u884c\u7684\u8fdb\u7a0b\u53ea\u80fd\u6709\u4e00\u4e2a\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4e00\u4e2a\u8fdb\u7a0b\u5360\u7528CPU\u65f6\uff0c\u5176\u4ed6\u8fdb\u7a0b\u5c31\u5fc5\u987b\u7b49\u5f85\u3002CFS\u4e3a\u4e86\u5b9e\u73b0\u516c\u5e73\uff0c\u5fc5\u987b\u60e9\u7f5a\u5f53\u524d\u6b63\u5728\u8fd0\u884c\u7684\u8fdb\u7a0b\uff0c\u4ee5\u4f7f\u90a3\u4e9b\u6b63\u5728\u7b49\u5f85\u7684\u8fdb\u7a0b\u4e0b\u6b21\u88ab\u8c03\u5ea6\u3002<\/span><\/p>\n<p><span style=\"font-size: 13px;\">\u5177\u4f53\u5b9e\u73b0\u65f6\uff0cCFS\u901a\u8fc7\u6bcf\u4e2a\u8fdb\u7a0b\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\uff08vruntime\uff09\u6765\u8861\u91cf\u54ea\u4e2a\u8fdb\u7a0b\u6700\u503c\u5f97\u88ab\u8c03\u5ea6\u3002CFS\u4e2d\u7684\u5c31\u7eea\u961f\u5217\u662f\u4e00\u68f5\u4ee5vruntime\u4e3a\u952e\u503c\u7684\u7ea2\u9ed1\u6811\uff0c\u865a\u62df\u65f6\u95f4\u8d8a\u5c0f\u7684\u8fdb\u7a0b\u8d8a\u9760\u8fd1\u6574\u4e2a\u7ea2\u9ed1\u6811\u7684\u6700\u5de6\u7aef\u3002\u56e0\u6b64\uff0c\u8c03\u5ea6\u5668\u6bcf\u6b21\u9009\u62e9\u4f4d\u4e8e\u7ea2\u9ed1\u6811\u6700\u5de6\u7aef\u7684\u90a3\u4e2a\u8fdb\u7a0b\uff0c\u8be5\u8fdb\u7a0b\u7684vruntime\u6700\u5c0f\u3002<\/span><\/p>\n<p>\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u662f\u901a\u8fc7\u8fdb\u7a0b\u7684\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u548c\u8fdb\u7a0b\u7684\u6743\u91cd\uff08weight\uff09\u8ba1\u7b97\u51fa\u6765\u7684\u3002\u5728CFS\u8c03\u5ea6\u5668\u4e2d\uff0c\u5c06\u8fdb\u7a0b\u4f18\u5148\u7ea7\u8fd9\u4e2a\u6982\u5ff5\u5f31\u5316\uff0c\u800c\u662f\u5f3a\u8c03\u8fdb\u7a0b\u7684\u6743\u91cd\u3002\u4e00\u4e2a\u8fdb\u7a0b\u7684\u6743\u91cd\u8d8a\u5927\uff0c\u5219\u8bf4\u660e\u8fd9\u4e2a\u8fdb\u7a0b\u66f4\u9700\u8981\u8fd0\u884c\uff0c\u56e0\u6b64\u5b83\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u5c31\u8d8a\u5c0f\uff0c\u8fd9\u6837\u88ab\u8c03\u5ea6\u7684\u673a\u4f1a\u5c31\u8d8a\u5927\u3002<\/p>\n<p><span style=\"font-size: 13px;\">\u90a3\u4e48\uff0c\u5728\u7528\u6237\u6001\u8fdb\u7a0b\u7684\u4f18\u5148\u7ea7nice\u503c\u4e0eCFS\u8c03\u5ea6\u5668\u4e2d\u7684\u6743\u91cd\u53c8\u6709\u4ec0\u4e48\u5173\u7cfb\uff1f\u5728\u5185\u6838\u4e2d\u901a\u8fc7prio_to_weight\u6570\u7ec4\u8fdb\u884cnice\u503c\u548c\u6743\u91cd\u7684\u8f6c\u6362\u3002<\/span><\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nstatic const int prio_to_weight&#x5B;40] = {\r\n \/* -20 *\/     88761,     71755,     56483,     46273,     36291,\r\n \/* -15 *\/     29154,     23254,     18705,     14949,     11916,\r\n \/* -10 *\/      9548,      7620,      6100,      4904,      3906,\r\n \/*  -5 *\/      3121,      2501,      1991,      1586,      1277,\r\n \/*   0 *\/      1024,       820,       655,       526,       423,\r\n \/*   5 *\/       335,       272,       215,       172,       137,\r\n \/*  10 *\/       110,        87,        70,        56,        45,\r\n \/*  15 *\/        36,        29,        23,        18,        15,\r\n};\r\n<\/pre>\n<p>\u800c\u5728\u5185\u6838\u4e2d\uff0c\u8fdb\u7a0b\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u662f\u81ea\u8fdb\u7a0b\u8bde\u751f\u4ee5\u6765\u8fdb\u884c\u7d2f\u52a0\u7684\uff0c\u6bcf\u4e2a\u65f6\u949f\u5468\u671f\u5185\u4e00\u4e2a\u8fdb\u7a0b\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u662f\u901a\u8fc7\u4e0b\u9762\u7684\u65b9\u6cd5\u8ba1\u7b97\u7684\uff1a<\/p>\n<p><strong><span style=\"font-size: 13px;\">\u4e00\u6b21\u8c03\u5ea6\u95f4\u9694\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4=\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4*\uff08NICE_0_LOAD\/\u6743\u91cd\uff09<\/span><\/strong><\/p>\n<p>\u5176\u4e2d\uff0cNICE_0_LOAD\u662fnice\u4e3a0\u65f6\u7684\u6743\u91cd\u3002\u4e5f\u5c31\u662f\u8bf4\uff0cnice\u503c\u4e3a0\u7684\u8fdb\u7a0b\u5b9e\u9645\u8fd0\u884c\u65f6\u95f4\u548c\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u76f8\u540c\u3002\u901a\u8fc7\u8fd9\u4e2a\u516c\u5f0f\u53ef\u4ee5\u770b\u5230\uff0c\u6743\u91cd\u8d8a\u5927\u7684\u8fdb\u7a0b\u83b7\u5f97\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\u8d8a\u5c0f\uff0c\u90a3\u4e48\u5b83\u5c06\u88ab\u8c03\u5ea6\u5668\u6240\u8c03\u5ea6\u7684\u673a\u4f1a\u5c31\u8d8a\u5927\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u76f4\u5bf9CFS\uff08Completely Fair Scheduling\uff0c\u5b8c\u5168\u516c\u5e73\u8c03\u5ea6\uff09\u4e2d\u7684\u865a\u62df\u8fd0\u884c\u65f6\u95f4\uff08vrunt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[110],"tags":[327,379,326],"class_list":["post-4331","post","type-post","status-publish","format-standard","hentry","category-linux","tag-cfs","tag-379","tag-326"],"views":17960,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=4331"}],"version-history":[{"count":2,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4331\/revisions"}],"predecessor-version":[{"id":4346,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/4331\/revisions\/4346"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=4331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=4331"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=4331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}