[pve-devel] [PATCH v2] fix #2402: allow 1GB hugepages if 2MB is unavailable

Stefan Reiter s.reiter at proxmox.com
Thu Oct 10 12:18:41 CEST 2019


As reported in bug #2402, a system started with "default_hugepagesz=1G
hugepagesz=1G" does not have a /sys/kernel/mm/hugepages/hugepages-2048kB
directory.

To fix, ignore the missing directory in hugepages_mount (since it might
not be needed anyway), and correctly check if the requested hugepage
size is available in hugepages_size instead.

Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

v2: Correct error message if 1GB hugepages would be supported, but memory is not
a multiple of 1024

 PVE/QemuServer/Memory.pm | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/PVE/QemuServer/Memory.pm b/PVE/QemuServer/Memory.pm
index b579955..5aceabf 100644
--- a/PVE/QemuServer/Memory.pm
+++ b/PVE/QemuServer/Memory.pm
@@ -358,7 +358,7 @@ sub hugepages_mount {
    my $mountdata = PVE::ProcFSTools::parse_proc_mounts();
 
    foreach my $size (qw(2048 1048576)) {
-	return if (! -d "/sys/kernel/mm/hugepages/hugepages-${size}kB");
+	next if (! -d "/sys/kernel/mm/hugepages/hugepages-${size}kB");
 
 	my $path = "/run/hugepages/kvm/${size}kB";
 
@@ -398,20 +398,26 @@ sub hugepages_size {
    if ($conf->{hugepages} eq 'any') {
 
 	#try to use 1GB if available && memory size is matching
-	if (-d "/sys/kernel/mm/hugepages/hugepages-1048576kB" && ($size % 1024 == 0)) {
+	my $gb_exists = -d "/sys/kernel/mm/hugepages/hugepages-1048576kB";
+	if ($gb_exists && ($size % 1024 == 0)) {
 	    return 1024;
-	} else {
+	} elsif (-d "/sys/kernel/mm/hugepages/hugepages-2048kB") {
 	    return 2;
 	}
 
+	die "your system doesn't support hugepages for memory size $size\n"
+	    if $gb_exists;
+
+	die "your system doesn't support hugepages\n";
+
    } else {
 
 	my $hugepagesize = $conf->{hugepages} * 1024 . "kB";
 
 	if (! -d "/sys/kernel/mm/hugepages/hugepages-$hugepagesize") {
-		die "your system doesn't support hugepages of $hugepagesize";
+		die "your system doesn't support hugepages of $hugepagesize\n";
 	}
-	die "Memory size $size is not a multiple of the requested hugepages size $hugepagesize" if ($size % $conf->{hugepages}) != 0;
+	die "Memory size $size is not a multiple of the requested hugepages size $hugepagesize\n" if ($size % $conf->{hugepages}) != 0;
 	return $conf->{hugepages};
    }
 
-- 
2.20.1





More information about the pve-devel mailing list