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:
parent
ee51b28edd
commit
1ece93c805
Notes:
sideshowbarker
2024-07-19 02:55:41 +09:00
Author: https://github.com/tomuta Commit: https://github.com/SerenityOS/serenity/commit/1ece93c8055 Pull-request: https://github.com/SerenityOS/serenity/pull/3385
1 changed files with 4 additions and 0 deletions
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue