kalloc.c
//PAGEBREAK: 21
// Free the page of physical memory pointed at by v,
// which normally should have been returned by a
// call to kalloc().  (The exception is when
// initializing the allocator; see kinit above.)
21
Free the page of physical memory pointed at by v,
which normally should have been returned by a
call to kalloc().  (The exception is when
initializing the allocator; see kinit above.)
21 Free the page of physical memory pointed at by v which normally should have been returned by a call to kalloc () . ( The exception is when initializing the allocator ; see kinit above . )
void
kfree(char *v)
{
  struct run *r;
  if((uint)v % PGSIZE || v < end || V2P(v) >= PHYSTOP)
    panic("kfree");
  if(kmem.use_lock)
    acquire(&kmem.lock);
  r = (struct run*)v;
  if(kmem.refsCount[V2P(v) >> PGSHIFT] > 0)         
    --kmem.refsCount[V2P(v) >> PGSHIFT];
  if(kmem.refsCount[V2P(v) >> PGSHIFT] == 0){       
    memset(v, 1, PGSIZE);
    r->next = kmem.freelist;
    kmem.freelist = r;
  }
  if(kmem.use_lock)
    release(&kmem.lock);
}
void kfree ( char * v ) { struct run * r ; if ( ( uint ) v % PGSIZE || v < end || V2P ( v ) >= PHYSTOP ) panic ( " " ) ; if ( kmem . use_lock ) acquire ( & kmem . lock ) ; r = ( struct run * ) v ; if ( kmem . refsCount [ V2P ( v ) >> PGSHIFT ] > 0 ) -- kmem . refsCount [ V2P ( v ) >> PGSHIFT ] ; if ( kmem . refsCount [ V2P ( v ) >> PGSHIFT ] == 0 ) { memset ( v , 1 , PGSIZE ) ; r -> next = kmem . freelist ; kmem . freelist = r ; } if ( kmem . use_lock ) release ( & kmem . lock ) ; }
PAGEBREAK: 21
Free the page of physical memory pointed at by v,
which normally should have been returned by a
call to kalloc().
PAGEBREAK : 21 Free the page of physical memory pointed at by v which normally should have been returned by a call to kalloc () .
// Decrement the reference count of a page whenever someone frees it // Free the page only if there are no references to the page // Fill with junk to catch dangling refs.