Think about cores, if you want better performance
So, here we are in the world of multi-core CPUs, but we still learn programming in the same way as we used to do in single core days. Unfortunately, by looking at this you might be asking the question...
Isn’t OS is capable of handling it?
Yes it is and it does the best it can do to handle it. However, the kernel designers can’t think of all possible scenarios.
Just like we are coding to minimize the cache hits / miss, we need to do the same with multi-core CPUs
Why? What will be the impact ?
To properly understand, look at the blog picture.
If a process is executing in core-1, moves to core-2 after next preemption, the cache at core-1 will be invalidated. It can’t take advantage of L1 cache which can make things very fast
So, we need to make sure that processes are just not hopping over CPUs. This is bad for performance, especially for 32-64 core CPUs.
Security Implications
if we restrict the process to limited amount of cores, then the process can’t prevent the system from running even with 100% CPU usage.
As a safety precaution, always keep 1 core free so that system can recover from the potential attack
How to do it?
you can do it in linux by manually while starting the process using “taskset” command. Here is a small youtube video which describes how to do the same.
Thanks for reading.. please subscribe to get more tips
A Programming Tip by 9Lean













