1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:17:35 +00:00

Remove the cheesy block cache from DiskBackedFS.

This should be reimplemented with proper paging support. This approach was
mostly just chewing kmalloc memory.
This commit is contained in:
Andreas Kling 2019-01-01 02:27:05 +01:00
parent 4b6a8f8a08
commit 42d9f18cae
3 changed files with 1 additions and 37 deletions

View file

@ -7,7 +7,6 @@ typedef int InterruptDisabler;
#endif #endif
//#define DBFS_DEBUG //#define DBFS_DEBUG
#define BLOCK_CACHE
DiskBackedFS::DiskBackedFS(RetainPtr<DiskDevice>&& device) DiskBackedFS::DiskBackedFS(RetainPtr<DiskDevice>&& device)
: m_device(move(device)) : m_device(move(device))
@ -43,18 +42,6 @@ ByteBuffer DiskBackedFS::readBlock(unsigned index) const
#ifdef DBFS_DEBUG #ifdef DBFS_DEBUG
kprintf("DiskBackedFileSystem::readBlock %u\n", index); kprintf("DiskBackedFileSystem::readBlock %u\n", index);
#endif #endif
#ifdef BLOCK_CACHE
{
LOCKER(m_blockCacheLock);
InterruptDisabler disabler;
auto it = m_blockCache.find(index);
if (it != m_blockCache.end()) {
return (*it).value;
}
}
#endif
auto buffer = ByteBuffer::create_uninitialized(blockSize()); auto buffer = ByteBuffer::create_uninitialized(blockSize());
//kprintf("created block buffer with size %u\n", blockSize()); //kprintf("created block buffer with size %u\n", blockSize());
DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize()); DiskOffset baseOffset = static_cast<DiskOffset>(index) * static_cast<DiskOffset>(blockSize());
@ -62,16 +49,6 @@ ByteBuffer DiskBackedFS::readBlock(unsigned index) const
bool success = device().read(baseOffset, blockSize(), bufferPointer); bool success = device().read(baseOffset, blockSize(), bufferPointer);
ASSERT(success); ASSERT(success);
ASSERT(buffer.size() == blockSize()); ASSERT(buffer.size() == blockSize());
#ifdef BLOCK_CACHE
{
LOCKER(m_blockCacheLock);
InterruptDisabler disabler;
if (m_blockCache.size() >= 32)
m_blockCache.removeOneRandomly();
m_blockCache.set(index, buffer);
}
#endif
return buffer; return buffer;
} }
@ -100,12 +77,4 @@ void DiskBackedFS::setBlockSize(unsigned blockSize)
if (blockSize == m_blockSize) if (blockSize == m_blockSize)
return; return;
m_blockSize = blockSize; m_blockSize = blockSize;
invalidateCaches();
}
void DiskBackedFS::invalidateCaches()
{
LOCKER(m_blockCacheLock);
InterruptDisabler disabler;
m_blockCache.clear();
} }

View file

@ -2,8 +2,6 @@
#include "FileSystem.h" #include "FileSystem.h"
#include <AK/ByteBuffer.h> #include <AK/ByteBuffer.h>
#include <AK/HashMap.h>
#include <AK/Lock.h>
class DiskBackedFS : public FS { class DiskBackedFS : public FS {
public: public:
@ -18,7 +16,6 @@ protected:
explicit DiskBackedFS(RetainPtr<DiskDevice>&&); explicit DiskBackedFS(RetainPtr<DiskDevice>&&);
void setBlockSize(unsigned); void setBlockSize(unsigned);
void invalidateCaches();
ByteBuffer readBlock(unsigned index) const; ByteBuffer readBlock(unsigned index) const;
ByteBuffer readBlocks(unsigned index, unsigned count) const; ByteBuffer readBlocks(unsigned index, unsigned count) const;
@ -29,7 +26,4 @@ protected:
private: private:
size_t m_blockSize { 0 }; size_t m_blockSize { 0 };
RetainPtr<DiskDevice> m_device; RetainPtr<DiskDevice> m_device;
mutable SpinLock m_blockCacheLock;
mutable HashMap<unsigned, ByteBuffer> m_blockCache;
}; };

View file

@ -4,6 +4,7 @@
#include "UnixTypes.h" #include "UnixTypes.h"
#include <AK/Buffer.h> #include <AK/Buffer.h>
#include <AK/OwnPtr.h> #include <AK/OwnPtr.h>
#include <AK/Lock.h>
#include "ext2_fs.h" #include "ext2_fs.h"
struct ext2_group_desc; struct ext2_group_desc;