Ubuntu top command cpu usage more than 100

Through the study of load average and CPU context switching in my previous two articles: “Linux CPU Context Switch Deep Dive”, “Linux CPU Context Switch Troubleshooting”, I believe you have a preliminary understanding of CPU performance. But what metrics do you use most to troubleshoot high CPU usages?

CPU Usage

The CPU usage is a statistic of CPU usage per unit time, displayed as a percentage. So, as the most commonly used and most familiar CPU metric, can you tell how the CPU usage is calculated? Also, do you know the meaning behind`%user`, %nice, %system, %iowait, %steal , etc? Can you tell the difference between them?

Let’s deep dive into CPU usage in this article. As I mentioned earlier, Linux is a multitasking OS, which divides the time of each CPU into very short time slices, and then allocates them to each task in turn through the scheduler, thus creating the illusion of multitasking running at the same time.

In order to obtain CPU time, Linux triggers a time interrupt through a pre-defined beat rate (express as HZ in the kernel), and uses the global variable jiffies to record the number of beats since booting. Every time a time interrupt occurs, the value of jiffies is incremented by 1.

The beat rate HZ is a configurable option for the kernel and can be set to 100, 250, 1000, etc. Different systems may set different values, you can view its configuration value by querying the /boot/config kernel option.For example, in my Amazon Linux 2, the `%user`0 is:

$ grep 'CONFIG_HZ=' /boot/config-$(uname -r) CONFIG_HZ_250=y CONFIG_HZ=250

`%user`1 means 250 interrupts are triggered per second (1 interrupt every 4 milliseconds). Upon receiving a time interrupt, the kernel drops everything and performs various scheduling and timekeeping related tasks.

The tick rate HZ is a kernel option, so user-space programs cannot directly access. For the convenience of user-space programs, the kernel also provides a uer-space tick rate %user`3 , which is always fixed at 100. In this way, the user program does not need to care what `HZ is set to in the kernel.

Issue

  • The output of top command shows that "XXXX" process is using more than 100% CPU utilization.

top - 09:11:37 up  2:37,  1 user,  load average: 0.89, 3.56, 3.72
Tasks: 398 total,   1 running, 397 sleeping,   0 stopped,   0 zombie
Cpu(s):  6.1%us,  2.3%sy,  0.0%ni, 88.5%id,  3.0%wa,  0.0%hi,  0.1%si,  0.0%st
Mem:  24605544k total,  3007220k used, 21598324k free,    63632k buffers
Swap: 18579448k total,     5748k used, 18573700k free,   732280k cached
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
9029 mysql     20   0 4856m 1.1g 4092 S 111.5  4.9  66:25.56 XXXX            
22173 apache    20   0  626m  22m 9856 S 23.2  0.1   0:04.35 httpd              
21935 apache    20   0  625m  25m  12m S  5.8  0.1   0:03.12 httpd              

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8
  • Red Hat Enterprise Linux 9
  • procps-ng

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

CPU utilization is the amount of work a CPU does to perform the tasks given to it. It’s an important metric to track because high CPU usage can negatively impact the performance of a system.

CPU usage can vary according to the CPU core count, since the system performs faster and more efficiently in the case of a higher core system. If the CPU cores are unable to handle the heavy load of an application, it results in context switching of tasks. But too much context switching will also cause a rise in CPU usage.

Tracking and monitoring CPU efficiency are essential for handling system processes and resources. Luckily, there are a number of tools available to monitor this metric.

Causes of high CPU utilization

Since high CPU utilization indicates poor system performance, it should be avoided. Higher than average CPU usage can often be attributed to one of the following causes:

1. System idle process

If a system is idle, the OS creates a process called the System Idle Process to prevent the system from shutting off. This process appears to show high CPU usage, but it actually indicates the percentage of CPU capacity not being used. If the idle process is taking up to 99% of the CPU's power, it means only 1% is being used to run actual tasks.

2. Autostart programs and background processes

Autostart programs are applications that are launched automatically when booting the operating system and they continue to run in the background. Too many background processes running simultaneously on a computer consume CPU resources and unnecessarily cause high CPU usage.

3. Virus and malware

If a system becomes extremely slow with a CPU usage of nearly 100%—but with no clear cause—the problem may be a virus or malware. These are often invisible and heavily utilize the CPU.

4. Browser

Even the browser can cause high CPU usage if:

  • Several tabs are opened at the same time
  • Multiple plugins and add-ons are running in the background
  • Browser tabs with ads or auto-playing videos are open

5. Programs with high CPU requirement

Applications or programs that require high processing power, including video editing software and high-resolution video games—can easily drive up CPU usage.

