[lxc-devel] [lxd/master] lxd/util: Detect hugetlbfs mount point
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Jun 29 03:22:46 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200628/e6e09183/attachment.bin>
-------------- next part --------------
From 571caeb86d7b4aabee84ebc1fb83e610b4e07031 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sun, 28 Jun 2020 23:22:13 -0400
Subject: [PATCH] lxd/util: Detect hugetlbfs mount point
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #7593
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/instance/drivers/driver_qemu.go | 8 ++++++-
lxd/util/kernel.go | 35 +++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 471100f64a..7617db6da1 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -775,7 +775,13 @@ func (vm *qemu) Start(stateful bool) error {
}
if shared.IsTrue(vm.expandedConfig["limits.memory.hugepages"]) {
- qemuCmd = append(qemuCmd, "-mem-path", "/dev/hugepages/", "-mem-prealloc")
+ hugetlb, err := util.HugepagesPath()
+ if err != nil {
+ op.Done(err)
+ return err
+ }
+
+ qemuCmd = append(qemuCmd, "-mem-path", hugetlb, "-mem-prealloc")
}
if vm.expandedConfig["raw.qemu"] != "" {
diff --git a/lxd/util/kernel.go b/lxd/util/kernel.go
index 0272dd101e..4019477af7 100644
--- a/lxd/util/kernel.go
+++ b/lxd/util/kernel.go
@@ -42,3 +42,38 @@ func HasFilesystem(filesystem string) bool {
return false
}
+
+// HugepagesPath attempts to locate the mount point of the hugepages filesystem.
+func HugepagesPath() (string, error) {
+ // Find the source mount of the path
+ file, err := os.Open("/proc/mounts")
+ if err != nil {
+ return "", err
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ matches := []string{}
+ for scanner.Scan() {
+ line := scanner.Text()
+ cols := strings.Fields(line)
+
+ if cols[2] == "hugetlbfs" {
+ matches = append(matches, cols[1])
+ }
+ }
+
+ if len(matches) == 0 {
+ return "", fmt.Errorf("No hugetlbfs mount found, can't use hugepages")
+ }
+
+ if len(matches) > 1 {
+ if shared.StringInSlice("/dev/hugepages", matches) {
+ return "/dev/hugepages", nil
+ }
+
+ return "", fmt.Errorf("More than one hugetlbfs instance found and none at standard /dev/hugepages")
+ }
+
+ return matches[0], nil
+}
More information about the lxc-devel
mailing list