Crate block_cache
source ·Expand description
A caching layer for block based storage devices.
For many storage devices, calls to the backing medium are quite expensive. This layer intends to reduce those calls,
improving efficiency in exchange for additional memory usage. Note that this crate is intended to be used as a part of
block_io
, but should work on its own.
Limitations
Currently, the BlockCache
struct is hardcoded to use a StorageDevice
reference,
when in reality it should just use anything that implements traits like BlockReader + BlockWriter
.
The read and write functions currently only support reading/writing individual blocks from disk even when the caller might prefer reading a larger number of contiguous blocks. This is inneficient and an optimized implementation should read multiple blocks at once if possible.
Cached blocks are stored as vectors of bytes on the heap, we should do something else such as separate mapped regions. Cached blocks cannot yet be dropped to relieve memory pressure.
Note that this cache only holds a reference to the underlying block device.
As such if any other system crates perform writes to the underlying device,
in that case the cache will give incorrect and potentially inconsistent results.
In the long run, the only way around this would be to only expose a BlockCache
instead of exposing a StorageDevice
. I suppose the least disruptive way to implement this
might be with a layer of indirection to an implementor of a BlockReader like trait,
so that the underlying block reader can be switched out when a cache is enabled.
Structs
- A cache to store read and written blocks from a storage device.