Effects of high CPU utilization

High CPU utilization adversely impacts system performance in the following ways:

  • Lag in CPU performance
  • Frequent rebooting of systems
  • Delay in response from application
  • Overheating of CPU

It's essential to check the CPU usage regularly to understand the cause and impact of high CPU utilization.

Determining CPU utilization

Below are some of the most popular commands used for real-time monitoring of the CPU usage in a Linux system.

top Command

The top command is used to display a real-time, dynamic view of a running system. It displays various crucial system metrics along with a set of processes that are currently being managed by the Linux kernel. It is one of the most widely used commands for tracking the CPU utilization, process statistics, and memory utilization of a Linux system.

For example, running the top command on a Linux system will display an output similar to the one shown below:

Ubuntu top command cpu usage more than 100
Fig 1: Output of top command

In the output above, the top command displays various important CPU statistics, including idle time and wait time. You can calculate the overall CPU utilization using the idle time using the formula given below:

CPU utilization = 100 - idle time

For example, in the output above, the idle time is 98.3%, so the CPU utilization can be calculated as follows:

CPU utilization = 100 - 98.3 = 1.7%

The top command generates a list of processes sorted by the parameter %CPU, or percentage of CPU consumed by a process. This list includes various details about each process and is refreshed automatically every 5 seconds.

mpstat Command

The mpstat command provides information about CPU performance and utilization by giving CPU statistics for the whole system and each available processor.

Running the mpstat command on a Linux system will display an output like the one shown in figure 2.

Ubuntu top command cpu usage more than 100
Fig 2: Output of mpstat command

This command shows various CPU statistics including idle time, io wait time and steal time. Similar to the top command, the idle time shown here can be used to compute the CPU utilization using the same formula.

The following command can be run to get statistics for each of the CPUs or processors:

mpstat -P ALL

This command will generate an output similar to the one shown in figure 3.

Ubuntu top command cpu usage more than 100
Fig 3: Output of mpstat -p ALL command

Thus, the CPU utilization of processors CPU0 and CPU1 can be calculated as shown below:

CPU0 = 100 - 92.13 = 7.87

CPU1= 100 - 22.78 = 77.22

Monitoring CPU utilization per process

Checking the CPU utilization for each process is essential. A system may show high CPU utilization even though only a few processes account for most of the usage. Investigate individual processes to identify the cause and terminate them as needed.

In addition to top command,

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

0 is another useful command for viewing process-level CPU statistics.

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

0 command

The

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

0 command provides information about the processes running in the Linux system. It’s used to view process-related information, including the user of the process, the type of terminal used, and the

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

3 of the process.

Running the

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

0 command on a Linux system will generate an output similar to the one shown below.

Ubuntu top command cpu usage more than 100
Fig 4: Output of ps command

You can also use the ps command to view the top 10 most CPU-intensive processes by running the following command:

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

The output of this command will look similar to the figure below.

Ubuntu top command cpu usage more than 100
Fig 5: Top 10 most CPU consuming processes

The output of the above command provides process-related information such as process ID(PID), process user, and the command used to run the process. This information is sorted according to CPU utilization and helps a user identify the process using most of the CPU so they can take action accordingly.

Conclusion

CPU utilization represents the amount of work a CPU handles to process resources or manage an operating system’s tasks. This metric is used to determine system performance by estimating the average CPU usage over a certain period of time.

Several factors contribute to high CPU usage so it’s essential to find the root cause to reduce it. This article provides three useful commands—top, mpstat, and

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

0 to help users monitor and troubleshoot CPU related issues on Linux.

In most scenarios, these commands are sufficient to troubleshoot and reduce the high CPU utilization.

Why does top show more than 100% CPU?

htop shows that cpu usage of per core over 100%? Some blogs explain that this is because I'm using a multi-core machine(this is true). If there are 8 (logic) cores, the max value of CPU% is gonna be 800%. CPU% over 100% means that my task is occupying more than one core.

What is CPU above 100 in Linux top command?

Yes, if a process in top goes over 100% or top shows >1.0 in load, this means that more than one core is occupied, or the system is oversubscribed. Oversubscription means that there is more work to be put onto the core than is phsyically manageble.

Why is my CPU usage above 100%?

CPU usage going up to 100% can be caused by multiple things such as a failing hard drive, virus/malware, or software that utilizes the CPU so much.

What is the 800% CPU in top command?

If you have 8 cores, then top can display CPU usage from 0% (idle system) to 800% (full power). Your program is just using your 4 cores with hyper-threading (so 8 virtual cores) at maximum capacity. So top gives you nearly 8 x 100% = 800%.