AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vm_object.c
Go to the documentation of this file.
1
6
7#include <core/system.h>
8#include <core/arch.h>
9#include <core/panic.h>
10#include <mm/mm.h>
11#include <mm/vm.h>
12#include <ds/queue.h>
13#include <ds/hashmap.h>
14#include <fs/vfs.h>
15
16MALLOC_DEFINE(M_VM_OBJECT, "vm-object", "virtual memory object");
17
26{
27 if (!vm_object->ref++ && vm_object->type == VMOBJ_FILE)
28 ((struct vnode *) vm_object->p)->ref++;
29}
30
39{
40 if (!--vm_object->ref && vm_object->type == VMOBJ_FILE)
41 vfs_close((struct vnode *) vm_object->p);
42}
43
53{
54 size_t off = vm_page->off;
55 hash_t hash = hashmap_digest(&off, sizeof(off));
56 return hashmap_insert(vm_object->pages, hash, vm_page) ? -ENOMEM : 0;
57}
int vfs_close(struct vnode *vnode)
Drops a reference to a vnode.
Definition close.c:18
uintptr_t hash_t
Definition hashmap.h:22
#define MALLOC_DEFINE(type, _name, _desc)
Definition kvmem.h:30
A vm object: what a mapping's pages come from (a file), and its pages that have been read in.
Definition vm.h:132
size_t ref
how many mappings it has
Definition vm.h:140
void * p
the pager's own data (a file's vnode)
Definition vm.h:146
int type
its kind (VMOBJ_*)
Definition vm.h:137
struct hashmap * pages
its pages that have been read in, by their offset
Definition vm.h:134
A page of physical memory (pages[] has one for every page of RAM).
Definition vm.h:150
size_t off
its offset in its object or anon
Definition vm.h:155
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
size_t ref
how many references there are to it
Definition vfs.h:133
#define VMOBJ_FILE
a file's pages
Definition vm.h:60
void vm_object_decref(struct vm_object *vm_object)
Drops a reference to a vm object: one mapping of it less.
Definition vm_object.c:38
int vm_object_page_insert(struct vm_object *vm_object, struct vm_page *vm_page)
Adds a page to a vm object, at the page's offset (vm_page->off).
Definition vm_object.c:52
void vm_object_incref(struct vm_object *vm_object)
Adds a reference to a vm object: one more mapping of it.
Definition vm_object.c:25