kalloc.c
// 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 .
char*
kalloc(void)
{
  struct run *r;
  if(kmem.use_lock)
    acquire(&kmem.lock);
  r = kmem.freelist;
  if(r){
    kmem.freelist = r->next;
    kmem.refsCount[V2P((char*)r) >> PGSHIFT] = 1;     
  }
  if(kmem.use_lock)
    release(&kmem.lock);
  return (char*)r;
}
char * kalloc ( void ) { struct run * r ; if ( kmem . use_lock ) acquire ( & kmem . lock ) ; r = kmem . freelist ; if ( r ) { kmem . freelist = r -> next ; kmem . refsCount [ V2P ( ( char * ) r ) >> PGSHIFT ] = 1 ; } if ( kmem . use_lock ) release ( & kmem . lock ) ; return ( char * ) r ; }
Allocate one 4096-byte page of physical memory.
Allocate one 4096 - byte page of physical memory .
// reference count of a page is set to one when it is allocated