# Bhyve and HyperThreading - is it safe to assign HT cores to a VM?



## Selin (Oct 1, 2020)

Hello

I have a 8 core CPU with HT support which gives me 16 threads.
Earlier I used VirtualBox and it says "do not assign to a VM more cores than you have physically". I.e. for my case - no more than 8 cores should be assigned to a guest(s).
Is it the same for the bhyve?
Or I can safely assign 10-12 cores to a single VM with the bhyve?

Thank you


----------



## ekvz (Oct 1, 2020)

I usually keep at least 1 thread for the host when working with virtualization (mostly qemu though) but that's it and i don't think qemu would have a problem even emulating more cores than there is threads. It'll probably just hurt performance (and possibly lag the the host) if all of them happen to get fully utilized. I guess the VirtualBox message is rather pointing to it being a bad idea (while being unclear about really reffering to threads) than it actually being unsafe.

Do really expect all those bottom of the barrel VPS providers to have even anywhere near the amount of threads they allocate as cores for their costumers? Even dedicated core in this context is practically accepted to mean thread. So i'd say 10-12 cores on a 8 core HT system should be actually pretty tame.


----------



## Phishfry (Oct 1, 2020)

I use dual LGA2011 CPU Intel/SuperMicro boards for my two virt boxes. On both I use hyperthreaded cores with no problem.
So 40 cores on one and 48 cores on the other with hyperthreading.
My philosophy is to create VM's with minimal core allotments. This is because I compile software on the host and want plenty of cores.
The one gotcha I have found is that the sysctl:hw.ncpu does not realize that the VM's have allotted cores.
ncpu will still show 40/48 cores when I have assigned cores to a VM.
So when I run build scripts the ncpu sysctl does not recognize that some cores are unavailable and tries to use them all.
`make -j $(sysctl -n hw.ncpu)`
This causes the  VM's to act sluggish as the host is trying to use all cores.
So that is the only caveat I have found. It is easy to work around.


----------



## a6h (Oct 1, 2020)

Also consider how many VM instances do you want to run simultaneously. Change the settings accordingly.
For example, generally I only have one vm running. It's FreeBSD CURRENT and often it's busy compiling (kernel, ports). In this case I allocate max resources to the this instance of vm. But there's time that I run about 3 vms simultaneously, e.g. CURRENT, STABLE, RELENG. In this situation I have to make decision how to share a limited resources (core, ram) among them.

[EDIT]: OT but performance related: using tmpfs(5) is something you have to consider.


			TMPFS - FreeBSD Wiki


----------



## Selin (Oct 3, 2020)

Thank you for your replays!
Glad to hear that I can utilize host resources efficiently with bhyve! )

And one more question - does it make sense to specify detailed CPU configuration (i.e. number of sockets, cores, threads) in case of using Windows Server on guests?
Or it will be ok just to set the number of CPUs?
I mean - is there any difference in "internal bhyve kitchen" between simple

```
cpu="12"
```
and detailed

```
cpu="12"
cpu_sockets="1"
cpu_cores="6"
cpu_threads="2"
```
_(I'm using vm-bhyve config language here)_
I mean - does it affect performance somehow, etc.?


----------



## Phishfry (Oct 3, 2020)

Selin said:


> does it affect performance somehow, etc.


Not from my perspective. I only use the -c setting for my VM's.


----------

