HomeFreeBSD

vmm: Allocate vCPUs on first use of a vCPU.

Description

vmm: Allocate vCPUs on first use of a vCPU.

Convert the vcpu[] array in struct vm to an array of pointers and
allocate vCPUs on first use. This avoids always allocating VM_MAXCPU
vCPUs for each VM, but instead only allocates the vCPUs in use. A new
per-VM sx lock is added to serialize attempts to allocate vCPUs on
first use. However, a given vCPU is never freed while the VM is
active, so the pointer is read via an unlocked read first to avoid the
need for the lock in the common case once the vCPU has been created.

Some ioctls need to lock all vCPUs. To prevent races with ioctls that
want to allocate a new vCPU, these ioctls also lock the sx lock that
protects vCPU creation.

Reviewed by: corvink, markj
Differential Revision: https://reviews.freebsd.org/D37174

Details

Provenance
jhbAuthored on Nov 18 2022, 6:05 PM
Reviewer
corvink
Differential Revision
D37174: vmm: Allocate vCPUs on first use of a vCPU.
Parents
rGc0f35dbf19c3: vmm: Use a cpuset_t for vCPUs waiting for STARTUP IPIs.
Branches
Unknown
Tags
Unknown