CPU context switch is a core function to ensure normal operations of Linux system. It can be divided into “process context switch”, “thread context switch” and “interrupt context switch”.
Check CPU Context Switching
We know that too many context switching can consume CPU time in saving and restoring data such as registers, program counters, kernel stacks and virtual memory, etc, which could cause significant drop in system performance.
Since context switching has such a large impact on system performance, how do we check context switching? Well, you can use vmstat
tool to query the context switching of your system.
vmstat
vmstat
is a commonly used system performance analysis tool. It is mainly used to analyze the memory usage and it is also commonly used to analyze the number of CPU context switches and interrupts.
For example, the vmstat 6
command outputs this data every 6 seconds. Here’s a sample output of vmstat 6
:
$ vmstat 6
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 94632 12228 245960 0 0 3 4 0 1 2 1 96 1 0
0 0 0 94544 12228…