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.
This commit is contained in:
Tom 2020-09-01 16:04:23 -06:00 committed by Andreas Kling
parent ee51b28edd
commit 1ece93c805
Notes: sideshowbarker 2024-07-19 02:55:41 +09:00

View file

@ -114,6 +114,10 @@ struct KmallocGlobalHeap {
if (m_global_heap.m_subheap_memory[i].vaddr().as_ptr() == memory) { if (m_global_heap.m_subheap_memory[i].vaddr().as_ptr() == memory) {
auto region = m_global_heap.m_subheap_memory.take(i); auto region = m_global_heap.m_subheap_memory.take(i);
klog() << "kmalloc(): Removing memory from heap at " << region->vaddr() << ", bytes: " << region->size(); 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; return true;
} }
} }