Recent Articles

The Cost Of Linux
Matt Asay's AC/OS blog says that one of the "expenses" noted in Microsoft TCO studies is the cost of training.

Bash Aliases
Most shells have some provision for aliases. Aliases can assign default behavior to a command (for example "rm" is often aliased to "rm -i")...

Bash In-process Regular Expressions
Bash acquired in-process regular expressions in version 3.0, but I never noticed, probably because most of the machines I'm using are Bash 2.05b.


10.25.05


Taskset For CPU Affinity

By A.P. Lawrence

SMP operating systems have choices when it comes to scheduling processes: a new or newly rescheduled process can run on any available cpu.

However, while it shouldn't matter where a new process runs, an existing process should go back to the same cpu it was running on simply because the cpu may still be caching data that belongs to that process. This is particularly apt to be true if the process is a thread: the other threads in the same program are very likely to have cpu cache of interest to their brethren (though obviously this also diminishes the performance gain that might be seen from multithreading) . For these reasons, scheduling algorithms pay attention to cpu affinity and try to keep it constant.

It is possible to force a process to run only on a certain cpu. There are Linux system calls (sched_setaffinity and sched_getaffinity) and a command line "taskset".

Most of us probably don't need to bother with being heavy handed here. The Linux scheduler probably does a better job assigning processes to cpu's than we would. There may be conditions where you want to effectively dedicate a cpu to a certain process. Usually that means forcing all other processes to another cpu to prevent them from migrating to the cpu you want to keep dedicate.


That's not too hard if we are only dealing with two cpu's because processes inherit affinity from their parants. So if you forced "init" to bind to cpu 0, all of its children would inherit that restriction and wouldn't use cpu one unless specifically set. You'd then set your "special" process to use cpu 1. This only gets a little more complicated with more than two processors; available cpu's are just a bit mask, so you would bind init to use more than one cpu but not the one you want to keep clear.

*Originally published at APLawrence.com
About the Author:
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com

About LinuxDeveloperNews
Get the lastest information on current changes in the Linux Development World.

LinuxDeveloperNews is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxDeveloperNews.com WirelessProNews.com
CProgrammingTrends.com DevWebPro.com




-- LinuxDeveloperNews is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2005 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal

archives | advertising info | news headlines | free newsletters | comments/feedback | submit article

LinuxDeveloperNews News Archives About Us Feedback LinuxDeveloperNews Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact