\u547d\u4ee4<\/a>\u8f93\u51fa\u7684D\u72b6\u6001\u8fdb\u7a0b\u3002ps\u7684man\u6307\u5357\u79f0\u5176\u4e3a\u201c\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff08\u901a\u5e38\u662f\u7531\u4e8eI\/O\uff09\u201d\u3002<\/p>\n<\/p>\n
\u5e73\u5747\u8d1f\u8f7d\u5305\u542b\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7684\u8fdb\u7a0b\uff0c\u610f\u5473\u7740linux\u7684loadavg\u53ef\u80fd\u7531\u4e8ec\u76d8\uff08\u6216NFS\u6587\u4ef6\u7cfb\u7edf\uff09I\/O\u8d1f\u8f7d\u800c\u964d\u4f4e\u3002\u8bfb\u8005\u5047\u5982\u719f\u6089\u5176\u4ed6\u7cfb\u7edf\u7684cpuloadavg\u7edf\u8ba1\u65b9\u6cd5\uff0c\u518d\u4e0elinux\u6765\u5bf9\u6bd4\uff0c\u53ef\u80fd\u4f1a\u500d\u611f\u8be7\u5f02\uff1a\u4e3a\u4ec0\u4e48\u5305\u542b\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff1f\u76ee\u524d\u5df2\u6709\u7279\u522b\u591a\u7684\u6587\u7ae0\u6765\u89e3\u91caloadavg\uff0c\u5176\u4e2d\u5927\u90e8\u4efd\u4e5f\u80fd\u5f3a\u8c03Linux\u5305\u542b\u4e86\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff0c\u5e76\u4e14\u65e0\u4eba\u7ed9\u51fa\u89e3\u91ca\u751a\u81f3\u63a8\u6d4b\uff1a\u4e3a\u4f55\u4f1a\u5305\u542b\u5b83\u5462\uff1fbrendangregg\u89c9\u5f97\uff0clinux\u7684\u7edf\u8ba1\u4e0d\u4ec5\u4ec5\u662fcpu\u7ef4\u5ea6\u7684\u6d4b\u5ea6\uff0c\u800c\u662f\u591a\u7ef4\u5ea6\u7684\u7edf\u8ba1\uff0c\u4e0b\u8fb9\u6765\u8be6\u5c3d\u5256\u6790\u3002<\/p>\n
Patch\u6eaf\u6e90<\/p>\n
\u3010\u8bd1\u8005\u6ce8\uff1a\u672c\u6bb5\u6587\u5b57\u4e3b\u8981\u8bb0\u5f55\u4e86brendangregg\u7684\u63a2\u6c42\u5386\u7a0b\uff0c\u5047\u5982\u6709\u4e86\u89e3linux\u4ee3\u7801\u5386\u53f2\u8bb0\u5f55\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u53c2\u8003\u8be5\u6280\u5de7\uff0c\u5047\u5982\u53ea\u5bf9\u7ed3\u679c\u611f\u5174\u8da3\uff0c\u8bf7\u76f4\u63a5\u8df3\u81f3\u4e0b\u4e00\u6bb5\u6587\u5b57\u3002\u3011brendangregg\u670b\u53cb\u5f00\u59cb\u5228\u6839\u7a76\u5e95\uff0c\u4e00\u5f00\u59cb\u671f\u671b\u901a\u8fc7linux\u7684gitcommit\u5386\u53f2\uff0c\u770b\u80fd\u591f\u53d1\u89c9\u54ea\u4e9b\u86db\u4e1d\u9a6c\u8ff9\u3002\u9996\u5148\u68c0\u6d4bkernel\/sched\/loadavg.c\u7684\u9012\u4ea4\u5386\u53f2\uff0c\u53d1\u89c9uninterruptiblestate\u6bd4loadavg.c\u6587\u4ef6\u8fd8\u8981\u65e9\u51fa\u73b0\uff0c\u6240\u4ee5\u80af\u5b9a\u662f\u5148\u5728\u5176\u4ed6\u6587\u4ef6\u4e2d\u51fa\u73b0\u3002\u63a5\u7740\u4ed6\u53c8\u68c0\u6d4b\u4e86\u53e6\u5916\u4e00\u4e2a\u6587\u4ef6\uff0c\u4e00\u65e0\u6240\u83b7\uff0c\u7ebf\u7d22\u53c8\u6307\u5411\u4e86\u66f4\u8001\u7684\u6587\u4ef6\u3002brendangregg\u4e0d\u5f97\u5df2\u91c7\u53d6\u4e86\u66b4\u529b\u7834\u89e3\u6cd5\uff0c\u901a\u8fc7\u5bf9linux\u6574\u4e2arepo\u4f7f\u7528gitlog-p\u547d\u4ee4\uff0c\u8f93\u51fa\u4e864G\u5b57\u8282\u7684\u6587\u672c\u6587\u4ef6\uff0c\u4e4b\u540e\u5f00\u59cb\u6e10\u6e10\u56de\u6eaf\u2026\u4f46\u662f\u5f88\u4e0d\u5e78\uff0c\u8fd9\u8fd8\u662f\u8fc8\u5411\u4e86\u6b7b\u5357\u8857\u3002linuxrepo\u6700\u65e9\u7684\u8bb0\u5f55\u662f2005\u5e74\uff0c\u7248\u672c\u662f2.6.12-rc2\uff0c\u800c\u8be5\u7248\u672c\u5df2\u5305\u542b\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7684\u7edf\u8ba1\u3002brendangregg\u6ca1\u6709\u820d\u5f03\uff0c\u8f6c\u800c\u4f7f\u7528\u66f4\u8001repo\u8bb0\u5f55\uff0c\u4f46\u4f9d\u7136\u6ca1\u6709\u5f97\u5230\u7b54\u6848\u3002brendangregg\u53c8\u5bc4\u5e0c\u671b\u4e8e\u627e\u5230\u4f55\u65f6\u5f15\u5165\u4e86\u8be5\u66f4\u6539\uff0c\u901a\u8fc7\u76f4\u63a5\u5bf9\u6bd4LINUXv0.99\u4e0a\u7684tar\u5305\uff0c\u53d1\u89c9\u5728\u57280.99.15\u4e2d\u5df2\u6709\u8be5\u9879\u66f4\u6539\u7ea2\u65d7 linux\uff0c\u800c\u57280.99.13\u4e2d\u8fd8\u672a\u51fa\u73b0\uff0c\u5e76\u4e14\u20260.99.14\u7684tar\u5305\u6ca1\u80fd\u5728\u6ca1\u80fd\u627e\u5230\u3002<\/p>\n
\u5e86\u5e78\uff0c\u4ed6\u5728\u5176\u4ed6\u5730\u65b9\u627e\u5230\u4e86\u8fd9\u4e2atar\u5305\uff0c\u53ef\u4ee5\u786e\u8ba4\u7684\u662f\u8be5\u9879\u66f4\u6539\u4e8e1993\u5e7411\u6708\uff0c\u57280.99\u7684patchlevel14\u4e2d\u5f15\u5165\u3002\u9057\u61be\u7684\u662f\uff0c0.99.14\u7684\u53d1\u5e03\u63cf\u8ff0\u91cc\uff0c\u6ca1\u6709\u4efb\u4f55\u4e0e\u6b64\u9879\u66f4\u6539\u76f8\u5173\u7684\u89e3\u91ca\uff0c\u53c8\u4e00\u4e2a\u6b7b\u897f\u8857\uff1a\u201cChangestothelastofficialrelease(p13)aretoonumeroustomention(oreventoremember)\u2026\u201d\u2013Linus\u3002Linus\u5728\u53d1\u5e03\u63cf\u8ff0\u91cc\u53ea\u63d0\u53ca\u4e86\u4e3b\u8981\u66f4\u6539\uff0c\u5bf9loadavg\u8fd9\u7c7b\u5c0f\u66f4\u6539\u4e00\u6982\u800c\u8fc7\u3002\u901a\u8fc7\u7248\u672c\u7684\u53d1\u5e03\u65e5\u671f\uff0cbrendangregg\u5728\u5185\u6838\u7535\u90ae\u5217\u8868\u6863\u6848\u91cc\u627e\u5230\u4e86\u90a3\u79cdpatch\uff0c\u7136\u800c\u8fd9\u513f\u6700\u8001\u7684\u77ed\u4fe1\u662f1995\u5e746\u6708\u4efd\u5f00\u59cb\uff0c\u7cfb\u7edf\u7ba1\u7406\u5458\u5728\u4e0a\u9762\u5199\u4e86\u4e00\u53e5\u8bdd:\u201d\u4e3a\u4e86\u4f7f\u8fd9\u79cd\u7535\u90ae\u6863\u6848\u6108\u53d1\u9ad8\u6548\u5730\u5de5\u4f5c\uff0c\u6211\u4e0d\u7559\u795e\u6363\u6bc1\u4e86\u73b0\u6709\u7684\u6863\u6848\uff08\u54ce\u5440\uff09\u201d\u3002brendangregg\u500d\u611f\u4e86\u8fd9\u4e2a\u4e16\u754c\u6df1\u6df1\u7684\u6076\u610f\uff0c\u4f46\u662f\u4ed6\u8fd8\u662f\u6ca1\u6709\u820d\u5f03\u3002\u4ed6\u5728\u4e00\u4e9b\u5907\u4efd\u670d\u52a1\u5668\u4e2d\u53d1\u89c9\u4e86\u4e00\u90e8\u4efd\u66f4\u8001\u7684\u5185\u6838\u7535\u90ae\u5217\u8868tar\u5305\u3002\u4ed6\u641c\u67e5\u4e86\u516d\u5343\u591a\u4efd\u6458\u8981\uff0c\u5171\u5305\u542b\u4e5d\u4e07\u516b\u5343\u591a\u5c01\u7535\u5b50\u7535\u90ae\uff0c\u5176\u4e2d\u4e09\u4e07\u4efd\u662f\u4ece\u4e00\u4e5d\u4e5d\u4e03\u5e74\u8d77\u7684\u3002\u867d\u7136\uff0clinuxloadavg\u4e3a\u4ec0\u4e48\u5305\u542b\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff0c\u5c06\u6210\u4e3a\u6c38\u8fdc\u7684\u8c1c\u2026<\/p>\n
\u539f\u59cbPatch<\/p>\n
\u7687\u5929\u4e0d\u8d1f\u6709\u5fc3\u4eba\uff0cbrendangregg\u5728\u4e0a\u627e\u5230\u539f\u59cbpatch\uff0c\u5982\u4e0b\uff1a<\/p>\n
\n
From: Matthias Urlichs Subject: Load average broken ?Date: Fri, 29 Oct 1993 11:37:23 +0200The kernel only counts \"runnable\" processes when computing the load average.I don't like that; the problem is that processes which are swapping orwaiting on \"fast\", i.e. noninterruptible, I\/O, also consume resources.It seems somewhat nonintuitive that the load average goes down when youreplace your fast swap disk with a slow swap disk...Anyway, the following patch seems to make the load average much moreconsistent WRT the subjective speed of the system. And, most important, theload is still zero when nobody is doing anything. ;-)--- kernel\/sched.c.orig Fri Oct 29 10:31:11 1993+++ kernel\/sched.c Fri Oct 29 10:32:51 1993@@ -414,7 +414,9 @@unsigned long nr = 0;for(p = &LAST_TASK; p > &FIRST_TASK; --p)- if (*p && (*p)->state == TASK_RUNNING)+ if (*p && ((*p)->state == TASK_RUNNING) ||+ (*p)->state == TASK_UNINTERRUPTIBLE) ||+ (*p)->state == TASK_SWAPPING))nr += FIXED_1;return nr;}--Matthias Urlichs XLink-POP N|rnberg | EMail: urlichs@smurf.sub.orgSchleiermacherstra_e 12 Unix+Linux+Mac | Phone: ...please use email.90491 N|rnberg (Germany) Consulting+Networking+Programming+etc'ing 42<\/pre>\n<\/p>\n\u7531\u6b64\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u8ba4linuxloadavg\u7684\u66f4\u6539\u662f\u4e3a\u4e86\u53cd\u6620\u7cfb\u7edf\u8d44\u6e90\u7684\u9700\u6c42\u91cf\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662fCPU\u8d44\u6e90\u3002\u6253\u4e0a\u8fd9\u4e2apatch\u540e\uff0clinux\u4ece\u201ccpuloadavg\u201d\u7edf\u8ba1\u53d8\u4e3a\u201csystemloadavg\u201d\u7edf\u8ba1\u3002\u9012\u4ea4\u8bb0\u5f55\u4e2d\u63d0\u53ca\u4e86\u4e00\u4e2a\u4f4e\u6027\u80fd\u7684swapc\u76d8\u6848\u4f8b\uff1a\u56e0\u4e3a\u6027\u80fd\u589e\u957f\uff0c\u9020\u6210\u5bf9\u7cfb\u7edf\u8d44\u6e90\u7684\u9700\u6c42\u964d\u4f4e\uff08\u8fd0\u884c+\u6392\u961f\u7b49\u5f85\u7684\u8fdb\u7a0b\uff09\uff0c\u6ca1\u6709\u6253\u4e0a\u8fd9\u4e2apatch\u65f6\uff0c\u7cfb\u7edf\u7684\u5e73\u5747\u8d1f\u8f7d\u7edf\u8ba1\u5c06\u4f1a\u53d8\u4f4e\uff0cMatthias\u89c9\u5f97\u8fd9\u6837\u4e0d\u7b26\u5408\u76f4\u89c2\u5224\u5b9a\uff0c\u6240\u4ee5\u4fee\u6b63\u4e86\u7edf\u8ba1\u3002<\/p>\n
\u73b0\u5728\u7684Uninterruptible<\/p>\n
Linux\u7684\u5e73\u5747\u8d1f\u8f7d\u6709\u65f6\u663e\u5f97\u5341\u5206\u9ad8\uff0c\u5e76\u975e\u5b8c\u5168\u4e0ec\u76d8I\/O\u538b\u529b\u6b63\u76f8\u5173\uff0c\u867d\u7136\u8fd8\u6709\u672a\u77e5\u8bf1\u56e0\u3002brendangregg\u731c\u60f3\u8fd9\u662f\u7531\u4e8e\u57281993\u5e74\u6539\u52a8\u540e\uff0c\u65b0\u589e\u4e86\u8bb8\u591a\u53ef\u6b65\u5165\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7684\u4ee3\u7801\u8def\u5f84\u3002\u5728linux0.99.14\u4e2d\uff0c\u4ec5\u5b58\u572813\u6761\u4ee3\u7801\u8def\u5f84\u4f1a\u76f4\u63a5\u6b65\u5165TASK_UNINTERRUPTIBLE\u6216TASK_SWAPPING(\u8be5\u72b6\u6001\u540e\u6765\u88ab\u5220\u6389)\u72b6\u6001\u3002\u73b0\u5728\u7684Linux4.12\u7248\u672c\uff0c\u65e9\u5df2\u6709\u8d85\u8fc7400\u6761\u4ee3\u7801\u8def\u5f84\u4f1a\u6b65\u5165TASK_UNINTERRUPTIBLE\uff0c\u8fd9\u5176\u4e2d\u5305\u542b\u4e00\u4e9b\u9501\u5b50\u53e5\u3002\u5176\u5b9e\uff0c\u8fd9\u513f\u9762\u7684\u4e2a\u522b\u4ee3\u7801\u8def\u5f84\u4e0d\u5e94\u5f53\u88ab\u7edf\u8ba1\u5165\u8d1f\u8f7d\u3002brendangregg\u7ed9Matthias\u53d1\u77ed\u4fe1\u54a8\u8be2\u5176\u5bf9loadavg\u542b\u610f\u53d8\u5316\u7684\u60f3\u6cd5\uff0c\u56de\u590d\u5982\u4e0b\uff1a\u201c\u5e73\u5747\u8d1f\u8f7d\u662f\u4ece\u4eba\u7684\u89c6\u89d2\u6765\u8bc4\u5224\u91cf\u7cfb\u7edf\u5fd9\u788c\u7a0b\u5ea6\u7684\u6570\u503c\u3002TASK_UNINTERRUPTIBLE\u610f\u5473\u7740\uff08\u6216\u4ee5\u524d\u610f\u5473\u7740\uff09\u88ab\u963b\u585e\uff08\u4f8b\u5982\u8bfbc\u76d8\uff09\u7684\u8fdb\u7a0b\u5bf9\u7cfb\u7edf\u8d1f\u8f7d\u7684\u8d21\u732e\u3002\u4f8b\u5982\u4e00\u4e2adisk-bound\u578b\u7684\u7cfb\u7edf\uff0c\u5176TASK_RUNNING\u7684\u5e73\u5747\u503c\u663e\u7136\u662f0.1\uff0c\u8be5\u503c\u6beb\u65e0\u5b9e\u9645\u610f\u4e49\u3002\u201d\u6240\u4ee5\uff0cMatthias\u89c9\u5f97linux\u4e0a\u7684\u4fee\u6b63\u662f\u6709\u9053\u7406\u7684\uff0c\u4ece\u7535\u90ae\u56de\u590d\u4e2d\u4e5f\u53ef\u4ee5\u770b\u51faTASK_UNINTERRUPTIBLE\u4ee5\u524d\u662f\u6307\u8fdb\u7a0b\u88abc\u76d8I\/O\u963b\u585e\u3002\u4f46\u73b0\u5728TASK_UNITERRUPTIBLE\u7684\u542b\u610f\u4e30\u5bcc\u4e86\u8bb8\u591a\u3002\u5e73\u5747\u8d1f\u8f7d\u662f\u5426\u5e94\u53ea\u8003\u8651CPU\u6216\u5219c\u76d8\u8d44\u6e90\u7684\u9700\u6c42\uff1f\u8c03\u5ea6\u5668\u7684maintainerPeterZijstra\u63d0\u53ca\u4e86\u4e00\u4e2a\u770b\u6cd5\uff1a\u7cfb\u7edf\u8d1f\u8f7d\u4e0d\u7edf\u8ba1TASK_UNINTERRUPTIBLE\uff0c\u800c\u662f\u7edf\u8ba1task_struct->in_iowait\u3002\u4f46\u8fd9\u662f\u6211\u4eec\u771f\u6b63\u60f3\u8981\u7684\u4e48\uff1f\u5176\u5b9e\u6211\u4eec\u4f1a\u60f3\u7edf\u8ba1\u7ebf\u7a0b\u5bf9\u7cfb\u7edf\u8d44\u6e90\u7684\u9700\u6c42\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f\u5316\u5b66\u8d44\u6e90\uff1f\u5047\u5982\u662f\u57fa\u4e8e\u7ebf\u7a0b\u7edf\u8ba1\uff0c\u8fd9\u4e48\u8fd9\u4e9b\u6b65\u5165\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7684\u7ebf\u7a0b\u4e5f\u6d88\u8017\u4e86\u7cfb\u7edf\u8d44\u6e90\uff0c\u7531\u4e8e\u5979\u4eec\u5e76\u975eidle\u3002\u6240\u4ee5\uff0c\u5176\u5b9e\u76ee\u524d\u7684linuxloadavg\u7edf\u8ba1\u5176\u5b9e\u624d\u662f\u6211\u4eec\u771f\u6b63\u60f3\u8981\u7684\u3002\u63a5\u51fa\u6765brendangregg\u7ed9\u51fa\u4e86\u51e0\u4e2a\u53cd\u4f8b\u3002<\/p>\n
\u4e0d\u53ef\u4e2d\u65ad\u4efb\u52a1\u7684\u68c0\u6d4b\u5256\u6790<\/p>\n
\u53f3\u56fe\u662f\u4e00\u53f0\u751f\u4ea7\u73af\u5883\u670d\u52a1\u5668\u7684Off-Cpu\u706b\u7130\u56fe\uff0c\u7edf\u8ba1\u6301\u7eed60\u79d2\uff0c\u4ec5\u663e\u793aTASK_UNINTERRUPTIBLE\u72b6\u6001\u7684\u5185\u6838\u6808\u3002\u901a\u8fc7\u7edf\u8ba1\u56fe\u53ef\u4ee5\u5f97\u5230\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u7684\u4ee3\u7801\u8def\u5f84:<\/p>\n
<\/p>\n
x\u8f74\u4ee3\u8868off-CPU\u7684\u65f6\u95f4\u957f\u77ed\uff0c\u4ece\u5de6\u81f3\u53f3\u6ca1\u6709\u4efb\u4f55\u6392\u5e8f\uff0c\u8272\u8c03\u9971\u548c\u5ea6\u968f\u673a\u6ca1\u6709\u4efb\u4f55\u542b\u610f\u3002\u56fe\u662f\u901a\u8fc7bcc\u5de5\u5177(\u4f9d\u8d56\u4e8ekernel4.8+\u4e0a\u7684eBPF\u7279\u70b9)\u4ee5\u53ca\u706b\u7130\u56fe\u811a\u672c\uff1a<\/p>\n
\n
# .\/bcc\/tools\/offcputime.py -K --state 2 -f 60 > out.stacks# awk '{ print $1, $2 \/ 1000 }' out.stacks | .\/FlameGraph\/flamegraph.pl --color=io --countname=ms > out.offcpu.svgb><\/pre>\n<\/p>\nbrendangregg\u4f7f\u7528awk\u5c06\u65f6\u95f4\u7cbe\u5ea6\u4eceus\u8c03\u6574\u4e3ams\uff0c\u2019\u2013state2\u2019\u8868\u793aTASK_UNINTERRUPTIBLE(\u53c2\u8003sched.h)\u3002offcputime.py\u652f\u6301\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u6808\uff0c\u8fd9\u513f\u4e3a\u4e86\u8bf4\u660e\u4ec5\u663e\u793a\u7528\u6237\u6001\u6808\u3002\u4e0a\u56fe60\u79d2\u5185\u6709926ms\u6b65\u5165\u4e86\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\uff0c\u6240\u4ee5\u4ec5\u5f71\u54cd\u5e73\u5747\u8d1f\u8f7d0.015\uff08926ms\/60s\uff09\u3002\u8be5\u670d\u52a1\u7a0b\u5e8f\u5e76\u6ca1\u6709\u592a\u591a\u7684c\u76d8I\/O\uff0c\u4e3b\u8981\u662fcgroup\u8def\u5f84\u76f8\u5173\u3002<\/p>\n
\u53f3\u56fe\u662f\u53e6\u4e00\u6848\u4f8b\uff0c\u4ec5\u7edf\u8ba1\u4e8610\u79d2<\/p>\n
<\/p>\n
\u56fe\u7247\u5de6\u8fb9\u8038\u7acb\u7684\u5e73\u5766\u533a\u57df\u662fsystemd-journal\u8c03\u7528\u51fd\u6570proc_pid_cmdline_read()\uff08\u8bfb\u53d6\/proc\/PID\/cmdline\uff09\uff0c\u5bf9\u5e73\u5747\u8d1f\u8f7d\u8d21\u732e\u4e860.07\u3002\u5728\u53f3\u8fb9\u7684\u66f4\u4e3a\u5bbd\u655e\u7684\u5e73\u5766\u533a\u57df\u662f\u963b\u585e\u5728rwsem_down_read_failed()\u51fd\u6570\uff08\u5bf9\u5e73\u5747\u8d1f\u8f7d\u8d21\u732e\u4e860.23\uff09\u3002\u4e0b\u8fb9\u7684\u4e00\u6bb5\u4ee3\u7801\u6458\u81earwsem_down_read_failed()\u51fd\u6570\uff1a<\/p>\n
<\/p>\n
\n
\/* wait to be given the lock *\/while (true) {set_task_state(tsk, TASK_UNINTERRUPTIBLE);if (!waiter.task)break;schedule();}<\/pre>\n<\/p>\n\u53ef\u4ee5\u770b\u89c1\uff0clock\u8def\u5f84\u4f7f\u7528\u4e86TASK_UNINTERRUPTIBLE\u3002linux\u7684\u9501\u5b50\u53e5\u901a\u5e38\u652f\u6301\u53ef\u4e2d\u65ad\u4e0e\u4e0d\u53ef\u4e2d\u65ad\u4e24\u7c7bAPI\uff08\u5982\u4e92\u65a5\u9501mutex_lock()vsmutex_lock_interruptible(),\u8baf\u53f7\u91cfdown()vsdown_interruptible()\uff09\u3002\u53ef\u4e2d\u65ad\u7248\u672c\u53ef\u88absignal\u6253\u65ad\u5e76\u88ab\u5524\u8d77\u6267\u884c\u3002\u901a\u5e38\u800c\u8a00\uff0c\u7531\u4e8elock\u5931\u8d25\u800c\u6b65\u5165\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u4e0d\u4f1a\u5bf9\u5e73\u5747\u8d1f\u8f7d\u5bfc\u81f4\u5f88\u5927\u7684\u5f71\u54cd\uff0c\u4f46\u672c\u6848\u4f8b\u5219\u5f71\u54cd\u4e860.30\u3002\u5047\u5982\u8be5\u503c\u66f4\u9ad8\uff0c\u5219\u987b\u8981\u5256\u6790\u9501\u7ade\u4e89\u662f\u5426\u5408\u7406\u4ee5\u53ca\u80fd\u591f\u4f18\u5316\u3002<\/p>\n
\u91cc\u9762\u4fe9\u6848\u4f8b\u4e2d\u7684\u4e0d\u53ef\u4e2d\u65ad\u7761\u7720\u8def\u5f84\u662f\u5426\u5e94\u5f53\u88ab\u7edf\u8ba1\u5165\u5e73\u5747\u8d1f\u8f7d\u5462\uff1fbrendangregg\u89c9\u5f97\u5e94\u5f53\u88ab\u7edf\u8ba1\uff0c\u7406\u7531\u5982\u4e0b\uff1a\u7ebf\u7a0b\u5728\u5904\u7406\u4efb\u52a1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u83b7\u53d6\u9501\u5931\u8d25\u88ab\u963b\u585e\uff0c\u5e76\u975e\u6b65\u5165idle\uff0c\u8fd9\u4e00\u76f4\u4f1a\u6d88\u8017\u7cfb\u7edf\u8d44\u6e90\uff08\u4e3b\u8981\u6307\u8f6f\u4ef6\u8d44\u6e90linux\u5185\u6838\u4fe1\u53f7\u91cf<\/strong>\uff0c\u800c\u4e0d\u662f\u786c\u4ef6\u8d44\u6e90\uff09\u3002<\/p>\nlinux\u5e73\u5747\u8d1f\u8f7d\u5206\u6790<\/p>\n
brendangregg\u5c1d\u8bd5\u5bf9linux\u5e73\u5747\u8d1f\u8f7d\u6309\u7c7b\u578b\u8fdb\u884c\u7ec6\u5206\u7edf\u8ba1\u3002\u4ed6\u5728\u4e00\u4e2a8\u6838\u7a7a\u95f2CPU\u7684\u7cfb\u7edf\u4e0a\u4f7f\u7528tar\u6253\u5305\u672a\u88abpagecache\u7f13\u5b58\u7684\u6587\u4ef6\uff0c\u88abc\u76d8\u8bfb\u963b\u585e\u4e86\u51e0\u5206\u949f\u3002\u4e0b\u8fb9\u662f\u4e00\u4e9b\u7edf\u8ba1\u8f93\u51fa\uff1a<\/p>\n
\n
terma$ pidstat -p `pgrep -x tar` 60Linux 4.9.0-rc5-virtual (bgregg-xenial-bpf-i-0b7296777a2585be1) 08\/01\/2017 _x86_64_ (8 CPU)10:15:51 PM UID PID %usr %system %guest %CPU CPU Command10:16:51 PM 0 18468 2.85 29.77 0.00 32.62 3 tartermb$ iostat -x 60[...]avg-cpu: %user %nice %system %iowait %steal %idle0.54 0.00 4.03 8.24 0.09 87.10Device: rrqm\/s wrqm\/s r\/s w\/s rkB\/s wkB\/s avgrq-sz avgqu-sz await r_await w_await svctm %utilxvdap1 0.00 0.05 30.83 0.18 638.33 0.93 41.22 0.06 1.84 1.83 3.64 0.39 1.21xvdb 958.18 1333.83 2045.30 499.38 60965.27 63721.67 98.00 3.97 1.56 0.31 6.67 0.24 60.47xvdc 957.63 1333.78 2054.55 499.38 61018.87 63722.13 97.69 4.21 1.65 0.33 7.08 0.24 61.65md0 0.00 0.00 4383.73 1991.63 121984.13 127443.80 78.25 0.00 0.00 0.00 0.00 0.00 0.00termc$ uptime22:15:50 up 154 days, 23:20, 5 users, load average: 1.25, 1.19, 1.05[...]termc$ uptime22:17:14 up 154 days, 23:21, 5 users, load average: 1.19, 1.17, 1.06<\/pre>\n<\/p>\nOff-CPU\u706b\u7130\u56fe<\/p>\n
<\/p>\n
\u4e00\u5206\u949floadavg=1.19\uff0c\u5206\u62c6\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u4e0a\u8ff0\u4e4b\u548c\u7b49\u4e8e1.15\uff0c\u8ddd\u5b9e\u9645\u7edf\u8ba1\u503c1.19\u76f8\u5dee0.04\u3002\u76f8\u5dee\u53ef\u80fd\u662f\u7edf\u8ba1\u504f\u5dee\u5f15\u5165\uff0c\u4f46\u66f4\u53ef\u80fd\u662f\u7531\u4e8eloadavg\u662f\u6307\u6570\u8870\u51cf\u6ed1\u52a8\u5e73\u5747\uff0c\u800c\u524d\u9762\u4f30\u7b97\u7528\u5230\u7684\u7edf\u8ba1\u90fd\u662f\u5e38\u89c4\u7684\u7b97\u672f\u5e73\u5747\u30021.19\u7684\u524d\u4e00\u5206\u949f\u7edf\u8ba1\u503c\u4e3a1.25linux\u64cd\u4f5c\u7cfb\u7edf\u754c\u9762\uff0c\u7ed3\u5408\u524d\u6587\u63d0\u53ca\u76841\u5206\u949f\u6307\u6570\u8870\u51cf\u7edf\u8ba1\uff0c\u53ef\u8fd9\u4e48\u4f30\u7b97\uff1a0.62x1.15+0.38x1.25=1.18\uff0c\u4e0e\u5b9e\u9645\u7edf\u8ba1\u503c1.19\u7279\u522b\u63a5\u8fd1\u3002\u5047\u5982\u4ec5\u8003\u8651cpuloadavg\uff0c\u7ed3\u5408mpstat\u7684\u8f93\u51fa\u53ef\u63a8\u6d4b\u51fa0.37\u3002<\/p>\n
\u91cd\u65b0\u89e3\u91calinuxloadavg<\/p>\n
brendangregg\u89c9\u5f97\u5e73\u5747\u8d1f\u8f7d\u5e94\u505a\u5982\u4e0b\u89e3\u91ca\uff1a<\/p>\n
\u5176\u5b9e\u4e4b\u540e\u5c31\u4f1a\u6709\u201c\u7269\u7406\u8d44\u6e90\u5e73\u5747\u8d1f\u8f7d\u201d\uff0c\u5305\u542bCPU\u4ee5\u53cac\u76d8\u8d44\u6e90\uff0c\u751a\u81f3\u201cCPU\u5e73\u5747\u8d1f\u8f7d\u201d,\u201c\u78c1\u76d8\u5e73\u5747\u8d1f\u8f7d\u201d,\u201c\u7f51\u7edc\u5e73\u5747\u8d1f\u8f7d\u201d\u7b49\u7b49\u3002<\/p>\n
\u600e\u6837\u8bc4\u4f30\u8d1f\u8f7d\u662f\u5426\u5408\u7406<\/p>\n
\u901a\u5e38\u7684\u7ecf\u9a8c\u662f\u5f53\u7cfb\u7edf\u8d1f\u8f7d\u8d85\u8fc7\u4e00\u4e2a\u7279\u5b9a\u503cX\uff0c\u5219\u89c9\u5f97\u5c06\u5f71\u54cd\u4e1a\u52a1\u5ef6\u540e\uff0c\u4f46\u4e8b\u5b9e\u4e0a\u5e76\u975e\u8fd9\u4e48\u3002\u4ec5\u8003\u8651CPU\u8d1f\u8f7d\uff0cload\/CPU\u6570\u76ee\u5047\u5982\u5c0f\u4e8e1.0\u5219\u53ef\u80fd\u5b58\u5728\u6027\u80fd\u95ee\u9898\u3002\u5b9e\u9645\u4e0a\u8fd9\u4e9b\u5224\u5b9a\u65b9\u5f0f\u5b58\u5728\u7f3a\u9677linux\u5185\u6838\u4fe1\u53f7\u91cf<\/strong>\uff0c\u7531\u4e8e\u8d1f\u8f7d\u662f\u4e00\u4e2a\u5e73\u5747\u503c\uff0c\u5e76\u4e0d\u80fd\u53cd\u6620\u77ac\u65f6\u72b6\u6001\u3002\u4f8b\u5982load\/CPU\u7b49\u4e8e1.5\u65f6\uff0c\u6709\u4e9b\u7cfb\u7edf\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u800c\u6709\u4e9b\u5219\u5b58\u5728\u6027\u80fd\u95ee\u9898\u3002brendangregg\u4e3e\u4e86\u4e2a\u53cd\u4f8b\uff0c\u4e24\u53f0\u7535\u90ae\u670d\u52a1\u5668\u7684CPU\u5e73\u5747\u8d1f\u8f7d\u4e3a11-16\uff08load\/CPU\u6bd4\u503c\u4e3a5.5-8\uff09\uff0c\u8d1f\u8f7d\u8f83\u9ad8\uff0c\u4f46\u7528\u6237\u5b8c\u5168\u80fd\u63a5\u53d7\u3002\u6240\u4ee5\u4ed6\u7ed9\u51fa\u4e86\u4e00\u4e2a\u63a8\u8bba\uff1a\u5927\u90e8\u4efd\u7cfb\u7edf\u5728load\/CPU\u5927\u4e8e2\u65f6\uff0c\u90fd\u8fd8\u80fd\u6b63\u5e38\u8fd0\u884c\u3002Linux\u7684systemloadavg\u66f4\u590d\u6742\uff0c\u7531\u4e8e\u5b83\u4e0d\u4ec5\u4ec5\u5305\u542bCPU\u8d44\u6e90\uff0c\u6240\u4ee5\u4e0d\u80fd\u76f4\u63a5\u4e58\u4ee5CPU\u6570\u76ee\u3002\u4f46\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u6765\u505a\u6a2a\u5411\u5bf9\u6bd4\uff1a\u4f8b\u5982\u7cfb\u7edf\u5728\u8d1f\u8f7d\u4e3a20\u65f6\u80fd\u6b63\u5e38\u5de5\u4f5c\uff0c\u5ffd\u7136\u5f04\u6210\u4e8640\uff0c\u8fd9\u65f6\u53ef\u7ed3\u5408\u5176\u4ed6\u624b\u6bb5\u6765\u5256\u6790\u5177\u4f53\u7f18\u7531\u3002<\/p>\n\u5176\u4ed6\u91cf\u5316\u624b\u6bb5<\/p>\n
\u5f53linux\u7cfb\u7edf\u8d1f\u8f7d\u964d\u4f4e\uff0c\u610f\u5473\u7740\u5bf9\u7cfb\u7edf\u7684\u8d44\u6e90\u6d88\u8017\u964d\u4f4e\uff0c\u4f46\u5e76\u6ca1\u6709\u5f3a\u8c03\u662f\u54ea\u4e00\u79cd\u5177\u4f53\u7684\u8d44\u6e90\uff08\u4f8b\u5982CPU\uff0cc\u76d8\uff0c\u9501\u7b49\uff09\u3002\u53ef\u4ee5\u901a\u8fc7\u5176\u4ed6\u7684\u624b\u6bb5\u6765\u8f85\u52a9\u5256\u6790\u786e\u8ba4\uff0c\u4f8b\u5982CPU\u8d44\u6e90\uff1a<\/p>\n
\u524d\u4e24\u4e2a\u662f\u501f\u52a9\u7387\u6307\u6807\uff0c\u53ef\u62ff\u6765\u8fa8\u8bc6\u5de5\u4f5c\u8d1f\u8f7d\u7684\u7279\u70b9\uff1b\u540e\u4e09\u4e2a\u662f\u9971\u548c\u5ea6\u6307\u6807\uff0c\u53ef\u62ff\u6765\u8fdb\u884c\u6027\u80fd\u5256\u6790\u3002\u4e0d\u4ec5CPU\u91cf\u5316\uff0c\u8fd8\u53ef\u4ee5\u5bf9c\u76d8I\/O\u8fdb\u884c\u91cf\u5316\u3002\u987b\u8981\u8bf4\u660e\u7684\u662f\uff0c\u672c\u8282\u63d0\u53ca\u7684\u5404\u7c7b\u91cf\u5316\u624b\u6bb5\u4e0e\u5e73\u5747\u8d1f\u8f7d\u7edf\u8ba1\u5e76\u4e0d\u51b2\u7a81\u3002<\/p>\n
\u7ed3\u8bed<\/p>\n
1993\u5e74\uff0c\u4e00\u4f4dlinux\u5de5\u7a0b\u5e08\u53d1\u89c9\u8d1f\u8f7d\u7edf\u8ba1\u5b58\u5728\u4e0d\u7b26\u5408\u76f4\u89c2\u4e4b\u5904\uff0c\u63d0\u4e86\u4e09\u884cpatch\u5c06\u201cCPUloadavg\u201d\u53d8\u6210\u4e86\u201csystemloadavg\u201d\uff0c\u501f\u4ee5\u53cd\u6620\u7cfb\u7edf\u5bf9CPU\u4e0ec\u76d8\u8d44\u6e90\u7684\u9700\u6c42\uff0c\u5177\u4f53\u5b9e\u73b0\u5219\u662f\u964d\u4f4e\u4e86\u5bf9uninterruptible\u7684\u7edf\u8ba1\u3002\u968f\u7740linux\u7684\u53d1\u5c55\uff0c\u6b65\u5165uninterruptible\u7684\u8def\u5f84\u8d8a\u6765\u8d8a\u591a\uff0c\u4f8b\u5982lock\u3002\u672c\u6587\u4e2d\uff0cbrendangregg\u5206\u6790\u65f6\u4f7f\u7528bcc\/eBPF\u91c7\u96c6\u6570\u636e\u5e76\u5236\u505a\u51faOff-CPU\u706b\u7130\u56fe\uff0c\u8fd8\u63d0\u53ca\u4e86\u5404\u7c7b\u5de5\u5177\uff0c\u8fd9\u79cd\u6211\u4eec\u90fd\u53ef\u4ee5\u5728\u5b9e\u9645\u5256\u6790\u95ee\u9898\u65f6\u52a0\u4ee5\u501f\u52a9\u3002\u6700\u540e\uff0c\u672c\u6587\u4ee5linuxkernel\/sched\/loadavg.c\u4e2d\u7684\u6ce8\u91ca\u6765\u7ed3\u675f\uff1a<\/p>\n
\n
* This file contains the magic bits required to compute the global loadavg* figure. Its a silly number but people think its important. We go through* great pains to make it work on big machines and tickless kernels.<\/pre><\/p>\n","protected":false},"excerpt":{"rendered":"avg\u7684wikipedia\u89e3\u91ca\u4e3a\uff1a\u7cfb\u7edf\u9700\u8981\u8fdb\u884c\u5904\u7406\u7684\u5de5\u4f5c\u91cf\uff0c\u5177\u8c61\u5219\u53ef\u4ee5\u8868\u8ff0\u4e3a\u7cfb\u7edf\u4e0a\u6b63\u5728\u8fd0\u884c(running)\u548c\u5df2\u7ecfready\u4e14\u7b49\u5f85\u8c03\u5ea6(runnable)\u7684\u8fdb\u7a0b\u6570\u4e4b\u548c\u3002avg\u7684\u4e00\u79cd\u7279\u5316\u5b50\u7c7b\u578b\uff0c\u5177\u4f53\u539f\u56e0\u540e\u6587\u4f1a\u89e3\u91ca\uff09\uff0c\u5b83\u8868\u793a\u7cfb\u7edf\u4e0a\u6b63\u5728\u4ee5\u53ca\u7b49\u5f85\u8fd0\u884c\u7684\u7ebf\u7a0b\u5bf9\u8d44\u6e90\u7684\u9700\u6c42\u3002\u4ed6\u5728\u4e00\u4e9b\u5907\u4efd\u670d\u52a1\u5668\u4e2d\u53d1\u73b0\u4e86\u4e00\u90e8\u5206\u66f4\u8001\u7684\u5185\u6838\u90ae\u4ef6\u5217\u8868tar\u5305\u3002py\u652f\u6301\u7528\u6237\u6001\u4e0e\u5185\u6838\u6001\u6808\uff0c\u8fd9\u91cc\u4e3a\u4e86\u8bf4\u660e\u4ec5\u663e\u793a\u7528\u6237\u6001\u6808\u3002<\/p>\n","protected":false},"author":1,"featured_media":282927,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-282926","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=282926"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282926\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/282927"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=282926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=282926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=282926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}