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

pre-split memory between per-cpu free lists

上级 c99284eb
...@@ -32,32 +32,13 @@ kmemprint(void) ...@@ -32,32 +32,13 @@ kmemprint(void)
cprintf("]\n"); cprintf("]\n");
} }
// Initialize free list of physical pages.
void
kinit(void)
{
char *p;
for (int c = 0; c < NCPU; c++) {
kmems[c].name[0] = (char) c + '0';
safestrcpy(kmems[c].name+1, "kmem", MAXNAME-1);
initlock(&kmems[c].lock, kmems[c].name);
}
p = (char*)PGROUNDUP((uint)end);
for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE)
kfree(p);
kminit();
kinited = 1;
}
//PAGEBREAK: 21 //PAGEBREAK: 21
// Free the page of physical memory pointed at by v, // Free the page of physical memory pointed at by v,
// which normally should have been returned by a // which normally should have been returned by a
// call to kalloc(). (The exception is when // call to kalloc(). (The exception is when
// initializing the allocator; see kinit above.) // initializing the allocator; see kinit above.)
void static void
kfree(char *v) kfree_pool(struct kmem *m, char *v)
{ {
struct run *r; struct run *r;
...@@ -68,7 +49,6 @@ kfree(char *v) ...@@ -68,7 +49,6 @@ kfree(char *v)
if (kinited) if (kinited)
memset(v, 1, PGSIZE); memset(v, 1, PGSIZE);
struct kmem *m = kmem;
acquire(&m->lock); acquire(&m->lock);
r = (struct run*)v; r = (struct run*)v;
r->next = m->freelist; r->next = m->freelist;
...@@ -85,6 +65,31 @@ kfree(char *v) ...@@ -85,6 +65,31 @@ kfree(char *v)
release(&m->lock); release(&m->lock);
} }
void
kfree(char *v)
{
kfree_pool(kmem, v);
}
// Initialize free list of physical pages.
void
kinit(void)
{
char *p;
for (int c = 0; c < NCPU; c++) {
kmems[c].name[0] = (char) c + '0';
safestrcpy(kmems[c].name+1, "kmem", MAXNAME-1);
initlock(&kmems[c].lock, kmems[c].name);
}
p = (char*)PGROUNDUP((uint)end);
for(; p + PGSIZE <= (char*)PHYSTOP; p += PGSIZE)
kfree_pool(&kmems[((uintptr_t)p) / (PHYSTOP/NCPU)], p);
kminit();
kinited = 1;
}
// Allocate one 4096-byte page of physical memory. // Allocate one 4096-byte page of physical memory.
// Returns a pointer that the kernel can use. // Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated. // Returns 0 if the memory cannot be allocated.
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论