提交 f66a86ef 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

make vma objects rcu_freed

上级 8e75c72a
...@@ -12,11 +12,11 @@ extern "C" { ...@@ -12,11 +12,11 @@ extern "C" {
} }
#include "file.hh" #include "file.hh"
#include "vm.hh"
extern "C" { extern "C" {
#include "elf.h" #include "elf.h"
#include "cpu.h" #include "cpu.h"
#include "vm.h"
#include "prof.h" #include "prof.h"
#include <stddef.h> #include <stddef.h>
} }
......
...@@ -10,10 +10,11 @@ extern "C" { ...@@ -10,10 +10,11 @@ extern "C" {
#include "queue.h" #include "queue.h"
#include "condvar.h" #include "condvar.h"
#include "proc.h" #include "proc.h"
#include "vm.h"
#include <stddef.h> #include <stddef.h>
} }
#include "vm.hh"
extern pml4e_t kpml4[]; extern pml4e_t kpml4[];
static pme_t* static pme_t*
......
...@@ -5,12 +5,12 @@ extern "C" { ...@@ -5,12 +5,12 @@ extern "C" {
#include "condvar.h" #include "condvar.h"
#include "cpu.h" #include "cpu.h"
#include "proc.h" #include "proc.h"
#include "vm.h"
#include "fs.h" #include "fs.h"
#include "wq.h" #include "wq.h"
#include "ipc.h" #include "ipc.h"
} }
#include "vm.hh"
#include "file.hh" #include "file.hh"
static void static void
......
...@@ -10,10 +10,10 @@ extern "C" { ...@@ -10,10 +10,10 @@ extern "C" {
#include "cpu.h" #include "cpu.h"
#include "bits.h" #include "bits.h"
#include "kmtrace.h" #include "kmtrace.h"
#include "vm.h"
#include "sched.h" #include "sched.h"
} }
#include "vm.hh"
#include "ns.hh" #include "ns.hh"
u64 u64
......
...@@ -10,11 +10,12 @@ extern "C" { ...@@ -10,11 +10,12 @@ extern "C" {
#include "cpu.h" #include "cpu.h"
#include "bits.h" #include "bits.h"
#include "kmtrace.h" #include "kmtrace.h"
#include "vm.h"
#include "sched.h" #include "sched.h"
#include <stddef.h> #include <stddef.h>
} }
#include "vm.hh"
enum { sched_debug = 0 }; enum { sched_debug = 0 };
struct runq { struct runq {
......
...@@ -8,9 +8,10 @@ extern "C" { ...@@ -8,9 +8,10 @@ extern "C" {
#include "queue.h" #include "queue.h"
#include "proc.h" #include "proc.h"
#include "cpu.h" #include "cpu.h"
#include "vm.h"
} }
#include "vm.hh"
long long
sys_fork(void) sys_fork(void)
{ {
......
...@@ -10,28 +10,15 @@ extern "C" { ...@@ -10,28 +10,15 @@ extern "C" {
#include "queue.h" #include "queue.h"
#include "condvar.h" #include "condvar.h"
#include "proc.h" #include "proc.h"
#include "vm.h"
} }
#include "vm.hh"
#include "gc.hh" #include "gc.hh"
static void vmap_free(void *p); static void vmap_free(void *p);
enum { vm_debug = 0 }; enum { vm_debug = 0 };
static struct vma *
vma_alloc(void)
{
struct vma *e = (struct vma *) kmalloc(sizeof(struct vma));
if (e == 0)
return 0;
memset(e, 0, sizeof(struct vma));
e->va_type = PRIVATE;
snprintf(e->lockname, sizeof(e->lockname), "vma:%p", e);
initlock(&e->lock, e->lockname, LOCKSTAT_VM);
return e;
}
static void static void
vmn_decref(struct vmnode *n) vmn_decref(struct vmnode *n)
{ {
...@@ -39,27 +26,13 @@ vmn_decref(struct vmnode *n) ...@@ -39,27 +26,13 @@ vmn_decref(struct vmnode *n)
vmn_free(n); vmn_free(n);
} }
static void vma::~vma()
vma_free(void *p)
{ {
struct vma *e = (struct vma *) p; if(n)
if(e->n) vmn_decref(n);
vmn_decref(e->n); destroylock(&lock);
destroylock(&e->lock);
kmfree(e);
} }
class vma_delayed : public rcu_freed {
private:
vma *_e;
public:
vma_delayed(vma *e) : rcu_freed("vma_delayed"), _e(e) {}
virtual ~vma_delayed() {
vma_free(_e);
}
};
static int static int
vmn_doallocpg(struct vmnode *n) vmn_doallocpg(struct vmnode *n)
{ {
...@@ -342,7 +315,7 @@ struct state { ...@@ -342,7 +315,7 @@ struct state {
static int static int
vmap_free_vma(struct clist_range *r, void *st) vmap_free_vma(struct clist_range *r, void *st)
{ {
vma_free(r->value); delete r->value;
crange_del(r->cr, r->key, r->size); crange_del(r->cr, r->key, r->size);
return 1; return 1;
} }
...@@ -398,7 +371,7 @@ vmap_insert(struct vmap *m, struct vmnode *n, uptr va_start) ...@@ -398,7 +371,7 @@ vmap_insert(struct vmap *m, struct vmnode *n, uptr va_start)
return -1; return -1;
} }
struct vma *e = vma_alloc(); struct vma *e = new vma();
if (e == 0) { if (e == 0) {
release(&m->lock); release(&m->lock);
return -1; return -1;
...@@ -417,7 +390,7 @@ vmap_copy_vma(struct clist_range *r, void *_st) ...@@ -417,7 +390,7 @@ vmap_copy_vma(struct clist_range *r, void *_st)
{ {
struct state *st = (struct state *) _st; struct state *st = (struct state *) _st;
struct vma *e = (struct vma *) r->value; struct vma *e = (struct vma *) r->value;
struct vma *c = vma_alloc(); struct vma *c = new vma();
if (c == 0) { if (c == 0) {
return 0; return 0;
} }
...@@ -482,9 +455,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len) ...@@ -482,9 +455,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len)
return -1; return -1;
} }
crange_del(m->cr, va_start, len); crange_del(m->cr, va_start, len);
gc_delayed(e);
vma_delayed *vd = new vma_delayed(e);
gc_delayed(vd);
release(&m->lock); release(&m->lock);
return 0; return 0;
} }
...@@ -497,7 +468,7 @@ vmap_free(void *p) ...@@ -497,7 +468,7 @@ vmap_free(void *p)
struct vmap *m = (struct vmap *) p; struct vmap *m = (struct vmap *) p;
for(u64 i = 0; i < NELEM(m->e); i++) { for(u64 i = 0; i < NELEM(m->e); i++) {
if (m->e[i]) if (m->e[i])
vma_free(m->e[i]); delete m->e[i];
} }
freevm(m->pml4); freevm(m->pml4);
m->pml4 = 0; m->pml4 = 0;
...@@ -543,7 +514,7 @@ vmap_insert(struct vmap *m, struct vmnode *n, uptr va_start) ...@@ -543,7 +514,7 @@ vmap_insert(struct vmap *m, struct vmnode *n, uptr va_start)
for(u64 i = 0; i < NELEM(m->e); i++) { for(u64 i = 0; i < NELEM(m->e); i++) {
if(m->e[i]) if(m->e[i])
continue; continue;
m->e[i] = vma_alloc(); m->e[i] = new vma();
if (m->e[i] == 0) if (m->e[i] == 0)
return -1; return -1;
m->e[i]->va_start = va_start; m->e[i]->va_start = va_start;
...@@ -570,7 +541,7 @@ vmap_copy(struct vmap *m, int share) ...@@ -570,7 +541,7 @@ vmap_copy(struct vmap *m, int share)
for(u32 i = 0; i < NELEM(m->e); i++) { for(u32 i = 0; i < NELEM(m->e); i++) {
if(m->e[i] == 0) if(m->e[i] == 0)
continue; continue;
c->e[i] = vma_alloc(); c->e[i] = new vma();
if (c->e[i] == 0) { if (c->e[i] == 0) {
release(&m->lock); release(&m->lock);
vmap_free(c); vmap_free(c);
...@@ -616,8 +587,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len) ...@@ -616,8 +587,7 @@ vmap_remove(struct vmap *m, uptr va_start, u64 len)
cprintf("vmap_remove: partial unmap unsupported\n"); cprintf("vmap_remove: partial unmap unsupported\n");
return -1; return -1;
} }
vma_delayed *vd = new vma_delayed(m->e[i]); gc_delayed(m->e[i]);
gc_delayed(vd);
m->e[i] = 0; m->e[i] = 0;
} }
} }
......
//#define TREE //#define TREE
#include "gc.hh"
// A mapping of a chunk of an address space to // A mapping of a chunk of an address space to
// a specific memory object. // a specific memory object.
enum vmatype { PRIVATE, COW}; enum vmatype { PRIVATE, COW};
struct vma { struct vma : public rcu_freed {
uptr va_start; // start of mapping uptr va_start; // start of mapping
uptr va_end; // one past the last byte uptr va_end; // one past the last byte
enum vmatype va_type; enum vmatype va_type;
struct vmnode *n; struct vmnode *n;
struct spinlock lock; // serialize fault/unmap struct spinlock lock; // serialize fault/unmap
char lockname[16]; char lockname[16];
vma() : rcu_freed("vma"), va_start(0), va_end(0), va_type(PRIVATE), n(0) {
snprintf(lockname, sizeof(lockname), "vma:%p", this);
initlock(&lock, lockname, LOCKSTAT_VM);
}
virtual ~vma();
}; };
// A memory object (physical pages or inode). // A memory object (physical pages or inode).
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论