I ran into a problem with Firefox on Xubuntu. Sometimes, Firefox hogs one CPU core, while all other cores are idling. Website buildup was very slow and very annoying.

I noticed that when I leave my computer alone for some time (without a reboot), something magical happens, and then Firefox again uses all CPU cores equally.

Somewhere, I read that CPU cores are attached to items in cache/buffer, and so it's actually better when a (multi-core) program temporarily uses one CPU core, instead of freeing up the other cores from their cache/buffer jobs.

Can somebody give some further explanation on how CPU loads are balanced?

1 Answer 1


In general, UNIX and Linux scheduling assumes lots of short programs (think ls, ps, grep ...) so it will start a program on one CPU. As programs run longer (think Firefox, or Chrome), the kernel realizes the load is imbalanced and will migrate the processes to different CPUs. This is done by the migration job (as seen by running ps).


To understand how migration is done, refer to: https://stackoverflow.com/questions/49707124/how-does-linux-kernel-migrate-the-process-among-multiple-cores

 * This is how migration works:
 * 1) we invoke migration_cpu_stop() on the target CPU using
 *    stop_one_cpu().
 * 2) stopper starts to run (implicitly forcing the migrated thread
 *    off the CPU) 
 * 3) it checks whether the migrated task is still in the wrong runqueue.
 * 4) if it's in the wrong runqueue then the migration thread removes
 *    it and puts it into the right queue.
 * 5) stopper completes and stop_one_cpu() returns and the migration
 *    is done.

To understand how load is determined refer to: https://github.com/torvalds/linux/blob/master/kernel/sched/fair.c and look at the comments around migration. But overall, the scheduler has to look at:

  • how busy the CPU is
  • the cost to migrate the process
  • the number of system faults generated

Then it has to determine which process to migrate and which CPU to migrate to.

This is all fairly complicated and so if you wish to understand this further, I recommend looking at: https://blog.acolyer.org/2016/04/26/the-linux-scheduler-a-decade-of-wasted-cores/ and the original paper: The Linux Scheduler: a Decade of Wasted Cores.


Not the answer you're looking for? Browse other questions tagged .