提交 326974a8 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

use kmalloc for vmnodes

上级 9766fb7a
...@@ -37,7 +37,6 @@ struct vmnode { ...@@ -37,7 +37,6 @@ struct vmnode {
uint npages; uint npages;
char *page[128]; char *page[128];
uint ref; uint ref;
uint alloc; // in use?
enum vmntype type; enum vmntype type;
struct inode *ip; struct inode *ip;
uint offset; uint offset;
......
...@@ -258,22 +258,19 @@ struct { ...@@ -258,22 +258,19 @@ struct {
struct vmnode * struct vmnode *
vmn_alloc(uint npg, uint type) vmn_alloc(uint npg, uint type)
{ {
for(uint i = 0; i < NELEM(vmnodes.n); i++) { struct vmnode *n = kmalloc(sizeof(struct vmnode));
struct vmnode *n = &vmnodes.n[i]; if (n == 0)
if(n->alloc == 0 && __sync_bool_compare_and_swap(&n->alloc, 0, 1)) { panic("out of vmnodes");
if(npg > NELEM(n->page)) { if(npg > NELEM(n->page)) {
panic("vmnode too big\n"); panic("vmnode too big\n");
}
for (uint i = 0; i < NELEM(n->page); i++)
n->page[i] = 0;
n->npages = npg;
n->ref = 0;
n->ip = 0;
n->type = type;
return n;
}
} }
panic("out of vmnodes"); for (uint i = 0; i < NELEM(n->page); i++)
n->page[i] = 0;
n->npages = npg;
n->ref = 0;
n->ip = 0;
n->type = type;
return n;
} }
static int static int
...@@ -310,7 +307,7 @@ vmn_free(struct vmnode *n) ...@@ -310,7 +307,7 @@ vmn_free(struct vmnode *n)
if (n->ip) if (n->ip)
iput(n->ip); iput(n->ip);
n->ip = 0; n->ip = 0;
n->alloc = 0; kmfree(n);
} }
void void
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论