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

some more reorg

上级 eabc1d9c
...@@ -61,10 +61,10 @@ dosegment(uptr a0, u64 a1) ...@@ -61,10 +61,10 @@ dosegment(uptr a0, u64 a1)
int npg = (va_end - va_start) / PGSIZE; int npg = (va_end - va_start) / PGSIZE;
if (odp) { if (odp) {
if ((vmn = vmn_alloc(npg, ONDEMAND)) == 0) if ((vmn = new vmnode(npg, ONDEMAND)) == 0)
goto bad; goto bad;
} else { } else {
if ((vmn = vmn_allocpg(npg)) == 0) if ((vmn = new vmnode(npg)) == 0)
goto bad; goto bad;
} }
...@@ -93,7 +93,7 @@ static void dostack(uptr a0, u64 a1) ...@@ -93,7 +93,7 @@ static void dostack(uptr a0, u64 a1)
prof_start(dostack_prof); prof_start(dostack_prof);
// Allocate a one-page stack at the top of the (user) address space // Allocate a one-page stack at the top of the (user) address space
if((vmn = vmn_allocpg(USTACKPAGES)) == 0) if((vmn = new vmnode(USTACKPAGES)) == 0)
goto bad; goto bad;
if(args->vmap->insert(vmn, USERTOP-(USTACKPAGES*PGSIZE)) < 0) if(args->vmap->insert(vmn, USERTOP-(USTACKPAGES*PGSIZE)) < 0)
goto bad; goto bad;
...@@ -106,7 +106,7 @@ static void dostack(uptr a0, u64 a1) ...@@ -106,7 +106,7 @@ static void dostack(uptr a0, u64 a1)
goto bad; goto bad;
sp -= strlen(args->argv[argc]) + 1; sp -= strlen(args->argv[argc]) + 1;
sp &= ~7; sp &= ~7;
if(copyout(args->vmap, sp, args->argv[argc], strlen(args->argv[argc]) + 1) < 0) if(args->vmap->copyout(sp, args->argv[argc], strlen(args->argv[argc]) + 1) < 0)
goto bad; goto bad;
ustack[1+argc] = sp; ustack[1+argc] = sp;
} }
...@@ -118,7 +118,7 @@ static void dostack(uptr a0, u64 a1) ...@@ -118,7 +118,7 @@ static void dostack(uptr a0, u64 a1)
args->proc->tf->rsi = sp - (argc+1)*8; args->proc->tf->rsi = sp - (argc+1)*8;
sp -= (1+argc+1) * 8; sp -= (1+argc+1) * 8;
if(copyout(args->vmap, sp, ustack, (1+argc+1)*8) < 0) if(args->vmap->copyout(sp, ustack, (1+argc+1)*8) < 0)
goto bad; goto bad;
// Save program name for debugging. // Save program name for debugging.
...@@ -144,7 +144,7 @@ static void doheap(uptr a0, u64 a1) ...@@ -144,7 +144,7 @@ static void doheap(uptr a0, u64 a1)
prof_start(doheap_prof); prof_start(doheap_prof);
// Allocate a vmnode for the heap. // Allocate a vmnode for the heap.
// XXX pre-allocate 32 pages.. // XXX pre-allocate 32 pages..
if((vmn = vmn_allocpg(32)) == 0) if((vmn = new vmnode(32)) == 0)
goto bad; goto bad;
if(args->vmap->insert(vmn, BRK) < 0) if(args->vmap->insert(vmn, BRK) < 0)
goto bad; goto bad;
...@@ -161,7 +161,7 @@ int ...@@ -161,7 +161,7 @@ int
exec(char *path, char **argv) exec(char *path, char **argv)
{ {
struct inode *ip = NULL; struct inode *ip = NULL;
struct vmap *vmap = NULL; struct vmap *vmp = NULL;
struct vmnode *vmn = NULL; struct vmnode *vmn = NULL;
struct elfhdr elf; struct elfhdr elf;
struct proghdr ph; struct proghdr ph;
...@@ -183,14 +183,14 @@ exec(char *path, char **argv) ...@@ -183,14 +183,14 @@ exec(char *path, char **argv)
if(elf.magic != ELF_MAGIC) if(elf.magic != ELF_MAGIC)
goto bad; goto bad;
if((vmap = vmap_alloc()) == 0) if((vmp = new vmap()) == 0)
goto bad; goto bad;
// Arguments for work queue // Arguments for work queue
struct eargs args; struct eargs args;
args.proc = myproc(); args.proc = myproc();
args.ip = ip; args.ip = ip;
args.vmap = vmap; args.vmap = vmp;
args.path = path; args.path = path;
args.argv = argv; args.argv = argv;
...@@ -225,7 +225,7 @@ exec(char *path, char **argv) ...@@ -225,7 +225,7 @@ exec(char *path, char **argv)
// Commit to the user image. // Commit to the user image.
oldvmap = myproc()->vmap; oldvmap = myproc()->vmap;
myproc()->vmap = vmap; myproc()->vmap = vmp;
myproc()->brk = BRK + 8; // XXX so that brk-1 points within heap vma.. myproc()->brk = BRK + 8; // XXX so that brk-1 points within heap vma..
myproc()->tf->rip = elf.entry; // main myproc()->tf->rip = elf.entry; // main
...@@ -238,8 +238,8 @@ exec(char *path, char **argv) ...@@ -238,8 +238,8 @@ exec(char *path, char **argv)
bad: bad:
cprintf("exec failed\n"); cprintf("exec failed\n");
if(vmap) if(vmp)
vmap->decref(); vmp->decref();
if(vmn) if(vmn)
delete vmn; delete vmn;
gc_end_epoch(); gc_end_epoch();
......
...@@ -18,3 +18,13 @@ class rcu_freed { ...@@ -18,3 +18,13 @@ class rcu_freed {
virtual void do_gc(void) = 0; virtual void do_gc(void) = 0;
} __mpalign__; } __mpalign__;
void gc_begin_epoch();
void gc_end_epoch();
class scoped_gc_epoch {
public:
scoped_gc_epoch() { gc_begin_epoch(); }
~scoped_gc_epoch() { gc_end_epoch(); }
};
...@@ -97,8 +97,6 @@ void dir_flush(struct inode *dp); ...@@ -97,8 +97,6 @@ void dir_flush(struct inode *dp);
// gc.c // gc.c
void initgc(void); void initgc(void);
void initprocgc(struct proc *); void initprocgc(struct proc *);
void gc_begin_epoch();
void gc_end_epoch();
void gc_start(void); void gc_start(void);
#ifdef __cplusplus #ifdef __cplusplus
...@@ -249,12 +247,6 @@ void uartputc(char c); ...@@ -249,12 +247,6 @@ void uartputc(char c);
void uartintr(void); void uartintr(void);
// vm.c // vm.c
enum vmntype { EAGER, ONDEMAND };
struct vmap * vmap_alloc(void);
struct vmnode* vmn_alloc(u64, enum vmntype);
struct vmnode* vmn_allocpg(u64);
int copyout(struct vmap *, uptr, void*, u64);
void switchuvm(struct proc*); void switchuvm(struct proc*);
void switchkvm(void); void switchkvm(void);
int pagefault(struct vmap *, uptr, u32); int pagefault(struct vmap *, uptr, u32);
......
...@@ -14,12 +14,6 @@ using std::atomic; ...@@ -14,12 +14,6 @@ using std::atomic;
#define NHASH 30 #define NHASH 30
#endif #endif
class scoped_gc_epoch {
public:
scoped_gc_epoch() { gc_begin_epoch(); }
~scoped_gc_epoch() { gc_end_epoch(); }
};
template<class K, class V> template<class K, class V>
class xelem : public rcu_freed { class xelem : public rcu_freed {
public: public:
......
...@@ -274,15 +274,14 @@ inituser(void) ...@@ -274,15 +274,14 @@ inituser(void)
p = allocproc(); p = allocproc();
bootproc = p; bootproc = p;
if((p->vmap = vmap_alloc()) == 0) if((p->vmap = new vmap()) == 0)
panic("userinit: out of vmaps?"); panic("userinit: out of vmaps?");
struct vmnode *vmn = vmnode *vmn = new vmnode(PGROUNDUP(_initcode_size) / PGSIZE);
vmn_allocpg(PGROUNDUP(_initcode_size) / PGSIZE);
if(vmn == 0) if(vmn == 0)
panic("userinit: vmn_allocpg"); panic("userinit: vmn_allocpg");
if(p->vmap->insert(vmn, 0) < 0) if(p->vmap->insert(vmn, 0) < 0)
panic("userinit: vmap_insert"); panic("userinit: vmap_insert");
if(copyout(p->vmap, 0, _initcode_start, _initcode_size) < 0) if(p->vmap->copyout(0, _initcode_start, _initcode_size) < 0)
panic("userinit: copyout"); panic("userinit: copyout");
memset(p->tf, 0, sizeof(*p->tf)); memset(p->tf, 0, sizeof(*p->tf));
p->tf->cs = UCSEG | 0x3; p->tf->cs = UCSEG | 0x3;
...@@ -464,7 +463,7 @@ growproc(int n) ...@@ -464,7 +463,7 @@ growproc(int n)
return -1; return -1;
} }
struct vmnode *vmn = vmn_allocpg(PGROUNDUP(newn) / PGSIZE); vmnode *vmn = new vmnode(PGROUNDUP(newn) / PGSIZE);
if(vmn == 0){ if(vmn == 0){
release(&m->lock); release(&m->lock);
cprintf("growproc: vmn_allocpg failed\n"); cprintf("growproc: vmn_allocpg failed\n");
...@@ -680,7 +679,7 @@ threadalloc(void (*fn)(void *), void *arg) ...@@ -680,7 +679,7 @@ threadalloc(void (*fn)(void *), void *arg)
if (p == NULL) if (p == NULL)
return 0; return 0;
p->vmap = vmap_alloc(); p->vmap = new vmap();
if (p->vmap == NULL) { if (p->vmap == NULL) {
freeproc(p); freeproc(p);
return 0; return 0;
......
...@@ -110,7 +110,7 @@ sys_map(void) ...@@ -110,7 +110,7 @@ sys_map(void)
if (argint64(1, &len) < 0) if (argint64(1, &len) < 0)
return -1; return -1;
struct vmnode *vmn = vmn_allocpg(PGROUNDUP(len) / PGSIZE); vmnode *vmn = new vmnode(PGROUNDUP(len) / PGSIZE);
if (vmn == 0) if (vmn == 0)
return -1; return -1;
......
差异被折叠。
...@@ -4,9 +4,32 @@ ...@@ -4,9 +4,32 @@
using std::atomic; using std::atomic;
// A memory object (physical pages or inode).
enum vmntype { EAGER, ONDEMAND };
struct vmnode {
u64 npages;
char *page[128];
atomic<u64> ref;
enum vmntype type;
struct inode *ip;
u64 offset;
u64 sz;
vmnode(u64 npg, vmntype type = EAGER);
~vmnode();
void decref();
int allocpg();
vmnode* copy();
int load(inode *ip, u64 offset, u64 sz);
int demand_load();
};
// 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 : public rcu_freed { 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
...@@ -25,25 +48,6 @@ struct vma : public rcu_freed { ...@@ -25,25 +48,6 @@ struct vma : public rcu_freed {
virtual void do_gc() { delete this; } virtual void do_gc() { delete this; }
}; };
// A memory object (physical pages or inode).
struct vmnode {
u64 npages;
char *page[128];
atomic<u64> ref;
enum vmntype type;
struct inode *ip;
u64 offset;
u64 sz;
vmnode(u64 npg, vmntype type);
~vmnode();
void decref();
int allocpg();
int load(inode *ip, u64 offset, u64 sz);
int demand_load();
};
// An address space: a set of vmas plus h/w page table. // An address space: a set of vmas plus h/w page table.
// The elements of e[] are not ordered by address. // The elements of e[] are not ordered by address.
struct vmap { struct vmap {
...@@ -63,4 +67,11 @@ struct vmap { ...@@ -63,4 +67,11 @@ struct vmap {
vma* lookup(uptr start, uptr len); vma* lookup(uptr start, uptr len);
int insert(vmnode *n, uptr va_start); int insert(vmnode *n, uptr va_start);
int remove(uptr start, uptr len); int remove(uptr start, uptr len);
int pagefault(uptr va, u32 err);
int copyout(uptr va, void *p, u64 len);
private:
vma* pagefault_ondemand(uptr va, u32 err, vma *m);
int pagefault_wcow(uptr va, pme_t *pte, vma *m, u64 npg);
}; };
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论