How are CPU loads balanced? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












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?







share|improve this question













closed as off-topic by Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov, G-Man Jun 15 at 4:57


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov
If this question can be reworded to fit the rules in the help center, please edit the question.
















    up vote
    3
    down vote

    favorite
    1












    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?







    share|improve this question













    closed as off-topic by Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov, G-Man Jun 15 at 4:57


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov
    If this question can be reworded to fit the rules in the help center, please edit the question.














      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      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?







      share|improve this question













      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?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 14 at 16:41
























      asked Jun 14 at 14:43









      user258532

      1163




      1163




      closed as off-topic by Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov, G-Man Jun 15 at 4:57


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov
      If this question can be reworded to fit the rules in the help center, please edit the question.




      closed as off-topic by Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov, G-Man Jun 15 at 4:57


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Requests for learning materials (tutorials, how-tos etc.) are off topic. The only exception is questions about where to find official documentation (e.g. POSIX specifications). See the Help Center and our Community Meta for more information." – Ipor Sircer, schily, Rui F Ribeiro, Romeo Ninov
      If this question can be reworded to fit the rules in the help center, please edit the question.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote













          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).



          https://superuser.com/questions/440906/what-is-the-migration-process



          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.






          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













            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).



            https://superuser.com/questions/440906/what-is-the-migration-process



            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.






            share|improve this answer

























              up vote
              2
              down vote













              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).



              https://superuser.com/questions/440906/what-is-the-migration-process



              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.






              share|improve this answer























                up vote
                2
                down vote










                up vote
                2
                down vote









                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).



                https://superuser.com/questions/440906/what-is-the-migration-process



                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.






                share|improve this answer













                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).



                https://superuser.com/questions/440906/what-is-the-migration-process



                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.







                share|improve this answer













                share|improve this answer



                share|improve this answer











                answered Jun 14 at 20:45









                tk421

                2168




                2168












                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?