mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 05:08:22 +00:00
page cache rewrite
This commit is contained in:
@@ -73,8 +73,10 @@ static inline int fileflagstovnodeflags(int flags) {
|
||||
vnflags |= V_FFLAGS_NONBLOCKING;
|
||||
if (flags & O_NOCTTY)
|
||||
vnflags |= V_FFLAGS_NOCTTY;
|
||||
if (flags & (O_DIRECT | O_SYNC | O_DSYNC))
|
||||
if (flags & O_DIRECT)
|
||||
vnflags |= V_FFLAGS_NOCACHE;
|
||||
if (flags & (O_SYNC | O_DSYNC))
|
||||
vnflags |= V_FFLAG_MUST_SYNC;
|
||||
|
||||
return vnflags;
|
||||
}
|
||||
|
||||
@@ -99,15 +99,14 @@ void mm_init();
|
||||
|
||||
extern size_t mm_cache_cached_pages;
|
||||
|
||||
void mm_cache_init(void);
|
||||
#define MM_CACHE_GET_PAGE_FLAGS_NO_POPULATE 1
|
||||
int mm_cache_get_page(vnode_t *vnode, uintmax_t offset, int flags, page_t **res);
|
||||
int mm_cache_take_page(page_t *page);
|
||||
int mm_cache_make_dirty(page_t *page);
|
||||
void mm_cache_make_dirty(page_t *page);
|
||||
int mm_cache_truncate(vnode_t *vnode, uintmax_t offset);
|
||||
int mm_cache_sync_vnode(vnode_t *vnode, uintmax_t startoffset, size_t size);
|
||||
int mm_cache_push_page(vnode_t *vnode, uintmax_t offset, page_t *page);
|
||||
int mm_cache_sync_vnode(vnode_t *vnode);
|
||||
int mm_cache_sync(void);
|
||||
int mm_cache_evict(page_t *page);
|
||||
void mm_cache_init_writer(void);
|
||||
|
||||
void mm_range_init(void);
|
||||
mm_range_t *mm_alloc_range(void);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <list.h>
|
||||
|
||||
#define MEMORY_SECTION_COUNT 3
|
||||
#define MEMORY_SECTION_1MB 0
|
||||
@@ -16,24 +17,17 @@
|
||||
#define PAGE_FLAGS_DIRTY 8
|
||||
#define PAGE_FLAGS_READY 16
|
||||
#define PAGE_FLAGS_ERROR 32
|
||||
#define PAGE_FLAGS_VNODE_SYNCING 64
|
||||
#define PAGE_FLAGS_SYNCING 64
|
||||
|
||||
typedef struct page_t {
|
||||
struct vnode_t *backing;
|
||||
uintmax_t offset;
|
||||
struct page_t *hash_next;
|
||||
struct page_t *hash_prev;
|
||||
struct page_t *vnode_next;
|
||||
struct page_t *vnode_prev;
|
||||
union {
|
||||
struct {
|
||||
struct page_t *free_next;
|
||||
struct page_t *free_prev;
|
||||
};
|
||||
struct {
|
||||
struct page_t *write_next;
|
||||
struct page_t *write_prev;
|
||||
};
|
||||
list_node_t dirty_list_node;
|
||||
};
|
||||
uintmax_t refcount;
|
||||
uintmax_t lock_count;
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
#include <errno.h>
|
||||
#include <kernel/cred.h>
|
||||
#include <kernel/event.h>
|
||||
#include <trie.h>
|
||||
#include <errno.h>
|
||||
#include <kernel/page.h>
|
||||
#include <list.h>
|
||||
|
||||
#define V_ATTR_MODE 1
|
||||
#define V_ATTR_UID 2
|
||||
@@ -120,6 +123,7 @@ typedef struct advlock_t {
|
||||
#define V_FFLAGS_NOCTTY 32
|
||||
#define V_FFLAGS_NOCACHE 64
|
||||
#define V_FFLAGS_CLOSE_URGENT 128
|
||||
#define V_FFLAG_MUST_SYNC 256
|
||||
|
||||
typedef struct vnode_t {
|
||||
struct vops_t *ops;
|
||||
@@ -135,7 +139,14 @@ typedef struct vnode_t {
|
||||
void *fifobinding;
|
||||
};
|
||||
|
||||
struct page_t *pages;
|
||||
bool dirty;
|
||||
mutex_t writeback_mutex;
|
||||
mutex_t dirty_list_mutex;
|
||||
list_node_t vnode_dirty_list_node;
|
||||
list_t dirty_pages;
|
||||
|
||||
pushlock_t pages_lock;
|
||||
trie_t pages;
|
||||
|
||||
mutex_t adv_mutex;
|
||||
advlock_t *advlock;
|
||||
@@ -177,6 +188,7 @@ typedef struct vops_t {
|
||||
int (*rename)(vnode_t *sourcedir, vnode_t *source, char *oldname, vnode_t *targetdir, 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);
|
||||
// node must be unlocked on entry.
|
||||
int (*sync)(vnode_t *node);
|
||||
int (*advlock)(vnode_t *node, int op, advlock_t *advlock);
|
||||
int (*lock)(vnode_t *node);
|
||||
@@ -208,7 +220,12 @@ typedef struct vops_t {
|
||||
(vn)->type = t; \
|
||||
(vn)->vfs = v; \
|
||||
(vn)->vfsmounted = NULL; \
|
||||
(vn)->pages = NULL;
|
||||
trie_init(&(vn)->pages); \
|
||||
(vn)->pages_lock = 0; \
|
||||
MUTEX_INIT(&(vn)->writeback_mutex); \
|
||||
MUTEX_INIT(&(vn)->dirty_list_mutex); \
|
||||
(vn)->dirty = false; \
|
||||
list_init(&(vn)->dirty_pages);
|
||||
|
||||
#define VOP_LOCK(v) (v)->ops->lock(v)
|
||||
#define VOP_UNLOCK(v) (v)->ops->unlock(v)
|
||||
|
||||
@@ -39,7 +39,7 @@ int trie_insert_preallocated(trie_t *trie, uint64_t key, void *value, trie_preal
|
||||
void trie_free_preallocation(trie_preallocation_t *preallocation);
|
||||
int trie_lookup(trie_t *trie, uint64_t key, void **ret);
|
||||
int trie_remove(trie_t *trie, uint64_t key);
|
||||
void trie_truncate(trie_t *trie, uint64_t max_key);
|
||||
void trie_truncate(trie_t *trie, uint64_t min_key);
|
||||
void trie_iterate(trie_t *trie, uint64_t min_key, uint64_t max_key, trie_iterate_fn_t);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user