Kernel: DiskCache won't crash when running out of kmalloc memory

This commit is contained in:
Bananymous 2023-06-03 02:36:20 +03:00
parent 59b807189f
commit 884d986bd6
1 changed files with 20 additions and 16 deletions

View File

@ -55,7 +55,8 @@ namespace Kernel
} }
// We try to allocate new cache block for this sector // We try to allocate new cache block for this sector
TRY(m_cache.emplace_back()); if (!m_cache.emplace_back().is_error())
{
if (paddr_t paddr = Heap::get().take_free_page()) if (paddr_t paddr = Heap::get().take_free_page())
{ {
auto& cache_block = m_cache.back(); auto& cache_block = m_cache.back();
@ -65,6 +66,7 @@ namespace Kernel
cache_block.sectors[0].dirty = false; cache_block.sectors[0].dirty = false;
return {}; return {};
} }
}
// We could not cache the sector // We could not cache the sector
return {}; return {};
@ -106,7 +108,8 @@ namespace Kernel
} }
// We try to allocate new cache block // We try to allocate new cache block
TRY(m_cache.emplace_back()); if (!m_cache.emplace_back().is_error())
{
if (paddr_t paddr = Heap::get().take_free_page()) if (paddr_t paddr = Heap::get().take_free_page())
{ {
auto& cache_block = m_cache.back(); auto& cache_block = m_cache.back();
@ -116,6 +119,7 @@ namespace Kernel
cache_block.sectors[0].dirty = true; cache_block.sectors[0].dirty = true;
return {}; return {};
} }
}
// We could not allocate cache, so we must sync it to disk // We could not allocate cache, so we must sync it to disk
// right away // right away