[lxc-devel] [lxd/master] Fix total memory for per NUMA node

nicolasbock on Github lxc-bot at linuxcontainers.org
Wed Aug 5 21:09:30 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 493 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200805/23bd8ee2/attachment.bin>
-------------- next part --------------
From 15f68f5fa43cec52cac8a2b62dde712bee621402 Mon Sep 17 00:00:00 2001
From: Nicolas Bock <nicolas.bock at canonical.com>
Date: Wed, 5 Aug 2020 15:07:58 -0600
Subject: [PATCH] Fix total memory for per NUMA node

This change applies the same change as

375ce45456e9f0789a48541704014a1695896a0f

To the per NUMA node total memory calculation.

Signed-off-by: Nicolas Bock <nicolas.bock at canonical.com>
---
 lxd/resources/memory.go | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lxd/resources/memory.go b/lxd/resources/memory.go
index b948f39e3b..aa554d6096 100644
--- a/lxd/resources/memory.go
+++ b/lxd/resources/memory.go
@@ -135,8 +135,8 @@ func parseMeminfo(path string) (*meminfo, error) {
 	return &memory, nil
 }
 
-func getTotalMemory() uint64 {
-	memoryBlockSizePath := filepath.Join(sysDevicesSystemMemory, "block_size_bytes")
+func getTotalMemory(sysDevicesBase) uint64 {
+	memoryBlockSizePath := filepath.Join(sysDevicesBase, "block_size_bytes")
 
 	if !sysfsExists(memoryBlockSizePath) {
 		return 0
@@ -201,7 +201,7 @@ func GetMemory() (*api.ResourcesMemory, error) {
 	// Calculate the total memory from /sys/devices/system/memory, as the previously determined
 	// value reports the amount of available system memory minus the amount reserved for the kernel.
 	// If successful, replace the previous value, retrieved from /proc/meminfo.
-	memTotal := getTotalMemory()
+	memTotal := getTotalMemory(sysDevicesSystemMemory)
 	if memTotal > 0 {
 		info.Total = memTotal
 	}
@@ -256,6 +256,14 @@ func GetMemory() (*api.ResourcesMemory, error) {
 			node.Used = info.Used
 			node.Total = info.Total
 
+			// Calculate the total memory from /sys/devices/system/node/memory, as the previously determined
+			// value reports the amount of available system memory minus the amount reserved for the kernel.
+			// If successful, replace the previous value, retrieved from /sys/devices/system/node/meminfo.
+			memTotal := getTotalMemory(entryPath)
+			if memTotal > 0 {
+				node.Total = memTotal
+			}
+
 			memory.Nodes = append(memory.Nodes, node)
 		}
 	}


More information about the lxc-devel mailing list