浏览代码

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 年之前
父节点
当前提交
1ece93c805
共有 1 个文件被更改,包括 4 次插入0 次删除
  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;
                 }
             }