
Ask HN: Why can't OS have dedicated cores and memory? - uptownhr
Have you ever experience your mouse and keyboard input start to lag?<p>Why is it that you are not able to dedicate a core or a thread to your OS so, third party apps do not have access to them? This can prevent your entire OS from locking and your entire experience being jerky.
======
detaro
There are a lot of issues where dedicated cores don't help - e.g. locking
issues (see the discussion today about windows and chromium builds)

~~~
twobyfour
Would you mind explaining what some of these cases are and why it doesn't work
that way, please? (Sorry for what might be a fairly elementary question.)

~~~
actuallyalys
I'm not detaro, but I'll take a crack. It's kind of like traffic—if you're
constantly stopping for other cars, it doesn't really help to have a faster
car. If the UI thread is waiting for something else to happen, having an
entire core dedicated to the UI just means that entire core is waiting. In the
case detaro was alluding to, compiling Chrome was creating so many processes,
the UI had to wait for the kernel to shut down processes before it could do
what the UI needed it to do. [0]

Adit has some good posts on concurrency:

—[http://adit.io/posts/2013-05-11-The-Dining-Philosophers-
Prob...](http://adit.io/posts/2013-05-11-The-Dining-Philosophers-Problem-With-
Ron-Swanson.html)

—[http://adit.io/posts/2013-05-15-Locks,-Actors,-And-STM-In-
Pi...](http://adit.io/posts/2013-05-15-Locks,-Actors,-And-STM-In-
Pictures.html).

[0]: [https://randomascii.wordpress.com/2017/07/09/24-core-cpu-
and...](https://randomascii.wordpress.com/2017/07/09/24-core-cpu-and-i-cant-
move-my-mouse/)

------
davelnewton
You can, at least in Linux. But in general the OS will do a better scheduling
job than you will.

~~~
kpil
Maybe more efficient, but the default settings put my actions in the same
queue as everything else.

This can be rather annoying, especially if the machine is low on memory or
swapping to death.

As a matter of design principle for a desktop machine, it should prioritize
everything that I do.

That includes not stealing the keyboard focus when I'm typing, up to the point
of rolling back any popups that opened just before I started to type.

~~~
jldugger
Well, lets just say that there's a variety of levels a desktop environment,
and not all of them are immediately obvious to the OS or hardware layers.

The linux kernel is designed to be generic enough to work on wifi routers,
phones, laptops, and massive compute clusters. There's some thing you can do,
but there's going to be a class of optimizations any general purpose OS must
give up on. For example, Windows NT runs a lot of window manager stuff in
kernel space
([https://en.wikipedia.org/wiki/Architecture_of_Windows_NT](https://en.wikipedia.org/wiki/Architecture_of_Windows_NT)).
Once you pull that in, the scheduler will have a richer dataset work with. But
it kinda makes 32MB routers and headless servers less viable. Even Server Core
still has a window manager!

------
LoSboccacc
Mostly because the os needs to coordinate everything and not all operations
can be interrupted. Operating system maintain each program illusion to be
alone on the hardware, virtualizing disk transfers, memory mappings, display
regions and all the other hardware. Some operations once queued and dispatched
need to complete before other operations can be accepted - that might happen
for example when the os is figthing to access a memory page from disk but the
disk is busy in a large dma transfer - then the illusion of being alone comes
crashing down and no clever scheduling can fix it, because a class of
operations without a guaranteed time constraint exist on the ibm pc platform.

Without a hard real time guarantee from the hardware, everything built on it
cannot provide a guarantee on dispatching only the exact amount of operations
that the system can handle.

And that happens even before accounting that the os or some driver within may
have some cpu locking going on.

------
LinuxBender
This isn't specific to your question, but I have VM's that have 6 logical
processors. I use taskset to set the affinity of all OS processes to logical
proccesor 0. This doesn't work for some kernel threads, but it works for most
processes. I then give haproxy a number of logical processors, or balance
based on what is running on that VM.

On physical hardware I would use NUMA regions per set of applications as well
to optimize the use of CPU cache and get lower latency to memory, but the
overall memory availability will be reduced. This is done on some latency
sensitive applications.

You can do similar things in Windows. There is probably a way in Mac, but I
have never tried.

As others pointed out, there are many cases where doing all of this won't
help, so it really depends on the problem you are trying to solve, or the
optimization you wish to accomplish. There are certainly no one-size-fits-all
solutions.

------
rb808
[https://en.wikipedia.org/wiki/Processor_affinity](https://en.wikipedia.org/wiki/Processor_affinity)

In my experience we used affinity with older CPUs to improve single thread
performance. Recently it doesn't make much difference.

------
uptownhr
Feels like there isn't a solution using current OSes.

Why does CPU locking exist? I'm sure this is pretty technical question but if
anyone has a dumb answer for me... Is this something impossible get rid of?
Can it be scoped to a core and not the entire CPU?

------
zamalek
iOS supposedly runs the UI thread at maximum priority on phones, which is
similar to what you are suggesting here.

