tweak kalloc
This commit is contained in:
parent
9736728d23
commit
3d145283a2
1 changed files with 7 additions and 7 deletions
14
kalloc.c
14
kalloc.c
|
@ -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");
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue