From 2f18c84dc76563cb0ef50b5a9aaef8f63a0f8abf Mon Sep 17 00:00:00 2001 From: Tim Marx Date: Tue, 14 Jan 2020 14:30:36 +0100 Subject: [PATCH] add new helper to calculate timeout based on vm config Signed-off-by: Tim Marx --- PVE/QemuServer.pm | 4 ++-- PVE/QemuServer/Helpers.pm | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 5835e9a..0f8fe96 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -41,7 +41,7 @@ use PVE::Tools qw(run_command lock_file lock_file_full file_read_firstline file_ use PVE::QMPClient; use PVE::QemuConfig; -use PVE::QemuServer::Helpers qw(min_version); +use PVE::QemuServer::Helpers qw(min_version config_aware_timeout); use PVE::QemuServer::Cloudinit; use PVE::QemuServer::Machine; use PVE::QemuServer::Memory; @@ -5541,7 +5541,7 @@ sub vm_start { my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits} : $defaults->{cpuunits}; - my $start_timeout = ($conf->{hugepages} || $is_suspended) ? 300 : 30; + my $start_timeout = config_aware_timeout($conf, $is_suspended); my %run_params = ( timeout => $statefile ? undef : $start_timeout, umask => 0077, diff --git a/PVE/QemuServer/Helpers.pm b/PVE/QemuServer/Helpers.pm index fcc9392..68325b7 100644 --- a/PVE/QemuServer/Helpers.pm +++ b/PVE/QemuServer/Helpers.pm @@ -11,6 +11,7 @@ use PVE::ProcFSTools; use base 'Exporter'; our @EXPORT_OK = qw( min_version +config_aware_timeout ); my $nodename = PVE::INotify::nodename(); @@ -139,4 +140,25 @@ sub version_cmp { return 0; } +sub config_aware_timeout { + my ($config, $is_suspended) = @_; + my $memory = $config->{memory}; + my $timeout = 30; + + # Based on user reported startup time for vm with 512GiB @ 4-5 minutes + if (defined($memory) && $memory > 30720) { + $timeout = int($memory/1024); + } + + if ($is_suspended && $timeout < 300) { + $timeout = 300; + } + + if ($config->{hugepages} && $timeout < 150) { + $timeout = 150; + } + + return $timeout; +} + 1; -- 2.39.2