Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "high involuntary context" switches mean?

Tags:

People also ask

What is an involuntary context switch?

Involuntary context switch refers to the context switch that occurs when the process is forced to be rescheduled by the system due to time slice has expired. For example, involuntary context switches are prone to occur when a large number of processes are competing for CPU.

What is high context switches?

A high context switch rate in the operating system (OS) signals that the OS is handling many different tasks and must alternate between them. In a DB2® system, this usually causes latch contention or the presence of many database connections. A slow down in SQL query performance can be the result.

What is voluntary and involuntary context switches?

A voluntary context switch occurs when a thread blocks because it requires a resource that is unavailable. An involuntary context switch takes place when a thread executes for the duration of its time slice or when the system identifies a higher-priority thread to run.

How much context switching is too much?

If it's close to 10% or higher, that means your OS is spending too much time doing the context switches.


I have re-written a part of code in C. When testing it with logging the resource usage using getrusage(2) C API.

Before changing the code:

user time (ms): 21503
system time (ms): 372
involuntary context switches: 20

After changing:

user time (ms): 25589
system time (ms): 80732
involuntary context switches: 821

I see a lot of involuntary context switches being done in the code I have re-written.

My question is not about how to reduce context switches. But..

  1. What happens when "involuntary context switches" are more?
  2. In what way it will affect the system?

P.S: There is no activity on the disk as nothing is being written. It just pings the server several times.

Update:

Added system and user time taken.

Program is multi-threaded. Same number of threads (3k thread) are spawned in both the cases. Only the underlying api in C is being rewritten.