# VirtualBox performance under FreeBSD12



## Reaperzx (Jan 29, 2019)

I upgraded my home server from *9.3* to *12.0*.

With the help of this thread I managed to fix the problem of VirtualBox crashing my server every time i run it:
https://forums.freebsd.org/threads/virtualbox-5-2-22-causes-kernel-panic-with-bridged-adapter.68787/

No more crashes. But now virtual machines are very slow, I can barely log in via remote desktop and running web browser takes ages.

This makes VirtualBox basically unusable for me. Does anyone else have performance problems?

I have tried both Windowx XP (32-bit) and Windows 7 (64-bit) guests.


```
virtualbox-ose-kmod-5.2.22_1
virtualbox-ose-nox11-5.2.22_2
```


```
# kldstat
Id Refs Address                Size Name
1   39 0xffffffff80200000  243cd00 kernel
2    1 0xffffffff8263d000     2be8 coretemp.ko
3    1 0xffffffff82641000    27f48 geom_mirror.ko
4    1 0xffffffff82669000    a6b50 linux.ko
5    4 0xffffffff82710000     8df8 linux_common.ko
6    1 0xffffffff82719000    566b8 pf.ko
7    1 0xffffffff82770000    43880 if_cxgb.ko
8    3 0xffffffff827b4000    88920 vboxdrv.ko
9    1 0xffffffff82a21000     490c linprocfs.ko
10    1 0xffffffff82a26000    33c50 linux64.ko
11    2 0xffffffff82a5a000     2cd0 vboxnetflt.ko
12    2 0xffffffff82a5d000     a020 netgraph.ko
13    1 0xffffffff82a68000     1710 ng_ether.ko
14    1 0xffffffff82a6a000     3f30 vboxnetadp.ko
```

CPU is i5-3570. I have given guest system 3 cores and 12GB RAM (4GB for Windows XP).

What is most strange is while the guest system lags, in FreeBSD host the CPU usage is close to zero.

Virtualbox used to work more or less OK on FreeBSD 9.3. I guess Virtualbox version was 5.1.12. And CPU usage used to be high under load.


----------



## SirDice (Jan 29, 2019)

What type of disk controller did you gave the VMs? That can make a world of difference.


----------



## Reaperzx (Jan 29, 2019)

Seems I havent modified my VM configuration for 4 years.

Seems I am using *ICH9 SATA Controller*:

```
<Machine uuid="{bb5ede3e-d230-4a68-b26a-ae6c2bdbb1db}" name="Windows7" OSType=
"Windows7_64" snapshotFolder="Snapshots" lastStateChange="2019-01-21T17:30:07Z"
aborted="true">
    <MediaRegistry>
      <HardDisks>
        <HardDisk uuid="{d60da95b-da30-4fda-bbe0-1b6545d64288}" location="/usr/l
ocal/share/qemu/img/Windows7.vdi" format="VDI" type="Normal"/>
      </HardDisks>
    </MediaRegistry>
    <Hardware>
      <CPU count="3">
        <PAE enabled="true"/>
        <LongMode enabled="true"/>
        <HardwareVirtExLargePages enabled="true"/>
      </CPU>
      <Memory RAMSize="12288"/>
      <Chipset type="ICH9"/>
      <BIOS>
        <IOAPIC enabled="true"/>
      </BIOS>
      <Network>
        <Adapter slot="0" enabled="true" MACAddress="0800274564A1" cable="true"type="82540EM">
          <BridgedInterface name="em0"/>
        </Adapter>
    </Hardware>
    <StorageControllers>
      <StorageController name="SATA Controller" type="AHCI" PortCount="4" useHostIOCache="false" Bootable="true" IDE0MasterEmulationPort="0" IDE0SlaveEmulationPort="1" IDE1MasterEmulationPort="2" IDE1SlaveEmulationPort="3">
        <AttachedDevice type="HardDisk" port="0" device="0">
          <Image uuid="{d60da95b-da30-4fda-bbe0-1b6545d64288}"/>
        </AttachedDevice>
      </StorageController>
    </StorageControllers>
  </Machine>
```

(Some information removed for clarity)

VDI file was put on SSD disk for acceptable performance


----------



## jpierri (Jan 29, 2019)

I was experiencing bad performance and a lot of crashes with VirtualBox 5.2.22 under FreeBSD 12.0-RELEASE-p2 on a AMD Ryzen 7 until I added this to /etc/sysctl.conf:

```
vfs.aio.max_aio_queue_per_proc=1024
vfs.aio.max_aio_per_proc=128
vfs.aio.max_aio_procs=128
vfs.aio.max_buf_aio=64
```
And I also enabled "Use Host I/O cache" with:

```
<StorageController name="SATA" type="AHCI" PortCount="2" useHostIOCache="true" Bootable="true" ...
```
Now it runs smoothly and no more crashes.

EDIT: I forgot to mention that my VDI files are on a ZPOOL.


----------



## Rhadamanthys (Jan 31, 2019)

For me what did the trick was to change de disks controllers to IDE and don't use more than one core for the processor.


----------



## Reaperzx (Feb 1, 2019)

One core is totally no-go, because Windows VM-s are quite resource hungry. Have actually considered upgrading home server to Ryzen 2700 to get more cores.

What I have done so far: updated virtualbox:

```
virtualbox-ose-kmod-5.2.26
virtualbox-ose-nox11-5.2.26_1
```

No change, as expected.

Then I recompiled Virtualbox with all dependant ports `portupgrade -rRf virtualbox-ose-nox11` - 66 of them total. That changed the virtual maxhines to somewhat usable. And I can see Virtualbox load in FreeBSD host htop as expected. I guess some library was out-of-date after system upgrade.

Something still seems to be wrong, with network. Seems kinda slow and sometimes loses connection. And when I did speedtest in VM in chrome, i got speed 8Mbit/s down, 450 Mbit/s up (I have 500/500 connection).

I have considered changing VM network card type, currently intel 82540EM. But maybe there is something wrong with the bridging...


----------

