High Context Switch Troubleshooting

  • 7002720
  • 20-Feb-2009
  • 22-Feb-2013

Environment

Novell Open Enterprise Server 11 (OES 11)
Novell Open Enterprise Server 1 (OES 1)
Novell Open Enterprise Server 2 (OES 2)
SUSE Linux Enterprise Server 11
SUSE Linux Enterprise Server 10
SUSE Linux Enterprise Server 9

Situation

You have observed a high number of context switches and some applications may not be performing as expected. A context switch is the switching of the CPU from one process or thread to another. The context switches are reported in the system "cs" column.

#==[ Command ]======================================#
# /usr/bin/vmstat 1 4                                         vvvvv
procs -----------memory----------  ---swap-- -----io----  -system-- -----cpu------
 r  b   swpd   free   buff  cache   si    so    bi    bo   in    cs us sy id wa st
 1  1 373704   7156   1296   4144   47    78   139    92 2450   574  9 27 64  0  0
24 16 376664   6924   1360   3152  532  3104   552  3356 8101 33269  3 97  0  0  0
15 15 386388   6788   1356   5260 5872 10212  8656 10284 7623 39149  2 96  0  1  0
10 10 389896   6720   1232   3244 2384  3584  2532  3640 8893 17113 11 89  0  0  0
                                                              ^^^^^

When context switches exceed 10,000, you should account for the cause.

Resolution

A high number of context switches may just mean you have a lot of running busy processes and few idle ones. If your server is just busy and performance is an issue, consider distributing the processes among more servers. If the context switches are really high, then you might consider isolating the application causing the context switches. It may be an indication of an application bug. Use the ps command to view the running processes and unloaded and load applications one at a time to narrow down which may be causing the high number of context switches.

SLES11 tends to have higher numbers, but if your server and applications are running as expected, there is nothing to worry about.