1821253 Members
2798 Online
109632 Solutions
New Discussion юеВ

context switching

 
Arockia Jegan
Trusted Contributor

context switching

Hi,

We are having V class system running hpux 11.11. System has 16Gb mem and 12 CPUs. When I see the sar report I always see pswch/s value in thousands. We are not running many processes. I'm expecting minimal minimal context switching ... What may be the problem?
9 REPLIES 9
Jean-Louis Phelix
Honored Contributor

Re: context switching

Hello,

Perhaps someone changed the timeslice kernel parameter :

timeslice
Leave this set at 10. If this is set to 1, which used to happen because of that old sam
configuration template with a bug in it, excessive context switching overhead will usually
result. The system would spend, oh, 10 times what it normally does simply handling
timeslice interrupts. It can possibly also cause lock contention issues if set too low.

Regards,

Jean-Louis.
It works for me (┬й Bill McNAMARA ...)
Arockia Jegan
Trusted Contributor

Re: context switching

timeslice is 10 from the beginning.
John Dvorchak
Honored Contributor

Re: context switching

I don't know that thousands of context switches is all that unusual. Every process has switches, whether voluntary or forced. On a system with no applications running and just user shells you will have hundreds of switches per second. Remember that context switches are normal and each process, either a single command or an ongoing process, is switched before it finishes it's time slice. I/0 will cause voluntary context switching and an ongoing cpu intensive process will have a forced context switch before it's time slice completes, many times per second. Instead of looking for a raw number of c-switches look at the ratio of forced versus voluntary. If voluntary is many times higher than forced, I would suggest that ther might me an I/O problem, usually with a disk. That is where glance can be very useful to show the type of switch by process, rather than sar with is a global snapshot.
If it has wheels or a skirt, you can't afford it.
Alan Riggs
Honored Contributor

Re: context switching

Contex tswitching is not in itself a prolem. Even with few processes, if your individual processes are "long lived" they will be forced to yield CPU after each timeslice. This results in a context switch. A context switch will also be generated each time a process voluntarily abandons the CPU.

Do you run glance? IF so, then it might be worthwhile to examine some of your application processes in detail to see if they are being forced from CPU by timeslice or abandoning the CPU voluntarily. If they are giving up CPU voluntarily (which is my guess) then what you are seeing is a symptom of the application code.
Arockia Jegan
Trusted Contributor

Re: context switching

Thanks Guys. Most of the time the voluntary context switch is in thousands. Forced context switch is between 5 to 20. We are running a oracle job. Getting very low I/O rate(150 Phys IO rate). But there is no disk contention. Disk is not at all busy and the average queue is less than 1. If we start another oracle job then the IO is going down very low.
When I was looking at the sar reports/ Glance view I couldn't find anything strange other than context switching... any thoughts...
John Dvorchak
Honored Contributor

Re: context switching

Thoughts? Yes, the last time I saw a ratio like that the primary SCSI path to a disk drive had died and it was talking a long time to complete disk I/O via the alternate path. The queue was small because the actual time to write, once it found a good hardware path, was very small. Take a look at sar -d and look for unusually long av times.

I am not saying that you have a physical problem, but that ratio of thousands of voluntary to forced switches is not usual or normal. And if you think about it, if the system is waiting on a partially failed disk, the disk I/O rate would be unusually low.

To further explain, a voluntary context switch occurs when the process does an I/O and takes itself out of the runqueue. When the I/O completes it puts itself back into the runque to take it's turn at the processor.

A forced or involuntary context switch occurs when the process has used more than half of it's time slice, and gets switched out before it has completed, for a process with higher or equal priority. It is then placed by the system back in the runqueue.
If it has wheels or a skirt, you can't afford it.
Bill Hassell
Honored Contributor

Re: context switching

Make sure you are matching context switch metrics with I/O metrics. As mentioned, a context switch (potentially) can occur on a busy system for every I/O (including: once per keystroke, once per LAN I/O and once per disk or tape I/O). If you have more than 12 active processes and more than 12 active users on the system, seeing thousands of context switches with 150 disk I/O's/sec plus 200 LAN I/O's/sec and 50 users typing at the same time which will generate several hundred I/O's/sec...now the thousands metric looks normal.


Bill Hassell, sysadmin
Evert Ladrak
Advisor

Re: context switching

Just as something to check. Make sure that not all the disks in the Volume group's use the same primary path to the disks.
Try to balance the IO as much possible over the primary and alternate paths.
It makes a big difference even on Fibre channel.

-ETL
Evert
harry d brown jr
Honored Contributor

Re: context switching


Do you have EMS running?

live free or die
harry
Live Free or Die