Newer
Older
// memory for user processes. Allocates in 4096-byte pages.
// Free list is kept sorted and combines adjacent pages into
// long runs, to make it easier to allocate big segments.
// This combining is not useful now that xv6 uses paging.
kinit(char *p, uint len)
if(len <= 0 || len % PGSIZE)
if(r <= p && p < rend) {
cprintf("freeing a free page: r = 0x%x p = 0x%x rend = 0x%x\n",
r, p, rend);
if(rend == p){ // r before p: expand r to include p
r->len += len;
if(r->next && r->next == pend){ // r now next to r->next?
r->len += r->next->len;
r->next = r->next->next;
if(pend == r){ // p before r: expand p to include, replace r
p->len = len + r->len;
p->next = r->next;
*rp = p;
goto out;
}
// Allocate n bytes of physical memory.
// Returns a kernel-segment pointer.
// Returns 0 if the memory cannot be allocated.
if(n % PGSIZE || n <= 0)