The other answers didn't work for me, so I'm sharing my solution which is based on VirtualBox manual §2.4 CPU Hot-Plugging.
The GUI allowed me to add 32 vCPUs, but when the Linux guest booted nproc
and cat /proc/cpuinfo
would only show a single CPU/core/thread. I could see in dmesg
that 32 vCPUs were detected:
# dmesg | grep -E 'smp:|smpboot:'
[ 0.000000] smpboot: Allowing 32 CPUs, 31 hotplug CPUs
[ 0.192151] smpboot: CPU0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (family: 0x6, model: 0x55, stepping: 0x4)
[ 0.193848] smp: Bringing up secondary CPUs ...
[ 0.193850] smp: Brought up 1 node, 1 CPU
[ 0.193852] smpboot: Max logical packages: 32
[ 0.193854] smpboot: Total of 1 processors activated (4788.97 BogoMIPS)
Seems hotplug is enabled, but the CPUs are not online for some reason.
Run the following on the host:
for i in {1..31}; do VBoxManage controlvm $VM plugcpu $i; done
From within the guest I can see the CPUs have been hotplugged, but they are not automatically put online:
# dmesg | grep 'has been hot-added'
[ 317.236099] CPU1 has been hot-added
[ 317.289383] CPU2 has been hot-added
[ 317.341704] CPU3 has been hot-added
[ 317.393434] CPU4 has been hot-added
[ 317.602969] CPU5 has been hot-added
[ 317.603570] CPU6 has been hot-added
[ 317.603810] CPU7 has been hot-added
[ 317.604031] CPU8 has been hot-added
[ 317.780191] CPU9 has been hot-added
[ 317.780498] CPU10 has been hot-added
[ 317.780745] CPU11 has been hot-added
[ 317.817875] CPU12 has been hot-added
[ 317.870629] CPU13 has been hot-added
[ 317.911276] CPU14 has been hot-added
[ 317.962533] CPU15 has been hot-added
[ 318.012838] CPU16 has been hot-added
[ 318.063693] CPU17 has been hot-added
[ 318.116346] CPU18 has been hot-added
[ 318.167847] CPU19 has been hot-added
[ 318.232230] CPU20 has been hot-added
[ 318.284266] CPU21 has been hot-added
[ 318.344941] CPU22 has been hot-added
[ 318.373422] CPU23 has been hot-added
[ 318.501419] CPU24 has been hot-added
[ 318.501714] CPU25 has been hot-added
[ 318.535717] CPU26 has been hot-added
[ 318.652636] CPU27 has been hot-added
[ 318.653046] CPU28 has been hot-added
[ 318.689386] CPU29 has been hot-added
[ 318.739736] CPU30 has been hot-added
[ 318.790743] CPU31 has been hot-added
# nproc
6
But you can bring the CPUs online manually from within the guest by running:
# for CPU in /sys/devices/system/cpu/cpu*/online; do echo 1 | sudo tee $CPU >/dev/null; done
Healthy:
# nproc
32
This appear to persist when the guest is rebooted:
# dmesg | grep -E 'smp:|smpboot:'
[ 0.000000] smpboot: Allowing 32 CPUs, 0 hotplug CPUs
[ 0.189487] smpboot: CPU0: Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz (family: 0x6, model: 0x55, stepping: 0x4)
[ 0.191502] smp: Bringing up secondary CPUs ...
[ 0.278723] smp: Brought up 1 node, 32 CPUs
[ 0.278723] smpboot: Max logical packages: 1
[ 0.278723] smpboot: Total of 32 processors activated (153236.67 BogoMIPS)