The vmstat (virtual memory statistics) command
allows you to monitor your system’s memory usage. It shows how much
virtual memory there is, and how much is free and paging activity.
You can observe page-ins and page-outs as they happen. This is
extremely useful for detecting shortages of physical memory, which
can adversely affect system performance.
Number of context switches is more than the number of interrupts
because:
- A context switch (also sometimes referred to
as a process switch or a task
switch) is the switching of the
CPU (central processing unit) from one process or thread to
another. A process (also sometimes referred to as a task) is an
executing (i.e., running) instance of a program.An interrupt is
simply a signal that the hardware can send when it wants the
processor’s attention. A common example of this is when a packet is
received by the network card; when a packet is received, an
interrupt is thrown and the CPU deals with the packet
- There are three columns when the output of vmstat is generated:
us (user) time, sy (system) time, and id (idle) time. These three
break down the use of the CPU time in percentages. They should add
up to 100%. Ideally, a CPU will spend most of its time in the us
and id categories. The sy category refers to time the CPU spends
doing driver/kernel-level work. This time is taken away from user
applications. If the CPUs are spending most of their time in this
category, it could indicate excessive context switching due to
either CPU or memory bottlenecks, issues with kernel-level locking,
or other problems leading to excessive number of number of context
switching. A busy system will show a constant idle percentage near
zero. But a busy system doesn’t necessarily mean that the system is
overloaded.