grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 19/19] RFC: Ignore REGION_CONSECUTIVE


From: Daniel Axtens
Subject: [PATCH 19/19] RFC: Ignore REGION_CONSECUTIVE
Date: Tue, 12 Oct 2021 18:30:08 +1100

Looking into the region merging stuff, I started to wonder if we actually
want to just try adding as much memory as we can (up to the limit requested),
even if we cannot satisfy the full allocation (i.e. we are not CONSECUTIVE).

On powerpc-ieee1275 this actually allows me to satisfy bigger allocations:
while the FW cannot necessarily satisfy e.g. a 128MB allocation, it can
satisfy e.g. a 32MB allocation, and that might merge with a region that's
100MB, and then we can satisfy our 128MB allocation.

The way the call out to firmware operates in mm.c is that it preceeds a
'goto again;' - it kicks off a whole new round of attempting to satisfy
allocation. mm.c doesn't fill the allocation only from the new memory from
firmware.

Perhaps an even better approach would be for the mm.c code to try going to
firmware twice - once for the precise size of the allocation (rounded up etc)
and then if that doesn't succeed go back and ask for 'anything you can give me'?

Signed-off-by: Daniel Axtens <dja@axtens.net>
---
 grub-core/kern/ieee1275/init.c | 37 +++++++++-------------------------
 1 file changed, 10 insertions(+), 27 deletions(-)

diff --git a/grub-core/kern/ieee1275/init.c b/grub-core/kern/ieee1275/init.c
index f70cb134178b..87c1ab997138 100644
--- a/grub-core/kern/ieee1275/init.c
+++ b/grub-core/kern/ieee1275/init.c
@@ -186,7 +186,7 @@ count_free (grub_uint64_t addr, grub_uint64_t len, 
grub_memory_type_t type,
 
 static int
 regions_claim (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
-             unsigned int flags, void *data)
+              void *data)
 {
   grub_uint32_t total = *(grub_uint32_t *)data;
   grub_uint32_t linux_rmo_save;
@@ -257,13 +257,6 @@ regions_claim (grub_uint64_t addr, grub_uint64_t len, 
grub_memory_type_t type,
       grub_printf ("now %llx - %llx (vs %x)\n", addr, addr + len, 
linux_rmo_save);
     }
 
-  if (flags & GRUB_MM_ADD_REGION_CONSECUTIVE)
-    {
-      // only continue if we can satisfy the entire allocation
-      if (len < total)
-       return 0;
-    }
-
   if (len > total)
     len = total;
 
@@ -287,21 +280,6 @@ regions_claim (grub_uint64_t addr, grub_uint64_t len, 
grub_memory_type_t type,
   return 0;
 }
 
-static int
-heap_init (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
-          void *data)
-{
-  return regions_claim(addr, len, type, GRUB_MM_ADD_REGION_NONE, data);
-}
-
-static int
-region_claim (grub_uint64_t addr, grub_uint64_t len, grub_memory_type_t type,
-          void *data)
-{
-  return regions_claim(addr, len, type, GRUB_MM_ADD_REGION_CONSECUTIVE, data);
-}
-
-
 static grub_err_t grub_ieee1275_mm_add_region (grub_size_t size, unsigned int 
flags)
 {
   grub_uint32_t total = size;
@@ -325,7 +303,10 @@ static grub_err_t grub_ieee1275_mm_add_region (grub_size_t 
size, unsigned int fl
       grub_printf ("ieee1275: free = 0x%x, allocated = 0x%x\n", free_memory, 
allocated_memory);
 
       if (size > free_memory - RUNTIME_MIN_SPACE)
-       return GRUB_ERR_OUT_OF_MEMORY;
+        {
+         // hope region extension saves us
+         total = free_memory - RUNTIME_MIN_SPACE;
+       }
       else
        {
          total = grub_max(ALIGN_UP(size, 1024 * 1024) + 1024 * 1024, 32 * 1024 
* 1024);
@@ -333,13 +314,15 @@ static grub_err_t grub_ieee1275_mm_add_region 
(grub_size_t size, unsigned int fl
        }
       grub_printf ("ieee1275: looking for %x bytes of memory (%x 
requested)\n", total, size);
 
-      grub_machine_mmap_iterate (region_claim, &total);
+      grub_machine_mmap_iterate (regions_claim, &total);
       grub_printf ("ieee1275: get memory from fw %s\n", total == 0 ? 
"succeeded" : "failed");
     }
   else
-    grub_machine_mmap_iterate (heap_init, &total);
+    grub_machine_mmap_iterate (regions_claim, &total);
 
-  if (total == 0)
+  // lie a little: if we allocated _anything_ give it another go
+  // because region merging might have saved the day
+  if (total != size)
     return GRUB_ERR_NONE;
   else
     return GRUB_ERR_OUT_OF_MEMORY;
-- 
2.30.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]