Fundamentals 15 min read

Understanding Linux Load Average: Principles and Calculations

This article explains Linux load average, covering how it is calculated, its relationship with CPU usage, and how the kernel exposes load data to applications.

Refining Core Development Skills
Refining Core Development Skills
Refining Core Development Skills
Understanding Linux Load Average: Principles and Calculations

This article provides a comprehensive explanation of Linux load average, addressing common misconceptions and detailing the underlying mechanisms. It begins by explaining how load average is typically viewed using the top command, which retrieves data from the /proc/loadavg pseudo-file. The article then traces the data flow from user space to the kernel, explaining how the kernel defines and handles this pseudo-file.

The core of the article explains how load average is calculated in the kernel. It describes a two-step process: first, a high-resolution timer periodically collects the number of running and uninterruptible processes from each CPU's run queue, aggregating this into a system-wide instantaneous load value. Second, a timer interrupt uses an exponential weighted moving average (EWMA) algorithm to compute the 1, 5, and 15-minute load averages from this instantaneous value.

The article clarifies that modern Linux load average includes not only runnable processes but also uninterruptible processes (those waiting on I/O), which is why load average is not always directly correlated with CPU usage. It explains the historical context for this design choice, noting that it was introduced to better reflect overall system resource demand, not just CPU demand.

Finally, the article summarizes the key points: how load average is calculated, why it may not correlate directly with CPU usage, and how the kernel exposes this data to user applications through the /proc/loadavg interface.

kernelI/OLinuxCPUsystem performanceexponential weighted moving averageload averageprocess states
Refining Core Development Skills
Written by

Refining Core Development Skills

Fei has over 10 years of development experience at Tencent and Sogou. Through this account, he shares his deep insights on performance.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.