When managing a Linux system, monitoring CPU usage is crucial. One of the most popular tools for this is the top command. However, you might have noticed something curious: sometimes, CPU usage can exceed 100%.
In this article, we’ll explore why this happens, how top calculates CPU usage, and what it means for your system.
What Is the top Command?
The top command is a real-time system monitor. It provides a dynamic view of the system’s processes, including memory and CPU usage. By default, top updates its output every few seconds, showing which processes consume the most resources.
To run top, simply open your terminal and type:
top
You’ll see a screen filled with information about your system’s current processes.
Tasks: 325 total, 1 running, 324 sleeping, 0 stopped, 0 zombie
%Cpu(s): 4.4 us, 0.0 sy, 0.0 ni, 95.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 7731.5 total, 570.3 free, 4209.5 used, 2951.7 buff/cache
MiB Swap: 2048.0 total, 347.3 free, 1700.7 used. 2155.8 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6634 vyom 20 0 567248 53416 40440 S 6.2 0.7 2:07.67 gnome-terminal-
108953 vyom 20 0 13344 4224 3328 R 6.2 0.1 0:00.02 top
1 root 20 0 168476 10476 6892 S 0.0 0.1 0:08.03 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.08 kthreadd
3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp
5 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 slub_flushwq
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 netns
8 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/0:0H-events_highpri
11 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 mm_percpu_wq
12 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_kthread
How CPU Usage is Calculated
In top, CPU usage is calculated as a percentage of the CPU’s capacity. This can be a bit tricky because modern CPUs have multiple cores. For a single-core CPU, 100% means full usage. But for a multi-core CPU, top can show usage that exceeds 100%.
Example of Single-Core vs. Multi-Core
Imagine your system has four cores. If one process uses 100% of one core, top shows 100% for that process. But if another process uses 100% of a second core, you could see 200% total CPU usage. This is because top sums the usage across all cores.
Here’s a simple way to understand this:
- Single-core CPU: 100% means full usage.
- Dual-core CPU: 200% is the maximum (100% per core).
- Quad-core CPU: 400% is the maximum.
Why CPU Usage Can Exceed 100%
Seeing CPU usage over 100% is normal on multi-core systems. Each core can run at 100%, so on a quad-core CPU, you might see usage go up to 400%. This doesn’t mean your CPU is overworked; it just shows that multiple cores are being utilized.
Let’s look at an example. Run the following command to simulate high CPU load:
stress --cpu 4 --timeout 10
In the top output, you’ll notice that CPU usage can exceed 100%. If your system has four cores, it could reach 400%.
Tasks: 331 total, 5 running, 326 sleeping, 0 stopped, 0 zombie
%Cpu(s): 99.3 us, 0.7 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 7731.5 total, 399.0 free, 4205.2 used, 3127.3 buff/cache
MiB Swap: 2048.0 total, 348.2 free, 1699.7 used. 2190.8 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
109280 vyom 20 0 3708 256 256 R 98.7 0.0 0:03.03 stress
109282 vyom 20 0 3708 256 256 R 98.3 0.0 0:03.04 stress
109283 vyom 20 0 3708 256 256 R 98.3 0.0 0:03.02 stress
109281 vyom 20 0 3708 256 256 R 97.0 0.0 0:02.99 stress
Here, each stress process uses nearly 100% of a core, totaling 400%.
Analyzing top Output
Understanding what top shows helps you manage your system better. If CPU usage regularly exceeds 100%, it might indicate that your system is under heavy load. But it could also mean that your system is efficiently using its resources.
To analyze CPU usage, focus on these key points:
- %CPU Column: Shows the percentage of CPU used by each process.
- Overall CPU Usage: Displayed at the top of the screen, showing the total usage across all cores.
- Load Average: Indicates the system load over the last 1, 5, and 15 minutes. Values greater than the number of CPU cores suggest a heavily loaded system.
Conclusion
Seeing CPU usage over 100% in top is normal for multi-core systems. It shows that your system is using all available resources. By understanding how top calculates CPU usage and how to interpret the output, you can ensure your system runs smoothly. You can use the top command to view CPU usage when hosting your application on dedicated server hosting from Atlantic.Net!