I had the need to setup a new VM for software testing today, and I kept running into intermittent problems where VirtualBox would freeze and then an OS X kernel panic, freezing/crashing the entire machine.

Luckily, I had made a snapshot in the OS moments earlier to the crash so I had a safe place to revert to, but the crashes kept happing at seemingly random times.

I setup a looped execution of 'dmesg' to see what was going on just before the crash and saw this at the next freeze:

VBoxDrv: host_vmxon -> vmx_use_count=1 rc=0VBoxDrv: host_vmxoff -> vmx_use_count=0VBoxDrv: host_vmxon -> vmx_use_count=1 rc=0aio_queue_async_request(): too many in flight for proc: 16.aio_queue_async_request(): too many in flight for proc: 16.aio_queue_async_request(): too many in flight for proc: 16.aio_queue_async_request(): too many in flight for proc: 16.aio_queue_async_request(): too many in flight for proc: 16.aio_queue_async_request(): too many in flight for proc: 16.

It would appear that the default limits for the OS X kernel's asynchronous I/O are very, very low. VirtualBox likely exceeds them when your VM(s) are performing heavy disk I/O, hence the 'too many in flight' message in the logs.

Luckily for us, there's a quick and easy solution:

sudo sysctl -w kern.aiomax=512 kern.aioprocmax=128 kern.aiothreads=16

then restart VirtualBox. These settings will apply until you reboot. To make the changes permanent, add/update the following lines in /etc/sysctl.conf:

kern.aiomax=512kern.aioprocmax=128kern.aiothreads=16

Note: you can probably set those limits even higher, as documentation for Sybase (by SAP) recommends values 2048 / 1024 / 16 when using its software.