Switch to using the slab allocator for common objects.
This commit is contained in:
parent
b84ee76c20
commit
e5fd27f2f2
@ -33,7 +33,7 @@ VFS *
|
||||
O2FS_Mount(Disk *disk)
|
||||
{
|
||||
int status;
|
||||
VFS *fs = (VFS *)PAlloc_AllocPage();
|
||||
VFS *fs = VFS_Alloc();
|
||||
DiskCacheEntry *entry;
|
||||
SuperBlock *sb;
|
||||
|
||||
@ -119,7 +119,7 @@ O2FSLoadVNode(VFS *fs, ObjID *objid)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vn = (VNode *)PAlloc_AllocPage();
|
||||
vn = VNode_Alloc();
|
||||
if (!vn) {
|
||||
return NULL;
|
||||
}
|
||||
@ -147,7 +147,7 @@ O2FSReleaseVNode(VNode *vn)
|
||||
if (vn->refCount == 0) {
|
||||
DiskCache_Release(vn->fsptr);
|
||||
Spinlock_Destroy(&vn->lock);
|
||||
PAlloc_FreePage(vn);
|
||||
VNode_Free(vn);
|
||||
}
|
||||
}
|
||||
|
||||
@ -184,7 +184,7 @@ O2FS_GetRoot(VFS *fs, VNode **dn)
|
||||
return -1;
|
||||
}
|
||||
|
||||
vn = (VNode *)PAlloc_AllocPage();
|
||||
vn = VNode_Alloc();
|
||||
vn->op = &O2FSOperations;
|
||||
vn->disk = fs->disk;
|
||||
Spinlock_Init(&vn->lock, "VNode Lock");
|
||||
|
@ -61,5 +61,17 @@ void Slab_Init(Slab *slab, const char *name, uintptr_t objsz, uintptr_t align);
|
||||
void *Slab_Alloc(Slab *slab);
|
||||
void Slab_Free(Slab *slab, void *obj);
|
||||
|
||||
#define DECLARE_SLAB(_type) \
|
||||
_type *_type##_Alloc(); \
|
||||
void _type##_Free(_type *obj);
|
||||
|
||||
#define DEFINE_SLAB(_type, _pool) \
|
||||
_type *_type##_Alloc() { \
|
||||
return (_type *)Slab_Alloc(_pool); \
|
||||
} \
|
||||
void _type##_Free(_type *obj) { \
|
||||
Slab_Free(_pool, obj); \
|
||||
}
|
||||
|
||||
#endif /* __KMEM_H__ */
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
#ifndef __SYS_VFS_H__
|
||||
#define __SYS_VFS_H__
|
||||
|
||||
#include <sys/kmem.h>
|
||||
|
||||
typedef struct VFSOp VFSOp;
|
||||
typedef struct VNode VNode;
|
||||
|
||||
@ -27,6 +29,9 @@ typedef struct VNode {
|
||||
VFS *vfs;
|
||||
} VNode;
|
||||
|
||||
DECLARE_SLAB(VFS);
|
||||
DECLARE_SLAB(VNode);
|
||||
|
||||
typedef struct VFSOp {
|
||||
// VFS Operations
|
||||
int (*unmount)(VFS *fs);
|
||||
@ -44,5 +49,6 @@ int VFS_Open(VNode *fn);
|
||||
int VFS_Close(VNode *fn);
|
||||
int VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len);
|
||||
|
||||
|
||||
#endif /* __SYS_VFS_H__ */
|
||||
|
||||
|
@ -18,6 +18,9 @@ static TAILQ_HEAD(LRUCacheList, DiskCacheEntry) lruList;
|
||||
static uint64_t cacheHit;
|
||||
static uint64_t cacheMiss;
|
||||
static uint64_t cacheAlloc;
|
||||
static Slab cacheEntrySlab;
|
||||
|
||||
DEFINE_SLAB(DiskCacheEntry, &cacheEntrySlab);
|
||||
|
||||
#define CACHESIZE (16*1024*1024)
|
||||
#define HASHTABLEENTRIES 128
|
||||
@ -32,26 +35,29 @@ DiskCache_Init()
|
||||
|
||||
diskBuf = XMem_New();
|
||||
if (!diskBuf)
|
||||
Panic("DiskCache: Cannot create XMem region");
|
||||
Panic("DiskCache: Cannot create XMem region\n");
|
||||
|
||||
if (!XMem_Allocate(diskBuf, CACHESIZE))
|
||||
Panic("DiskCache: Cannot back XMem region");
|
||||
Panic("DiskCache: Cannot back XMem region\n");
|
||||
|
||||
TAILQ_INIT(&lruList);
|
||||
|
||||
hashTable = PAlloc_AllocPage();
|
||||
if (!hashTable)
|
||||
Panic("DiskCache: Cannot allocate hash table");
|
||||
Panic("DiskCache: Cannot allocate hash table\n");
|
||||
for (i = 0; i < HASHTABLEENTRIES; i++) {
|
||||
TAILQ_INIT(&hashTable[i]);
|
||||
}
|
||||
|
||||
Slab_Init(&cacheEntrySlab, "DiskCacheEntry Slab", sizeof(DiskCacheEntry), 16);
|
||||
|
||||
// Initialize cache
|
||||
uintptr_t bufBase = XMem_GetBase(diskBuf);
|
||||
for (i = 0; i < CACHESIZE/BLOCKSIZE; i++) {
|
||||
DiskCacheEntry *e = PAlloc_AllocPage();
|
||||
if (!e)
|
||||
Panic("DiskCache: Cannot allocate cache entry");
|
||||
DiskCacheEntry *e = DiskCacheEntry_Alloc();
|
||||
if (!e) {
|
||||
Panic("DiskCache: Cannot allocate cache entry\n");
|
||||
}
|
||||
|
||||
memset(e, 0, sizeof(*e));
|
||||
e->disk = NULL;
|
||||
|
@ -15,6 +15,12 @@ static Spinlock vfsLock;
|
||||
static VFS *rootFS;
|
||||
static VNode *rootNode;
|
||||
|
||||
static Slab vfsSlab;
|
||||
static Slab vnodeSlab;
|
||||
|
||||
DEFINE_SLAB(VFS, &vfsSlab);
|
||||
DEFINE_SLAB(VNode, &vnodeSlab);
|
||||
|
||||
int
|
||||
VFS_MountRoot(Disk *rootDisk)
|
||||
{
|
||||
@ -22,6 +28,9 @@ VFS_MountRoot(Disk *rootDisk)
|
||||
|
||||
Spinlock_Init(&vfsLock, "VFS Lock");
|
||||
|
||||
Slab_Init(&vfsSlab, "VFS Slab", sizeof(VFS), 16);
|
||||
Slab_Init(&vnodeSlab, "VNode Slab", sizeof(VNode), 16);
|
||||
|
||||
rootFS = O2FS_Mount(rootDisk);
|
||||
if (!rootFS)
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user