16

If a single threaded process is busy and uses 100% of a single core it seems like Windows is switching this process between the cores, because in Task Managers core overview all cores are equal used.

Why does Windows do that? Isn't this destroying L1/L2 caches?

2
  • Task Manager is IME not very reliable for details. In particular, in Windows XP, when Windows update brought my PC to its knees, according to Task Manager nothing was going on. I doubt that's been fixed, since it apparently a great deal of work had been expended to hide things.This historical unreliability might be part of the explanation. Mar 7, 2015 at 23:36
  • @Cheersandhth.-Alf: Possibly true, but Windows does move processes between cores.
    – Ben Voigt
    Mar 8, 2015 at 0:32

2 Answers 2

30

There are advantages to pinning a process to one core, primarily caching which you already mentioned.

There are also disadvantages -- you get unequal heating, which can create mechanical stresses that do not improve the expected lifetime of the silicon die.

To avoid this, OSes tend to keep all cores at equal utilization. When there's only one active thread, it will have to be moved and invalidate caches. As long as this is done infrequently (in CPU time), the impact of the extra cache misses during migration is negligible.

For example, the abstract of "Energy and thermal tradeoffs in hardware-based load balancing for clustered multi-core architectures implementing power gating" explicitly lists this as a design goal of scheduling algorithms (emphasis mine):

In this work, a load-balancing technique for these clustered multi-core architectures is presented that provides both a low overhead in energy and an a smooth temperature distribution across the die, increasing the reliability of the processor by evenly stressing the cores.

Spreading the heat dissipation throughout the die is also essential for techniques such as Turbo Boost, where cores are clocked temporarily at a rate that is unsustainable long term. By moving load to a different core regularly, the average heat dissipation remains sustainable even though the instantaneous power is not.

6
  • 5
    Plus 1 for teaching me something new also today (the heating consideration). Mar 8, 2015 at 0:37
  • 2
    If I run a simple bencmark with CPU-Z and pin it to a single core the result is ~405 in my Ryzen 3500u processor. If It is not pinned, it achieves ~365. That is 10% peformance difference. I would hardly call it negligible. In Linux the scheduler will try to keep a running thread in a single core.So OSes do not tend to keep all cores at equal utilization, it is only Windows afaik. There are other disadvantages to switching cores, the next core may be in low power state then it must switch to turbo frequency etc. . Jul 30, 2019 at 21:41
  • 2
    @EvrenYurtesen: No, mechanical stress is caused by thermal expansion. If you keep a single core busy, that will be a hot spot, it's trying to expand but the silicon around it isn't expanding to make room. Derivative of temperature over location is the problem, not derivative of temperature over time (which is already limited by heat capacity... even if you instantly change power dissipation, the temperature will change smoothly vs time)
    – Ben Voigt
    Jul 30, 2019 at 21:56
  • 2
    @BenVoigt if your logic applied, then APU type processors would fail more often, moreover processors with integrated memory controllers etc. would fail more often as some parts of the silicon never gets as hot as other parts. But this is never the case. Also, I worked with many HPC systems with over 5000 cores. The programs running on those systems are always restricted to certain cores so threads can't jump around. I never heard any of those processors fail due to this either. Lastly the thermal expansion coefficient of silicon is very small. Jul 31, 2019 at 12:59
  • 2
    Also linux binded running threads to certain cores for years, exactly opposite of what Windows i sdoing. I never heard servers failing due to this either. If what you said was true, there would have been some statistics about how many processors were trashed due to Linux scheduler. More importantly, I am sure Microsoft would have gloated over this telling their OS protects hardware. But I never saw that anywhere either... Jul 31, 2019 at 13:00
1

Your process may be the only one doing a lot of work, but it is not the only thing running. There are lots of other processes that need to run occasionally. When your process gets evicted and eventually re-scheduled, the core on which it was running previously might not be available. It's better to run the waiting process immediately on a free core than to wait for the previous core to be available (and in any case its data will likely have been bumped from the caches by the other thread).

In addition, modern CPUs allow all the cores in a package to share high-level caches. See the "Smart Cache" feature in this Intel Core i5 spec sheet. You still lose the lower-level cache(s) on core switch, but those are small and will probably churn somewhat anyway if you're running more than just a small tight loop.

1
  • 1
    "It's better to run the waiting process immediately on a free core than to wait for the previous core to be available" -- this would tend to cause all the other tasks to run on other cores, never evicting the CPU-bound thread. This is a nice idea, and an explanation that I've seen elsewhere, but it's not the primary reason that a single CPU-bound thread changes core, which becomes very apparent on a system with 8 or more cores, since the chance of a waking process not finding a free core and having to use the "hot" one is extremely low.
    – Ben Voigt
    Mar 8, 2015 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.