mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
numa: Introduce virNumaGetNodeMemory and use it instead of numa_node_size64
This commit is contained in:
parent
f72cfea1ab
commit
9dd02965a5
@ -1524,6 +1524,7 @@ virDomainNumatuneMemModeTypeFromString;
|
|||||||
virDomainNumatuneMemModeTypeToString;
|
virDomainNumatuneMemModeTypeToString;
|
||||||
virNumaGetAutoPlacementAdvice;
|
virNumaGetAutoPlacementAdvice;
|
||||||
virNumaGetMaxNode;
|
virNumaGetMaxNode;
|
||||||
|
virNumaGetNodeMemory;
|
||||||
virNumaIsAvailable;
|
virNumaIsAvailable;
|
||||||
virNumaSetupMemoryPolicy;
|
virNumaSetupMemoryPolicy;
|
||||||
virNumaTuneMemPlacementModeTypeFromString;
|
virNumaTuneMemPlacementModeTypeFromString;
|
||||||
|
@ -1680,6 +1680,7 @@ nodeGetCellsFreeMemory(unsigned long long *freeMems,
|
|||||||
int startCell,
|
int startCell,
|
||||||
int maxCells)
|
int maxCells)
|
||||||
{
|
{
|
||||||
|
unsigned long long mem;
|
||||||
int n, lastCell, numCells;
|
int n, lastCell, numCells;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int maxCell;
|
int maxCell;
|
||||||
@ -1702,9 +1703,7 @@ nodeGetCellsFreeMemory(unsigned long long *freeMems,
|
|||||||
lastCell = maxCell;
|
lastCell = maxCell;
|
||||||
|
|
||||||
for (numCells = 0, n = startCell; n <= lastCell; n++) {
|
for (numCells = 0, n = startCell; n <= lastCell; n++) {
|
||||||
long long mem;
|
virNumaGetNodeMemory(n, NULL, &mem);
|
||||||
if (numa_node_size64(n, &mem) < 0)
|
|
||||||
mem = 0;
|
|
||||||
|
|
||||||
freeMems[numCells++] = mem;
|
freeMems[numCells++] = mem;
|
||||||
}
|
}
|
||||||
@ -1717,6 +1716,7 @@ cleanup:
|
|||||||
unsigned long long
|
unsigned long long
|
||||||
nodeGetFreeMemory(void)
|
nodeGetFreeMemory(void)
|
||||||
{
|
{
|
||||||
|
unsigned long long mem;
|
||||||
unsigned long long freeMem = 0;
|
unsigned long long freeMem = 0;
|
||||||
int max_node;
|
int max_node;
|
||||||
int n;
|
int n;
|
||||||
@ -1728,9 +1728,7 @@ nodeGetFreeMemory(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (n = 0; n <= max_node; n++) {
|
for (n = 0; n <= max_node; n++) {
|
||||||
long long mem;
|
virNumaGetNodeMemory(n, NULL, &mem);
|
||||||
if (numa_node_size64(n, &mem) < 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
freeMem += mem;
|
freeMem += mem;
|
||||||
}
|
}
|
||||||
@ -1742,21 +1740,19 @@ nodeGetFreeMemory(void)
|
|||||||
* nodeGetCellMemory
|
* nodeGetCellMemory
|
||||||
* @cell: The number of the numa cell to get memory info for.
|
* @cell: The number of the numa cell to get memory info for.
|
||||||
*
|
*
|
||||||
* Will call the numa_node_size64() function from libnuma to get
|
* Request size of memory in a NUMA node.
|
||||||
* the amount of total memory in bytes. It is then converted to
|
|
||||||
* KiB and returned.
|
|
||||||
*
|
*
|
||||||
* Returns 0 if unavailable, amount of memory in KiB on success.
|
* Returns 0 if unavailable, amount of memory in KiB on success.
|
||||||
*/
|
*/
|
||||||
static unsigned long long nodeGetCellMemory(int cell)
|
static unsigned long long nodeGetCellMemory(int cell)
|
||||||
{
|
{
|
||||||
long long mem;
|
unsigned long long mem;
|
||||||
unsigned long long memKiB = 0;
|
unsigned long long memKiB = 0;
|
||||||
int maxCell;
|
int maxCell;
|
||||||
|
|
||||||
/* Make sure the provided cell number is valid. */
|
/* Make sure the provided cell number is valid. */
|
||||||
if ((maxCell = virNumaGetMaxNode()) < 0)
|
if ((maxCell = virNumaGetMaxNode()) < 0)
|
||||||
return 0;
|
goto cleanup;
|
||||||
|
|
||||||
if (cell > maxCell) {
|
if (cell > maxCell) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -1766,8 +1762,7 @@ static unsigned long long nodeGetCellMemory(int cell)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the amount of memory(bytes) in the node */
|
/* Get the amount of memory(bytes) in the node */
|
||||||
mem = numa_node_size64(cell, NULL);
|
if (virNumaGetNodeMemory(cell, &mem, NULL) < 0) {
|
||||||
if (mem < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to query NUMA total memory for node: %d"),
|
_("Failed to query NUMA total memory for node: %d"),
|
||||||
cell);
|
cell);
|
||||||
|
@ -202,6 +202,45 @@ virNumaGetMaxNode(void)
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNumaGetNodeMemorySize:
|
||||||
|
* @node: identifier of the requested NUMA node
|
||||||
|
* @memsize: returns the total size of memory in the NUMA node
|
||||||
|
* @memfree: returns the total free memory in a NUMA node
|
||||||
|
*
|
||||||
|
* Returns the size of the memory in one NUMA node in bytes via the @size
|
||||||
|
* argument and free memory of a node in the @free argument. The caller has to
|
||||||
|
* guarantee that @node is in range (see virNumaGetMaxNode).
|
||||||
|
*
|
||||||
|
* Returns 0 on success, -1 on error. Does not report errors.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
virNumaGetNodeMemory(int node,
|
||||||
|
unsigned long long *memsize,
|
||||||
|
unsigned long long *memfree)
|
||||||
|
{
|
||||||
|
long long node_size;
|
||||||
|
long long node_free;
|
||||||
|
|
||||||
|
if (memsize)
|
||||||
|
*memsize = 0;
|
||||||
|
|
||||||
|
if (memfree)
|
||||||
|
*memfree = 0;
|
||||||
|
|
||||||
|
if ((node_size = numa_node_size64(node, &node_free)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (memsize)
|
||||||
|
*memsize = node_size;
|
||||||
|
|
||||||
|
if (memfree)
|
||||||
|
*memfree = node_free;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
int
|
int
|
||||||
virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
||||||
@ -232,4 +271,20 @@ virNumaGetMaxNode(void)
|
|||||||
_("NUMA isn't available on this host"));
|
_("NUMA isn't available on this host"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
virNumaGetNodeMemory(int node ATTRIBUTE_UNUSED,
|
||||||
|
unsigned long long *memsize,
|
||||||
|
unsigned long long *memfree)
|
||||||
|
{
|
||||||
|
if (memsize)
|
||||||
|
*memsize = 0;
|
||||||
|
|
||||||
|
if (memfree)
|
||||||
|
*memfree = 0;
|
||||||
|
|
||||||
|
VIR_DEBUG("NUMA isn't available on this host");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,5 +58,8 @@ int virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
|
|||||||
|
|
||||||
bool virNumaIsAvailable(void);
|
bool virNumaIsAvailable(void);
|
||||||
int virNumaGetMaxNode(void);
|
int virNumaGetMaxNode(void);
|
||||||
|
int virNumaGetNodeMemory(int node,
|
||||||
|
unsigned long long *memsize,
|
||||||
|
unsigned long long *memfree);
|
||||||
|
|
||||||
#endif /* __VIR_NUMA_H__ */
|
#endif /* __VIR_NUMA_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user