kernel/kalloc.c
void *
kalloc(void)
{
  struct run *r;

  acquire(&kmem.lock);
  r = kmem.freelist;
  if(r) {
    kmem.freelist = r->next;
    kmem.npage--;
  }
  release(&kmem.lock);

  if(r)
    memset((char*)r, 5, PGSIZE); // fill with junk
  return (void*)r;
}
// Allocate one 4096-byte page of physical memory.
// Returns a pointer that the kernel can use.
// Returns 0 if the memory cannot be allocated.
Allocate one 4096-byte page of physical memory.
Returns a pointer that the kernel can use.
Returns 0 if the memory cannot be allocated.
Allocate one 4096 - byte page of physical memory . Returns a pointer that the kernel can use . Returns 0 if the memory cannot be allocated .
void *
kalloc(void)
{
  struct run *r;
  acquire(&kmem.lock);
  r = kmem.freelist;
  if(r) {
    kmem.freelist = r->next;
    kmem.npage--;
  }
  release(&kmem.lock);
  if(r)
    memset((char*)r, 5, PGSIZE); 
  return (void*)r;
}
void * kalloc ( void ) { struct run * r ; acquire ( & kmem . lock ) ; r = kmem . freelist ; if ( r ) { kmem . freelist = r -> next ; kmem . npage -- ; } release ( & kmem . lock ) ; if ( r ) memset ( ( char * ) r , 5 , PGSIZE ) ; return ( void * ) r ; }
Allocate one 4096-byte page of physical memory.
Allocate one 4096 - byte page of physical memory .
// fill with junk