Do you own a computer with multi-core processors? Have you heard about processor affinity? If not, you’ll learn here what it is and how it might help IT pros get more control over the performance of their applications.
A little bit of background—many computers these days have multiple core processors. Unfortunately, there aren’t that many applications out there that take advantage of these processors by recognizing multi-threading. However, even single-threaded applications can take advantage of multi-core processors.
What Exactly is Processor Affinity?
Processor affinity is the ability to direct a process to use specific cores. By default, all processes use all of the cores available on the system. If it’s set by default, using all of the cores must be the best choice, right? So why would we want to restrict a process to only certain cores? Actually, there might be a reason for you.
If a certain task or process runs frequently, there would be remains of the previous process run left in the process cache.
Controlling processor affinity 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.
What Are the Benefits of Processor Affinity?
For most programs, processor affinity probably won’t make any difference, but it helps when users are running, for example, anti-virus scans, a game, a browser with heavy Flash apps or something else that uses up a lot of the CPU. If two of these intensive programs are running at the same time—and using all of the possible processor cores—they would probably negatively impact each other’s performance.
But by isolating critical processes to one core and leaving the rest of them to the other core, it allows the critical processes to receive the full power of the processor core, and it does this without affecting the performance of the remainder of the processes.
Note to readers: Check out the post titled “Incredibly Sluggish PC? How to Easily Detect and Combat High Processor Usage” to learn about another interesting way of automatically handling process priorities!
How Do We Enable Processor Affinity?
To enable processor affinity, start by going to Windows Task Manager by using the Ctrl + Shift + Esc shortcut. Navigate to the Processes tab.
Right-click on the process you want to set an affinity for, such as a backup program or a media player.
You will then be presented with a screen similar to the following. It might be slightly different depending on the operating system you’re using and the number of processor cores you have. Select which processors you want to allow the process to utilize. Note that CPU 0 corresponds to the first core, CPU 1 corresponds to the second, CPU 2 the third and so on.
Press OK, and then you’re done. Repeat as desired for other processes.
Unfortunately, you may notice that this needs to be set everytime the process runs. To automatically have it set, you need to edit the program’s shortcut.
Go to a shortcut icon for the program you want to set an affinity for, and right-click on it. Select Properties. Then head to the Shortcut tab.
Under the Target field, copy down what’s already there. Replace it with the following:
C:\WINDOWS\system32\cmd.exe /c start “(Name of Application).exe” /affinity (Affinity Number) “(Path to the exe file)”
Make sure you keep all of the quotes the way they are. Replace Name of Application with the name of the exe file such as firefox.exe. Replace Path to exe file with the path such as C:\Program Files\Mozilla Firefox\firefox.exe.
For the /affinity tag, the number depends on what affinity you want to set. To find the affinity number, do the following:
- List your CPUs horizontally backwards. For quad core, it would look like: CPU 3, CPU 2, CPU 1, CPU 0.
- Convert the ones you want the process to use into 1 and the rest into 0. If I wanted firefox.exe to use CPU 3 and CPU 0, I would have the string 1001.
- This is binary. Convert your binary string into decimal. There are many tools online to do this, such as this one.
- For this example with 1001, it would be /affinity 9.
If I wanted the process firefox.exe to use CPU 3 and CPU 0, the target field would read:
C:\WINDOWS\system32\cmd.exe /c start “firefox.exe” /affinity 9 “C:\Program Files\Mozilla Firefox\firefox.exe”
After you’re done setting up the Target field, press OK and Apply, and try out your new shortcut. The program should automatically open using the proper CPU. You can check by going back to Task Manager.
Setting processor affinity can help improve performance with certain single-threaded programs, especially those that tend to consume a lot of CPU. However, be aware that for many programs, there will not be a noticeable performance improvement.
How is processor affinity working for you? Do you have a better method of doing this? Let us know in the comments.