Technology news and Jobs
The Linux distillery
The nuts and bolts of the Linux process scheduler
The Linux distillery
The nuts and bolts of the Linux process scheduler | The nuts and bolts of the Linux process scheduler |
|
| by David M Williams | |
| Monday, 18 February 2008 | |
|
Page 1 of 3
Multitasking isn’t simple to implement for an operating system developer. It’s simple enough to explain – the CPU’s time must be divided between all the different tasks. Yet, there’s a whole heap more to it than this. Some processes are more important than others and must run regularly. Others are less important and can sit idling in the background. And should you let programs decide when to relinquish control back to the operating system for someone else, or should the OS make these decisions giving each task a specified amount of time to run before suspending it? The part of Linux that looks after all this is known as the scheduler and the truth is that the scheduler offers a number of different algorithms to handle multitasking. No single algorithm is perfect for each and every occasion; a general purpose Linux server used by loads of interactive users may need a different means of handling time sharing than a dedicated web server for example. The Linux kernel actually allows the user to select at boot time which type of scheduling approach should be used. This is not widely appreciated and as a result many Linux systems may in fact be scheduling in a way which is sub-optimal for its purposes. In actual fact, the scheduler is not really a separate process on its own but is executed by every process. Whenever any running process goes to sleep or has to block waiting for input or output it calls scheduler routines to figure out if it should switch control to another task, and if so, which one. This doesn’t happen because application developers tell it to, but because these scheduler calls are embedded within system calls within the Linux kernel itself. Any process which is regularly communicating with devices – like disks and keyboards – will spend a lot of time waiting because the CPU is much faster than any input or output (I/O) device. This idle time is much better spent letting some other process run. By contrast, a mathematical complex program might spend large amounts of time just crunching numbers without any I/O activity. There’s two ways the operating system can proceed: it might let the processes relinquish control whenever they are stuck waiting for something. This is called co-operative multitasking. Or, the OS might take control and force processes to give up for a while so another can run. This latter case is more suitable for the computationally intense example and is known as pre-emptive multitasking. Linux uses both co-operating and pre-emptive multitasking. If a process doesn’t voluntarily hand control back on a regular basis it will be pre-empted. Please read on for how this works. CONTINUED |
| < Next story in category | Previous story in the category > |
|---|








