Linux LOADAVG algorithm

Source: Internet
Author: User
Tags define file system linux
Algorithm Linux LOADAVG algorithm


Published by: Biti_rainy



Today read Linux source code on the CPU load calculation method, while Google search everywhere for reference, dizzy for half a day, finally understand the CPU load calculation method, is not a simple move arithmetic average.


For Linux, the sampling calculation load interval of 5 seconds, which is defined in the source code of the fixed number, its sampling structure through the dynamic memory file system/proc/loadavg can dynamically get the timely data, other tools output, such as Uptime/top /sar, etc. are all generated by reading the memory data. We are here to focus on the kernel algorithm.

For a 5-second interval, the CPU state data is sampled dynamically, which is the run queue size, which includes the number of processes being running in the CPU and the number of processes in the CPU wait queue. For Linux, it actually calculates the moving average of 1 minutes, 5 minutes, and 15 minutes. For this we first introduce 3 constants defined in Linux:

#define EXP_1 1884/* 1/EXP (5sec/1min) * *
#define EXP_5 2014/* 1/EXP (5sec/5min) * *
#define EXP_15 2037/* 1/EXP (5sec/15min) * *

The three constants represent constants for 1/5/15 minutes, which are calculated by:

1884 = 2048/(Power (E, 5/(60*1)))/* E = 2.71828 * *

2014 = 2048/(Power (E, (5/60*5)))

2037 = 2048/(Power (E, (5/60*15)))

We assume that the load of the previous moment, measured in constant 1884, is Load1 (t-1), and the current sample run queue size is rq1, then the current load1 (t) = ((Load1 (t-1) * 1884) + rq1 * (2048-1884))/2048

The same can be 5 minutes and 15 minutes moving average algorithm is load5 (t) = ((Load5 (t-1) * 2014) + rq1 * (2048-2014))/2048 and load_15 (t) = ((Load15 (t-1) * 2037) + RQ 1 * (2048-2037))/2048

It can be seen that the larger the moving average interval, the smaller the current run queue size has on the moving average.

As for why this number is involved in calculus, this makes the image smoother.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.