Jelajahi Sumber

Kernel: Use removed memory as backup if backup hasn't been allocated

It may be impossible to allocate more backup memory after expanding
the heap if memory is running low. In that case we wouldn't allocate
backup memory until trying to expand the heap again. But we also
wouldn't take advantage of using removed memory as backup, which means
that no backup memory would be available when the heap needs to grow
again, causing subsequent expansion to fail because there is no
backup memory.
Tom 4 tahun lalu
induk
melakukan
1ece93c805
1 mengubah file dengan 4 tambahan dan 0 penghapusan
  1. 4 0
      Kernel/Heap/kmalloc.cpp

+ 4 - 0
Kernel/Heap/kmalloc.cpp

@@ -114,6 +114,10 @@ struct KmallocGlobalHeap {
                 if (m_global_heap.m_subheap_memory[i].vaddr().as_ptr() == memory) {
                     auto region = m_global_heap.m_subheap_memory.take(i);
                     klog() << "kmalloc(): Removing memory from heap at " << region->vaddr() << ", bytes: " << region->size();
+                    if (!m_global_heap.m_backup_memory) {
+                        klog() << "kmalloc(): Using removed memory as backup: " << region->vaddr() << ", bytes: " << region->size();
+                        m_global_heap.m_backup_memory = move(region);
+                    }
                     return true;
                 }
             }