LINUX TIPS AND TRICKS --- November 02, 2001

Published by ITworld.com -- changing the way you view IT
http://www.itworld.com/newsletters
_________________________________________________________________

Preemptive Kernel
By Danny Kalev

Preemption 101
"Preemption" basically means that a running task can be 
suspended while another task takes its place as the currently 
running process. Once a task has consumed its allotted quantum, 
or CPU time slice, the scheduler will suspend it and run the 
next task in the queue. In practice, the scheduling algorithm 
is more complicated because of different process priorities.

User vs. Kernel Preemption
You might get the impression that the scheduler can preempt a 
running process at any given time. That's not entirely correct. 5
Linux supports only user-level preemption, which allows the 
scheduler to suspend a process as long it's running in user 
mode. It will not suspend a running process that is in kernel 
mode, though (read more on kernel mode vs. user mode here: http://www.itworld.com/nl/lnx_tip/06082001).

Kernel Preemption Pros and Cons 
By contrast, a preemptive kernel may suspend a running task even 
if it's in kernel mode. This is necessary in hard-core, 
real-time applications that must meet very rigid time 
constraints. Under the user preemption model, syscalls present 
a challenge in this regard. Although their execution time is 
very short, it isn't constant. For instance, the time needed to 
complete a malloc() call depends on heap fragmentation, the 
size of the requested memory block, and the system's load. Thus,
one call may take 10 milliseconds to complete whereas another 
might take 50. A task that must terminate within 40 milliseconds
might not finish on time if another process calls malloc() 
in between.

By contrast, the scheduler could preempt the malloc() call and 
enable the real-time task to always finish on time under a 
preemptive kernel. Kernel preemption can also improve the 
responsiveness of some notorious applications that cause the 
system to freeze up for a short while during certain activities.

Kernel preemption exacts a price, though. Many applications 
aren't ready to deal with the possibility of a preempted 
syscall. Preemption also will require a kernel overhaul and 
complicate the kernel's code. Is it really worth the trouble? 
For most everyday uses, the answer is "no". That said, with 
Linux becoming the OS of choice in embedded and real-time 
environments, the demand to add kernel preemption is constantly 
increasing. Presently, several preemptive kernel patches are 
available such as Robert Love's patch: 
http://www.tech9.net/rml/linux/ For benchmark results, 
visit the Linux kernel preemption project: 
http://itw.itworld.com/GoNow/a14724a45152a76537031a3


About the author(s)
-------------------
Danny Kalev is a system analyst and software engineer with more 
than 10 years of experience, specializing in C++ and 
object-oriented analysis and design on various platforms 
including VMS, DOS, Windows, Unix, and linux. His technical 
interests involve code optimization, networking, and 
distributed computing. He is also a member of the ANSI C++ 
standardization committee and the author of ANSI/ISO C++ 
Professional Programmer's Handbook (Que, 1999). Danny can be 
reached at linuxnl@excite.com.
_________________________________________________________________

ADDITIONAL RESOURCES

The Linux kernel preemption project
http://itw.itworld.com/GoNow/a14724a45152a76537031a3

Using Kernel Processes
http://itw.itworld.com/GoNow/a14724a45152a76537031a0

Low priority tasks
http://itw.itworld.com/GoNow/a14724a45152a76537031a2

Multitasking and Preemption
http://itw.itworld.com/GoNow/a14724a45152a76537031a1
_________________________________________________________________

ITWORLD.COM NEWSLETTER ARCHIVE

Index of Linux Tips and Tricks
http://www.itworld.com/nl/lnx_tip/

SQL Databases
http://www.itworld.com/nl/lnx_tip/12152000/

Linux Databases Part II
http://www.itworld.com/nl/lnx_tip/12222000/
_________________________________________________________________

CUSTOMER SERVICE

SUBSCRIBE/UNSUBSCRIBE:
- Go to: http://www.itworld.com/newsletters
- Click on "View my newsletters" to log in and manage your
  account
- To subscribe, check the box next to the newsletter
- To unsubscribe, uncheck the box next to the newsletter 
- When finished, click submit

Questions? Please e-mail customer service at: 
mailto:support@itworld.com
_________________________________________________________________

CONTACTS

* Editorial: Andrew Santosusso, Newsletter Editor, 
  andrew_santosusso@itworld.com

* Advertising: Clare O'Brien, Vice President of Sales, 
  clare_obrien@itworld.com

* Career Corner: Janis Crowley, Vice President/General Manager,
  IDG Recruitment Solutions, janis_crowley@itcareers.net

* Other inquiries: Jodie Naze, Senior Product Marketing Manager, 
  jodie_naze@itworld.com
_________________________________________________________________

PRIVACY POLICY
ITworld.com has been TRUSTe certified 
http://www.itworld.com/Privacy/

Copyright 2001 ITworld.com, Inc., All Rights Reserved.
http://www.itworld.com
