There is a simple way of getting more performance from the multicore processors. It is called Processor Affinity. It is supported by mainstream operating systems. Let us see how to use it.
Suppose, we have a quad core linux machine, and we use as a desktop. All the applications running on the system will be running on one of the 4 cores. You want to assign one specific cores for music playing, one for routine background backup process, and rest for all desktop applications.
Linux allows a way of "pinning down" a process to a core or a set of cores, through a command line option. For example, we can use taskset command to pin down a running application (say apache webserver, whose PID is 2000) to core 1 as below:
$ taskset -cp 1 2000
While you can pin a running process task to a set of your cores, that does not mean that the process and its threads will be immediately moved to those CPU's you dictated. The kernel scheduler starts preferring your appointed cores instead of the cores your processes are currently using. It can take sometime to see the effect of taskset command for a running process.
Other way is to start a process "pinned down" to a specific core with this command:
$ taskset -c 3 apache
The apache server will start running on core 3 and will be pinned to that core
What are advantages of the processor affinity?
Firstly, one can isolate critical processes to one core and leaving the rest of them to the other cores, it allows the critical processes to receive the full power of the processor core.
Secondly, it can improve performance by reducing the number of cache flushes when process threads move to another processor. If the process is directed to use the same core everytime, performance can be improved due to the ability to re-use the cache. This is particularly true if we use a mix of programs that use high CPU power like anti-virus scan, flash applications which can be tied to cores to avoid the cache flushes
To summarize, processor affinity can improve performance by allocating applications to cores at a coarse grained granularity. Like other tools, one needs to experiment it and find the optimum mix!
用户1582657 2013-1-4 14:08
Good , Thanks