From af9130e5a42a78ccdf34bd90f2b8b242d8282128 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 14 Sep 2023 11:38:17 -0700 Subject: [PATCH] boot-qemu.py: Allow memory value to be customized The default memory value for most machines is 512 MB, which is generally sufficient for most use cases, as these machines are usually quick to start up and shutdown. Unfortunately, there are times where the machine may run out of memory when percpu memory allocations are involved along with a large number of cores, which can happen when booting under KVM due to the script's heuristics for selecting a good default for '-smp', which depends on the number of cores on the host machine. Rather than try to adjust the existing heuristics further, allow users to specify a memory value that may be better suited for their machine, just like '-smp'. Signed-off-by: Nathan Chancellor --- boot-qemu.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/boot-qemu.py b/boot-qemu.py index 129eb4a..28b717b 100755 --- a/boot-qemu.py +++ b/boot-qemu.py @@ -49,6 +49,7 @@ def __init__(self): self.interactive = False self.kernel = None self.kernel_dir = None + self.memory = '512m' self.supports_efi = False # It may be tempting to use self.use_kvm during initialization of # subclasses to set certain properties but the user can explicitly opt @@ -70,7 +71,6 @@ def __init__(self): '-nodefaults', ] # yapf: disable self._qemu_path = None - self._ram = '512m' def _find_dtb(self): if not self._dtbs: @@ -301,7 +301,7 @@ def run(self): self._qemu_args += ['-cpu', ','.join(self._kvm_cpu), '-enable-kvm'] # Machine specs - self._qemu_args += ['-m', self._ram] + self._qemu_args += ['-m', self.memory] if self.smp: self._qemu_args += ['-smp', str(self.smp)] @@ -512,7 +512,7 @@ def __init__(self): '-bios', bios, '-no-reboot', ] # yapf: disable - self._ram = '2G' + self.memory = '2G' self.smp = 2 @@ -555,12 +555,12 @@ def __init__(self): super().__init__() self.cmdline.append('console=ttyS0') + self.memory = '128m' self._default_kernel_path = Path('arch/powerpc/boot/uImage') self._initrd_arch = 'ppc32' self._machine = 'bamboo' self._qemu_arch = 'ppc' self._qemu_args.append('-no-reboot') - self._ram = '128m' def run(self): self._qemu_args += ['-machine', self._machine] @@ -582,6 +582,7 @@ class PowerPC64QEMURunner(QEMURunner): def __init__(self): super().__init__() + self.memory = '1G' self._default_kernel_path = Path('vmlinux') self._initrd_arch = self._qemu_arch = 'ppc64' self._qemu_args += [ @@ -589,7 +590,6 @@ def __init__(self): '-machine', 'pseries', '-vga', 'none', ] # yapf: disable - self._ram = '1G' class PowerPC64LEQEMURunner(QEMURunner): @@ -597,6 +597,7 @@ class PowerPC64LEQEMURunner(QEMURunner): def __init__(self): super().__init__() + self.memory = '2G' self._default_kernel_path = Path('arch/powerpc/boot/zImage.epapr') self._initrd_arch = 'ppc64le' self._qemu_arch = 'ppc64' @@ -605,7 +606,6 @@ def __init__(self): '-device', 'isa-ipmi-bt,bmc=bmc0,irq=10', '-machine', 'powernv', ] # yapf: disable - self._ram = '2G' class RISCVQEMURunner(QEMURunner): @@ -811,6 +811,12 @@ def parse_arguments(): '--shell', action='store_true', help='Instead of immediately shutting down machine, spawn a shell.') + parser.add_argument( + '-m', + '--memory', + help= + "Value for '-m' QEMU option (default: generally '512m', depends on machine)", + ) parser.add_argument( '-s', '--smp', @@ -884,6 +890,9 @@ def parse_arguments(): if args.gh_json_file: runner.gh_json_file = Path(args.gh_json_file).resolve() + if args.memory: + runner.memory = args.memory + if args.no_kvm: runner.use_kvm = False