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

atomic vm refcounts

上级 d61e3535
......@@ -582,7 +582,7 @@ fork(int flags)
}
} else {
np->vmap = myproc()->vmap;
__sync_fetch_and_add(&np->vmap->ref, 1);
np->vmap->ref++;
}
np->brk = myproc()->brk;
......
......@@ -22,7 +22,7 @@ enum { vm_debug = 0 };
static void
vmn_decref(struct vmnode *n)
{
if(subfetch(&n->ref, 1) == 0)
if(--n->ref == 0)
vmn_free(n);
}
......@@ -84,7 +84,7 @@ vmn_allocpg(u64 npg)
void
vmap_decref(struct vmap *m)
{
if(subfetch(&m->ref, 1) == 0)
if(--m->ref == 0)
vmap_free(m);
}
......@@ -216,7 +216,7 @@ pagefault(struct vmap *vmap, uptr va, u32 err)
if (vm_debug)
cprintf("pagefault: err 0x%x va 0x%lx type %d ref %lu pid %d\n",
err, va, m->va_type, m->n->ref, myproc()->pid);
err, va, m->va_type, (u64) m->n->ref, myproc()->pid);
if (m->va_type == COW && (err & FEC_WR)) {
if (pagefault_wcow(vmap, va, pte, m, npg) < 0) {
......@@ -379,7 +379,7 @@ vmap_insert(struct vmap *m, struct vmnode *n, uptr va_start)
e->va_start = va_start;
e->va_end = va_start + len;
e->n = n;
__sync_fetch_and_add(&n->ref, 1);
n->ref++;
crange_add(m->cr, e->va_start, len, (void *) e);
release(&m->lock);
return 0;
......@@ -410,7 +410,7 @@ vmap_copy_vma(struct range *r, void *_st)
if(c->n == 0) {
return 0;
}
__sync_fetch_and_add(&c->n->ref, 1);
c->n->ref++;
crange_add(st->cr, c->va_start, c->va_end - c->va_start, (void *) c);
return 1;
}
......
#define TREE
#include "gc.hh"
#include "atomic.hh"
// A mapping of a chunk of an address space to
// a specific memory object.
......@@ -27,7 +28,7 @@ struct vma : public rcu_freed {
struct vmnode {
u64 npages;
char *page[128];
u64 ref;
atomic<u64> ref;
enum vmntype type;
struct inode *ip;
u64 offset;
......@@ -44,7 +45,7 @@ struct vmap {
struct vma* e[16];
#endif
struct spinlock lock; // serialize map/lookup/unmap
u64 ref;
atomic<u64> ref;
u64 alloc;
pml4e_t *pml4; // Page table
char *kshared;
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论