mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:38:10 +00:00

The hashmap cache was ridiculously slow and hurt us more than it helped us. This patch replaces it with a flat memory cache that keeps up to 10'000 blocks in cache with a simple dirty bit. The syncd task will wake up periodically and call flush_writes() on all file systems, which now causes us to traverse the cache and write all dirty blocks to disk. There's a ton of room for improvement here, but this itself is already drastically better when doing repeated GCC invocations.
33 lines
819 B
C++
33 lines
819 B
C++
#pragma once
|
|
|
|
#include "FileSystem.h"
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
class DiskCache;
|
|
|
|
class DiskBackedFS : public FS {
|
|
public:
|
|
virtual ~DiskBackedFS() override;
|
|
|
|
virtual bool is_disk_backed() const override { return true; }
|
|
|
|
DiskDevice& device() { return *m_device; }
|
|
const DiskDevice& device() const { return *m_device; }
|
|
|
|
virtual void flush_writes() override;
|
|
|
|
protected:
|
|
explicit DiskBackedFS(NonnullRefPtr<DiskDevice>&&);
|
|
|
|
ByteBuffer read_block(unsigned index) const;
|
|
ByteBuffer read_blocks(unsigned index, unsigned count) const;
|
|
|
|
bool write_block(unsigned index, const ByteBuffer&);
|
|
bool write_blocks(unsigned index, unsigned count, const ByteBuffer&);
|
|
|
|
private:
|
|
DiskCache& cache() const;
|
|
|
|
NonnullRefPtr<DiskDevice> m_device;
|
|
mutable OwnPtr<DiskCache> m_cache;
|
|
};
|