[PATCH] libcsupport: Have greedy allocations use consume extended memory

chrisj at rtems.org chrisj at rtems.org
Mon Feb 8 06:30:03 UTC 2021


From: Chris Johns <chrisj at rtems.org>

- Call the heap extend handler until all memory has been
  requested.

Closes #3982
---
 cpukit/libcsupport/src/rtems_heap_greedy.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/cpukit/libcsupport/src/rtems_heap_greedy.c b/cpukit/libcsupport/src/rtems_heap_greedy.c
index 4dda39873f..2361f17d2e 100644
--- a/cpukit/libcsupport/src/rtems_heap_greedy.c
+++ b/cpukit/libcsupport/src/rtems_heap_greedy.c
@@ -30,8 +30,20 @@ void *rtems_heap_greedy_allocate(
   size_t block_count
 )
 {
+  Heap_Control *heap = RTEMS_Malloc_Heap;
+  size_t size = 128 * 1024 * 1024;
   void *opaque;
 
+  while (size > 0) {
+    opaque = (*rtems_malloc_extend_handler)( heap, size );
+    if (opaque == NULL) {
+      size >>= 1;
+    } else {
+      if ( rtems_malloc_dirty_helper != NULL )
+	(*rtems_malloc_dirty_helper)( opaque, size );
+    }
+  }
+
   _RTEMS_Lock_allocator();
   opaque = _Heap_Greedy_allocate( RTEMS_Malloc_Heap, block_sizes, block_count );
   _RTEMS_Unlock_allocator();
-- 
2.24.1



More information about the devel mailing list