kernel/kalloc.c
void
kfree(void *pa)
{
  struct run *r;
  
  if(((uint64)pa % PGSIZE) != 0 || (char*)pa < kernel_end || (uint64)pa >= PHYSTOP)
    panic("kfree");

  // Fill with junk to catch dangling refs.
  memset(pa, 1, PGSIZE);

  r = (struct run*)pa;

  acquire(&kmem.lock);
  r->next = kmem.freelist;
  kmem.freelist = r;
  kmem.npage++;
  release(&kmem.lock);
}
// 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.)
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.)
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(void *pa)
{
  struct run *r;
  if(((uint64)pa % PGSIZE) != 0 || (char*)pa < kernel_end || (uint64)pa >= PHYSTOP)
    panic("kfree");
  memset(pa, 1, PGSIZE);
  r = (struct run*)pa;
  acquire(&kmem.lock);
  r->next = kmem.freelist;
  kmem.freelist = r;
  kmem.npage++;
  release(&kmem.lock);
}
void kfree ( void * pa ) { struct run * r ; if ( ( ( uint64 ) pa % PGSIZE ) != 0 || ( char * ) pa < kernel_end || ( uint64 ) pa >= PHYSTOP ) panic ( " " ) ; memset ( pa , 1 , PGSIZE ) ; r = ( struct run * ) pa ; acquire ( & kmem . lock ) ; r -> next = kmem . freelist ; kmem . freelist = r ; kmem . npage ++ ; release ( & kmem . lock ) ; }
Free the page of physical memory pointed at by v,
which normally should have been returned by a
call to kalloc().
Free the page of physical memory pointed at by v which normally should have been returned by a call to kalloc () .
// Fill with junk to catch dangling refs.