diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index 74f244e0a..bdf338a9d 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -206,7 +206,17 @@ def _write_whole_disk_image(image, image_info, device): # TODO(dtantsur): switch to disk_utils.convert_image when it supports # -t and -W flags and defaults to 2 GiB memory limit. limits = processutils.ProcessLimits(address_space=2048 * units.Mi) - utils.execute(*command, prlimit=limits) + # TODO(TheJulia): qemu-img uses a default of 8 * nCPU to determine + # how many chunks of memory to allocate based upon the discussion in + # https://bugzilla.redhat.com/show_bug.cgi?id=1892773. + # Setting MALLOC_AREA_MAX=1 results in a process memory footprint of + # ~250mb. Setting it to 3 will allow for multiple areas, but won't + # greatly exceed the footprint. + env_vars = {'MALLOC_ARENA_MAX': '3'} + # Entirely disabling threading results in the same memory footprint + # as 1 areana, but multiple threads are useful for performance + # as the file could be fragmented/compressed. + utils.execute(*command, prlimit=limits, env_variables=env_vars) except processutils.ProcessExecutionError as e: raise errors.ImageWriteError(device, e.exit_code, e.stdout, e.stderr) diff --git a/ironic_python_agent/tests/unit/extensions/test_standby.py b/ironic_python_agent/tests/unit/extensions/test_standby.py index 6f905a36a..e75000275 100644 --- a/ironic_python_agent/tests/unit/extensions/test_standby.py +++ b/ironic_python_agent/tests/unit/extensions/test_standby.py @@ -182,7 +182,9 @@ class TestStandbyExtension(base.IronicAgentTest): standby._write_image(image_info, device) - execute_mock.assert_called_once_with(*command, prlimit=mock.ANY) + execute_mock.assert_called_once_with( + *command, prlimit=mock.ANY, + env_variables={'MALLOC_ARENA_MAX': '3'}) wipe_mock.assert_called_once_with(device, '') udev_mock.assert_called_once_with() rescan_mock.assert_called_once_with(device) diff --git a/releasenotes/notes/limit-qemu-img-malloc-arena-025ed84115481eae.yaml b/releasenotes/notes/limit-qemu-img-malloc-arena-025ed84115481eae.yaml new file mode 100644 index 000000000..38ddf24ea --- /dev/null +++ b/releasenotes/notes/limit-qemu-img-malloc-arena-025ed84115481eae.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes failures with disk image conversions which result in memory + allocation or input/output errors due to memory limitations by limiting + the number of available memory allocation pools to a non-dynamic + reasonable number which should not exceed the available system memory.