mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 11:45:06 +00:00
Add a very naive block cache to the DiskBackedFileSystem.
This would be a lot better as an LRU. Right now it's a 32-slot hash table with random eviction.
This commit is contained in:
parent
82bbfa8496
commit
fdc782c1d1
4 changed files with 36 additions and 3 deletions
|
@ -1,5 +1,11 @@
|
|||
#include "DiskBackedFileSystem.h"
|
||||
|
||||
#ifdef SERENITY
|
||||
#include "i386.h"
|
||||
#else
|
||||
typedef int InterruptDisabler;
|
||||
#endif
|
||||
|
||||
//#define DBFS_DEBUG
|
||||
|
||||
DiskBackedFileSystem::DiskBackedFileSystem(RetainPtr<DiskDevice>&& device)
|
||||
|
@ -36,11 +42,26 @@ ByteBuffer DiskBackedFileSystem::readBlock(unsigned index) const
|
|||
#ifdef DBFS_DEBUG
|
||||
kprintf("DiskBackedFileSystem::readBlock %u\n", index);
|
||||
#endif
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
auto it = m_blockCache.find(index);
|
||||
if (it != m_blockCache.end()) {
|
||||
return (*it).value;
|
||||
}
|
||||
}
|
||||
|
||||
auto buffer = ByteBuffer::createUninitialized(blockSize());
|
||||
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
|
||||
auto* bufferPointer = buffer.pointer();
|
||||
device().read(baseOffset, blockSize(), bufferPointer);
|
||||
ASSERT(buffer.size() == blockSize());
|
||||
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
if (m_blockCache.size() >= 32)
|
||||
m_blockCache.removeOneRandomly();
|
||||
m_blockCache.set(index, buffer);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
@ -74,5 +95,6 @@ void DiskBackedFileSystem::setBlockSize(unsigned blockSize)
|
|||
|
||||
void DiskBackedFileSystem::invalidateCaches()
|
||||
{
|
||||
// FIXME: Implement block cache.
|
||||
InterruptDisabler disabler;
|
||||
m_blockCache.clear();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue