[Bug 2004643] Re: additional memory management changes
Launchpad Bug Tracker
2004643 at bugs.launchpad.net
Thu Sep 28 20:49:31 UTC 2023
This bug was fixed in the package grub2-unsigned - 2.06-2ubuntu14.2
---------------
grub2-unsigned (2.06-2ubuntu14.2) kinetic; urgency=medium
* Cherry-pick more upstream memory patches (LP: #2004643)
* Source package generated from src:grub2 using make -f ./debian/rules
generate-grub2-unsigned
-- Julian Andres Klode <juliank at ubuntu.com> Mon, 20 Feb 2023 17:29:00
+0100
** Changed in: grub2-unsigned (Ubuntu Jammy)
Status: Fix Committed => Fix Released
** Changed in: grub2-signed (Ubuntu Jammy)
Status: Fix Committed => Fix Released
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to grub2-signed in Ubuntu.
https://bugs.launchpad.net/bugs/2004643
Title:
additional memory management changes
Status in grub2-signed package in Ubuntu:
Fix Released
Status in grub2-unsigned package in Ubuntu:
Fix Released
Status in grub2-signed source package in Focal:
Fix Released
Status in grub2-unsigned source package in Focal:
Fix Released
Status in grub2-signed source package in Jammy:
Fix Released
Status in grub2-unsigned source package in Jammy:
Fix Released
Status in grub2-signed source package in Kinetic:
Won't Fix
Status in grub2-unsigned source package in Kinetic:
Won't Fix
Status in grub2-signed source package in Lunar:
Fix Released
Status in grub2-unsigned source package in Lunar:
Fix Released
Bug description:
[Impact]
The 2.12 mm changes did not take into account grub's mm overhead when
requesting pages from the firmware and hence can cause out of memory
issues (i.e. we need 4 KiB, it allocates 4 KiB from the firwmare, but
then only has like 4000 byte left or something left that, because it
itself needs to store some metadata).
Also two performance improvements to those mm changes.
Full commits with more details:
commit 873be3c86c35f8c1d539b91bd5cc88a54036070a
Author: Zhang Boyang <zhangboyang.id at gmail.com>
Date: Sun Jan 29 19:49:33 2023 +0800
mm: Avoid complex heap growth math in hot path
We do a lot of math about heap growth in hot path of grub_memalign().
However, the result is only used if out of memory is encountered, which
is seldom.
This patch moves these calculations away from hot path. These
calculations are now only done if out of memory is encountered. This
change can also help compiler to optimize integer overflow checks away.
Signed-off-by: Zhang Boyang <zhangboyang.id at gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper at oracle.com>
Gbp-Pq: Topic 2.12-mm
commit ff73d7484d7f885cd1da82fe278fe607fb868b2d
Author: Zhang Boyang <zhangboyang.id at gmail.com>
Date: Sun Jan 29 19:49:32 2023 +0800
mm: Preallocate some space when adding new regions
When grub_memalign() encounters out-of-memory, it will try
grub_mm_add_region_fn() to request more memory from system firmware.
However, it doesn't preallocate memory space for future allocation
requests. In extreme cases, it requires one call to
grub_mm_add_region_fn() for each memory allocation request. This can
be very slow.
This patch introduces GRUB_MM_HEAP_GROW_EXTRA, the minimal heap growth
granularity. The new region size is now set to the bigger one of its
original value and GRUB_MM_HEAP_GROW_EXTRA. Thus, it will result in some
memory space preallocated if current allocations request is small.
The value of GRUB_MM_HEAP_GROW_EXTRA is set to 1MB. If this value is
smaller, the cost of small memory allocations will be higher. If this
value is larger, more memory will be wasted and it might cause
out-of-memory on machines with small amount of RAM.
Signed-off-by: Zhang Boyang <zhangboyang.id at gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper at oracle.com>
Gbp-Pq: Topic 2.12-mm
commit ef6115f3b411e63ce9125c60e572154024063d07
Author: Zhang Boyang <zhangboyang.id at gmail.com>
Date: Sun Jan 29 19:49:31 2023 +0800
mm: Adjust new region size to take management overhead into account
When grub_memalign() encounters out-of-memory, it will try
grub_mm_add_region_fn() to request more memory from system firmware.
However, the size passed to it doesn't take region management overhead
into account. Adding a memory area of "size" bytes may result in a heap
region of less than "size" bytes really available. Thus, the new region
may not be adequate for current allocation request, confusing
out-of-memory handling code.
This patch introduces GRUB_MM_MGMT_OVERHEAD to address the region
management overhead (e.g. metadata, padding). The value of this new
constant must be large enough to make sure grub_memalign(align, size)
always succeeds after a successful call to
grub_mm_init_region(addr, size + align + GRUB_MM_MGMT_OVERHEAD),
for any given addr and size (assuming no integer overflow).
The size passed to grub_mm_add_region_fn() is now correctly adjusted,
thus if grub_mm_add_region_fn() succeeded, current allocation request
can always succeed.
Signed-off-by: Zhang Boyang <zhangboyang.id at gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper at oracle.com>
Gbp-Pq: Topic 2.12-mm
[Test plan]
Boot a couple platforms make sure it works fine, let it rest in devel for a couple weeks until after the point release.
[where problems could occur]
It could fail to allocate memory in other ways now of course. Security issues because of overflows or stuff are always possible too. I did do some basic review though and that seemed fine.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/grub2-signed/+bug/2004643/+subscriptions
More information about the foundations-bugs
mailing list