vmmcache: initial implementation

This commit is contained in:
Matheus
2024-05-24 18:03:24 -03:00
parent 7673a365e8
commit 48b7fb4324
21 changed files with 772 additions and 134 deletions
+6
View File
@@ -10,6 +10,11 @@
#define PMM_SECTION_DEFAULT 2
#define PAGE_FLAGS_FREE 1
#define PAGE_FLAGS_TRUNCATED 2
#define PAGE_FLAGS_PINNED 4
#define PAGE_FLAGS_DIRTY 8
#define PAGE_FLAGS_READY 16
#define PAGE_FLAGS_ERROR 32
typedef struct page_t {
struct vnode_t *backing;
@@ -34,6 +39,7 @@ typedef struct page_t {
void *pmm_allocpage(int section);
page_t *pmm_getpage(void *addr);
void *pmm_getpageaddress(page_t *);
void pmm_hold(void *addr);
void pmm_release(void *addr);
void pmm_makefree(void *address, size_t count);
-4
View File
@@ -16,10 +16,6 @@ typedef struct tmpfsnode_t {
vattr_t attr;
union {
hashtable_t children;
struct {
void *data;
size_t pagecount;
};
char *link;
};
} tmpfsnode_t;
+7
View File
@@ -60,12 +60,14 @@ typedef struct vfs_t {
typedef struct vnode_t {
struct vops_t *ops;
mutex_t lock;
mutex_t sizelock;
int refcount;
int flags;
int type;
vfs_t *vfs;
vfs_t *vfsmounted;
void *socketbinding;
struct page_t *pages;
} vnode_t;
typedef struct vfsops_t {
@@ -101,6 +103,8 @@ typedef struct vops_t {
int (*maxseek)(vnode_t *node, size_t *max);
int (*resize)(vnode_t *node, size_t newsize, cred_t *cred);
int (*rename)(vnode_t *source, char *oldname, vnode_t *target, char *newname, int flags);
int (*getpage)(vnode_t *node, uintmax_t offset, struct page_t *page);
int (*putpage)(vnode_t *node, uintmax_t offset, struct page_t *page);
} vops_t;
#define VFS_INIT(v, o, f) \
@@ -118,6 +122,7 @@ typedef struct vops_t {
#define VOP_INIT(vn, o, f, t, v) \
(vn)->ops = o; \
MUTEX_INIT(&(vn)->lock); \
MUTEX_INIT(&(vn)->sizelock); \
(vn)->refcount = 1; \
(vn)->flags = f; \
(vn)->type = t; \
@@ -149,6 +154,8 @@ typedef struct vops_t {
#define VOP_MAXSEEK(v, rp) ((v)->ops->maxseek ? (v)->ops->maxseek(v, rp) : ENOTTY)
#define VOP_RESIZE(v, s, c) (v)->ops->resize(v, s, c)
#define VOP_RENAME(s, o, t, n, f) (s)->ops->rename(s, o, t, n, f)
#define VOP_GETPAGE(v, o, p) (v)->ops->getpage(v, o, p)
#define VOP_PUTPAGE(v, o, p) (v)->ops->putpage(v, o, p)
#define VOP_HOLD(v) __atomic_add_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST)
#define VOP_RELEASE(v) {\
if (__atomic_sub_fetch(&(v)->refcount, 1, __ATOMIC_SEQ_CST) == 0) {\
+15
View File
@@ -0,0 +1,15 @@
#ifndef _VMMCACHE_H
#define _VMMCACHE_H
#include <kernel/pmm.h>
#include <kernel/vfs.h>
void vmmcache_init();
int vmmcache_getpage(vnode_t *vnode, uintmax_t offset, page_t **res);
int vmmcache_takepage(page_t *page);
int vmmcache_makedirty(page_t *page);
int vmmcache_truncate(vnode_t *vnode, uintmax_t offset);
int vmmcache_syncvnode(vnode_t *vnode);
int vmmcache_sync();
#endif