Skip to content

Commit

Permalink
tweak kalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 10, 2007
1 parent 9736728 commit 3d14528
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ kinit(void)
void
kfree(char *v, int len)
{
struct run **rr;
struct run *p = (struct run*)v;
struct run *pend = (struct run*)(v + len);
struct run **rr, *p, *pend;

if(len % PAGE)
panic("kfree");
Expand All @@ -58,7 +56,8 @@ kfree(char *v, int len)
memset(v, 1, len);

acquire(&kalloc_lock);

p = (struct run*)v;
pend = (struct run*)(v + len);
rr = &freelist;
while(*rr){
struct run *rend = (struct run*) ((char*)(*rr) + (*rr)->len);
Expand Down Expand Up @@ -100,7 +99,8 @@ kfree(char *v, int len)
char*
kalloc(int n)
{
struct run **rr;
char *p;
struct run *r, **rr;

if(n % PAGE)
panic("kalloc");
Expand All @@ -109,15 +109,15 @@ kalloc(int n)

rr = &freelist;
while(*rr){
struct run *r = *rr;
r = *rr;
if(r->len == n){
*rr = r->next;
release(&kalloc_lock);
return (char*) r;
}
if(r->len > n){
char *p = (char*)r + (r->len - n);
r->len -= n;
p = (char*)r + r->len;
release(&kalloc_lock);
return p;
}
Expand Down

0 comments on commit 3d14528

Please sign in to comment.