Add VM_DISCARD_PAGES and the vm_discard_pages() libvmmapi wrapper to
reclaim backing for disposable guest RAM, such as ballooned pages.
Implement the ioctl in shared VMM code and define it in the amd64 and
arm64 machine-dependent ioctl headers, adding it to their libvmmapi
Capsicum allowlists. Shared code and the wrapper are built only where
the ioctl is defined.
Accept page-aligned ranges of at most 256 host pages within one
system-memory mapping. Reject wired or IOMMU mappings and overlapping
guest aliases of the same object offsets.
Hold the memory-segment shared lock to keep mappings stable and use
vm_object_page_remove() under the object write lock to discard pages
and swap backing. Existing pmap code handles nested translation
invalidation on amd64 and arm64.
Existing interfaces cannot do this from userspace. Guest system memory
is an OBJT_SWAP object mapped by both the guest vmspace and bhyve.
MADV_FREE ignores it because it applies only to anonymous objects with
a single mapping, MADV_DONTNEED only deactivates pages and updates the
caller's pmap rather than the guest's, and msync(2) with MS_INVALIDATE
only removes pages from vnode and device objects.
Reclamation is best-effort: host page holds may prevent freeing pages,
and concurrent accesses may repopulate the range. The caller must ensure
that the memory is disposable and no device is using it.
Sponsored by: The FreeBSD Foundation