Skip to content

Block Cache

include/block/bcache.h View source View on GitHub
struct bcache_entry (9 fields) source

must be allocated with malloc

§ uint8_t *buffer cc_counted_by(size)

allocated upon new reads

§ uint64_t size
§ uint64_t lba

logical block address

§ uint64_t access_time

used with a counter - not a real ‘timestamp’

§ struct mutex lock
§ bool dirty
§ bool no_evict
§ struct bio_request *request

associated outgoing request

§ refcount_t refcount
struct bcache_wrapper (4 fields) source
§ uint64_t key

block number

§ struct bcache_entry *value

pointer to cache entry

§ bool occupied
§ struct bcache_wrapper *next
struct bcache (6 fields) source
TODO

bitmap to mark present entries

§ struct bcache_wrapper **entries
§ uint64_t capacity
§ uint64_t count
§ uint64_t spb
§ struct spinlock lock
uint64_t bcache_hash(uint64_t x, uint64_t capacity)
source
void bcache_init(struct bcache *cache, uint64_t capacity)
source
void * bcache_get(
    struct block_device *disk,
    uint64_t lba,
    uint64_t block_size,
    uint64_t spb,
    bool no_evict,
    struct bcache_entry **out_entry
)
source
bool bcache_writethrough(
    struct block_device *disk,
    struct bcache_entry *ent,
    uint64_t spb
)
source
void bcache_write_queue(
    struct block_device *disk,
    struct bcache_entry *ent,
    uint64_t spb,
    enum bio_request_priority prio
)
source
void bcache_stat(
    struct block_device *disk,
    uint64_t *total_dirty_out,
    uint64_t *total_present_out
)
source
bool bcache_insert(
    struct block_device *disk,
    uint64_t lba,
    struct bcache_entry *ent,
    uint64_t spb
)
source
bool bcache_evict(struct block_device *disk, uint64_t spb)
source
enum err bcache_prefetch_async(
    struct block_device *disk,
    uint64_t lba,
    uint64_t block_size,
    uint64_t spb
)
source
void * bcache_create_ent(
    struct block_device *disk,
    uint64_t lba,
    uint64_t block_size,
    uint64_t sectors_per_block,
    bool no_evict,
    struct bcache_entry **out_entry
)
source
void bcache_increment_ticks(struct bcache *cache)
source
uint64_t bcache_get_ticks(struct bcache *cache)
source
void bcache_ent_lock(struct bcache_entry *ent)
source
void bcache_ent_unlock(struct bcache_entry *ent)
source
void bcache_ent_pin(struct bcache_entry *ent)
source
void bcache_ent_unpin(struct bcache_entry *ent)
source
void bcache_ent_acquire(struct bcache_entry *ent)
source
void bcache_ent_release(struct bcache_entry *ent)
source
void bcache_destroy(struct bcache *cache)
source
#define DEFAULT_BLOCK_CACHE_SIZE 2048
source
#define DEFAULT_MAX_DIRTY_ENTS 64
source