From 4b9eec50fe2c23343b1672eaff4373cb978afbc6 Mon Sep 17 00:00:00 2001 From: Dario Faggioli Date: Fri, 28 Jun 2013 16:32:52 +0200 Subject: [PATCH] libxl: implement per NUMA node free memory reporting By providing the implementation of nodeGetCellsFreeMemory for the driver. This is all just a matter of properly formatting, in a way that libvirt like, what Xen provides via libxl_get_numainfo(). [raistlin@Zhaman ~]$ sudo virsh --connect xen:/// freecell --all 0: 25004 KiB 1: 105848 KiB -------------------- Total: 130852 KiB Signed-off-by: Dario Faggioli --- src/libxl/libxl_driver.c | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 9f52394b49..a3a917192f 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4097,6 +4097,51 @@ libxlNodeGetFreeMemory(virConnectPtr conn) return phy_info.free_pages * ver_info->pagesize; } +static int +libxlNodeGetCellsFreeMemory(virConnectPtr conn, + unsigned long long *freeMems, + int startCell, + int maxCells) +{ + int n, lastCell, numCells; + int ret = -1, nr_nodes = 0; + libxl_numainfo *numa_info = NULL; + libxlDriverPrivatePtr driver = conn->privateData; + + if (virNodeGetCellsFreeMemoryEnsureACL(conn) < 0) + return -1; + + /* Early failure is probably worth just a warning */ + numa_info = libxl_get_numainfo(driver->ctx, &nr_nodes); + if (numa_info == NULL || nr_nodes == 0) { + VIR_WARN("libxl_get_numainfo failed to retrieve NUMA data"); + return 0; + } + + /* Check/sanitize the cell range */ + if (startCell > nr_nodes) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("start cell %d out of range (0-%d)"), + startCell, nr_nodes); + goto cleanup; + } + lastCell = startCell + maxCells - 1; + if (lastCell > nr_nodes) + lastCell = nr_nodes; + + for (numCells = 0, n = startCell; n <= lastCell; n++) { + if (numa_info[n].size == LIBXL_NUMAINFO_INVALID_ENTRY) + freeMems[numCells++] = 0; + else + freeMems[numCells++] = numa_info[n].free; + } + ret = numCells; + +cleanup: + libxl_numainfo_list_free(numa_info, nr_nodes); + return ret; +} + static int libxlConnectDomainEventRegister(virConnectPtr conn, virConnectDomainEventCallback callback, void *opaque, @@ -4683,6 +4728,7 @@ static virDriver libxlDriver = { .domainSetSchedulerParameters = libxlDomainSetSchedulerParameters, /* 0.9.0 */ .domainSetSchedulerParametersFlags = libxlDomainSetSchedulerParametersFlags, /* 0.9.2 */ .nodeGetFreeMemory = libxlNodeGetFreeMemory, /* 0.9.0 */ + .nodeGetCellsFreeMemory = libxlNodeGetCellsFreeMemory, /* 1.1.1 */ .connectDomainEventRegister = libxlConnectDomainEventRegister, /* 0.9.0 */ .connectDomainEventDeregister = libxlConnectDomainEventDeregister, /* 0.9.0 */ .domainManagedSave = libxlDomainManagedSave, /* 0.9.2 */ -- GitLab