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
|
void
|
||||||
kfree(char *v, int len)
|
kfree(char *v, int len)
|
||||||
{
|
{
|
||||||
struct run **rr;
|
struct run **rr, *p, *pend;
|
||||||
struct run *p = (struct run*)v;
|
|
||||||
struct run *pend = (struct run*)(v + len);
|
|
||||||
|
|
||||||
if(len % PAGE)
|
if(len % PAGE)
|
||||||
panic("kfree");
|
panic("kfree");
|
||||||
|
@ -58,7 +56,8 @@ kfree(char *v, int len)
|
||||||
memset(v, 1, len);
|
memset(v, 1, len);
|
||||||
|
|
||||||
acquire(&kalloc_lock);
|
acquire(&kalloc_lock);
|
||||||
|
p = (struct run*)v;
|
||||||
|
pend = (struct run*)(v + len);
|
||||||
rr = &freelist;
|
rr = &freelist;
|
||||||
while(*rr){
|
while(*rr){
|
||||||
struct run *rend = (struct run*) ((char*)(*rr) + (*rr)->len);
|
struct run *rend = (struct run*) ((char*)(*rr) + (*rr)->len);
|
||||||
|
@ -100,7 +99,8 @@ kfree(char *v, int len)
|
||||||
char*
|
char*
|
||||||
kalloc(int n)
|
kalloc(int n)
|
||||||
{
|
{
|
||||||
struct run **rr;
|
char *p;
|
||||||
|
struct run *r, **rr;
|
||||||
|
|
||||||
if(n % PAGE)
|
if(n % PAGE)
|
||||||
panic("kalloc");
|
panic("kalloc");
|
||||||
|
@ -109,15 +109,15 @@ kalloc(int n)
|
||||||
|
|
||||||
rr = &freelist;
|
rr = &freelist;
|
||||||
while(*rr){
|
while(*rr){
|
||||||
struct run *r = *rr;
|
r = *rr;
|
||||||
if(r->len == n){
|
if(r->len == n){
|
||||||
*rr = r->next;
|
*rr = r->next;
|
||||||
release(&kalloc_lock);
|
release(&kalloc_lock);
|
||||||
return (char*) r;
|
return (char*) r;
|
||||||
}
|
}
|
||||||
if(r->len > n){
|
if(r->len > n){
|
||||||
char *p = (char*)r + (r->len - n);
|
|
||||||
r->len -= n;
|
r->len -= n;
|
||||||
|
p = (char*)r + r->len;
|
||||||
release(&kalloc_lock);
|
release(&kalloc_lock);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue