10#include <sys/kassert.h>
11#include <sys/kdebug.h>
13#include <sys/spinlock.h>
15#include <sys/bufcache.h>
26static Slab cacheEntrySlab;
30#define CACHESIZE (16*1024*1024)
31#define HASHTABLEENTRIES 128
32#define BLOCKSIZE (16*1024)
48 Panic(
"BufCache: Cannot create XMem region\n");
51 Panic(
"BufCache: Cannot back XMem region\n");
57 Panic(
"BufCache: Cannot allocate hash table\n");
69 Panic(
"BufCache: Cannot allocate cache entry\n");
99 struct CacheHashTable *table;
135 struct CacheHashTable *table;
141 kprintf(
"BufCache: No space left!\n");
185 if (*entry ==
NULL) {
237 if (*entry !=
NULL) {
250 buf = (*entry)->buffer;
287 kprintf(
"Hits: %lld\n", cacheHit);
288 kprintf(
"Misses: %lld\n", cacheMiss);
289 kprintf(
"Allocations: %lld\n", cacheAlloc);
static void Debug_BufCache(int argc, const char *argv[])
int BufCache_Write(BufCacheEntry *entry)
int BufCache_Read(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
static int BufCacheLookup(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
void BufCache_Release(BufCacheEntry *entry)
static int BufCacheAlloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
int BufCache_Alloc(Disk *disk, uint64_t diskOffset, BufCacheEntry **entry)
int Disk_Write(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
int Disk_Read(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
int kprintf(const char *fmt,...)
#define REGISTER_DBGCMD(_NAME, _DESC, _FUNC)
void * PAlloc_AllocPage()
#define DEFINE_SLAB(_type, _pool)
void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align)
#define TAILQ_FOREACH(var, head, field)
#define TAILQ_HEAD(name, type)
#define TAILQ_INSERT_TAIL(head, elm, field)
#define TAILQ_FIRST(head)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_INSERT_HEAD(head, elm, field)
void SGArray_Init(SGArray *sga)
int SGArray_Append(SGArray *sga, uint64_t off, uint64_t len)
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
#define SPINLOCK_TYPE_NORMAL
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
void * memset(void *dst, int c, size_t len)
void Panic(const char *str)
bool XMem_Allocate(XMem *xmem, uintptr_t length)
uintptr_t XMem_GetBase(XMem *xmem)