virhostmem: Let caller pass max NUMA node to virHostMemGetFreePages

In all three cases (LXC, QEMU and VBox drivers) the caller has
access to host capabilities and thus know the maximum NUMA node.
This means, that virHostMemGetFreePages() doesn't have to query
it. Querying may fail if libvirt was compiled without numactl
support.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Michal Privoznik 2021-08-19 15:53:39 +02:00
parent 20816cbda5
commit 59e3584f71
5 changed files with 35 additions and 8 deletions

View File

@ -5013,12 +5013,22 @@ lxcNodeGetFreePages(virConnectPtr conn,
unsigned long long *counts,
unsigned int flags)
{
virLXCDriver *driver = conn->privateData;
g_autoptr(virCaps) caps = NULL;
int lastCell;
virCheckFlags(0, -1);
if (virNodeGetFreePagesEnsureACL(conn) < 0)
return -1;
return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts);
if (!(caps = virLXCDriverGetCapabilities(driver, false)))
return -1;
lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa);
return virHostMemGetFreePages(npages, pages, startCell, cellCount,
lastCell, counts);
}

View File

@ -17428,12 +17428,22 @@ qemuNodeGetFreePages(virConnectPtr conn,
unsigned long long *counts,
unsigned int flags)
{
virQEMUDriver *driver = conn->privateData;
g_autoptr(virCaps) caps = NULL;
int lastCell;
virCheckFlags(0, -1);
if (virNodeGetFreePagesEnsureACL(conn) < 0)
return -1;
return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts);
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
return -1;
lastCell = virCapabilitiesHostNUMAGetMaxNode(caps->host.numa);
return virHostMemGetFreePages(npages, pages, startCell, cellCount,
lastCell, counts);
}

View File

@ -843,14 +843,12 @@ virHostMemGetFreePages(unsigned int npages,
unsigned int *pages,
int startCell,
unsigned int cellCount,
int lastCell,
unsigned long long *counts)
{
int cell, lastCell;
int cell;
size_t i, ncounts = 0;
if ((lastCell = virNumaGetMaxNode()) < 0)
return 0;
if (startCell > lastCell) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("start cell %d out of range (0-%d)"),

View File

@ -45,6 +45,7 @@ int virHostMemGetFreePages(unsigned int npages,
unsigned int *pages,
int startCell,
unsigned int cellCount,
int lastCell,
unsigned long long *counts);
int virHostMemAllocPages(unsigned int npages,

View File

@ -7598,7 +7598,7 @@ vboxNodeGetFreeMemory(virConnectPtr conn G_GNUC_UNUSED)
}
static int
vboxNodeGetFreePages(virConnectPtr conn G_GNUC_UNUSED,
vboxNodeGetFreePages(virConnectPtr conn,
unsigned int npages,
unsigned int *pages,
int startCell,
@ -7606,9 +7606,17 @@ vboxNodeGetFreePages(virConnectPtr conn G_GNUC_UNUSED,
unsigned long long *counts,
unsigned int flags)
{
struct _vboxDriver *driver = conn->privateData;
int lastCell;
virCheckFlags(0, -1);
return virHostMemGetFreePages(npages, pages, startCell, cellCount, counts);
virObjectLock(driver);
lastCell = virCapabilitiesHostNUMAGetMaxNode(driver->caps->host.numa);
virObjectUnlock(driver);
return virHostMemGetFreePages(npages, pages, startCell,
cellCount, lastCell, counts);
}
static int