Example #1
0
void init_swap(){
	swap_blk = block_get_role(BLOCK_SWAP);
	ASSERT(swap_blk!=NULL);
	uint32_t sectors_num = block_size (swap_blk);
	// each sector is 512K, one page has 8 sectors
	uint32_t slots_num = sectors_num/8;
	size_t bm_pages = DIV_ROUND_UP (bitmap_buf_size (slots_num), PGSIZE);
	uint8_t* base = palloc_get_multiple (PAL_ZERO|PAL_ASSERT, bm_pages);
	swap_table = bitmap_create_in_buf (slots_num, base, bm_pages * PGSIZE);
	lock_init(&swap_lock);
}
Example #2
0
void buffer_cache_init (void) {
  buffer_vaddr = palloc_get_multiple(PAL_ZERO | PAL_USER, 8);
  if(buffer_vaddr == NULL)
	PANIC("BUFFER PALLOC FAILED!");
  int i;
  for (i=0; i<BUFFER_SIZE; i++){
	buffer_info_array[i].sector_num = -2; 
	buffer_info_array[i].dirty = false;
	buffer_info_array[i].recentlyUsed = false;
  }
}
Example #3
0
/*! Initializes the swap allocator. */
void swalloc_init(void)
{
    uint32_t i;

    swap_disk = block_get_role(BLOCK_SWAP);
    swap_slots = block_size(swap_disk) / PAGE_SECTORS;

    /* Initialize swap table */
    uint32_t num_pages_used = sizeof(struct swap) * swap_slots;
    num_pages_used = (uint32_t) pg_round_up((void *) num_pages_used) / PGSIZE;

    /* Get pages for swap table */
    swap_list = palloc_get_multiple(PAL_ASSERT | PAL_PAGING | PAL_ZERO, num_pages_used);

    /* Initialize list */
    list_init(open_swap_list);
    /* Initialize swap entries */
    for (i = 0; i < swap_slots; ++i)
    {
        swap_list[i].start_sector = i * PAGE_SECTORS;
        swap_list[i].in_use = false;
        list_push_back(open_swap_list, &(swap_list[i].open_elem));
    }
}
Example #4
0
bool
allocator_init (struct allocator *a,
                bool              userspace,
                size_t            members,
                size_t            item_size)
{
  ASSERT (a != NULL);
  ASSERT (members > 0);
  ASSERT (item_size > 0);
  
  memset (a, 0, sizeof (*a));
  a->item_size = item_size;
  a->used_map = bitmap_create (members);
  if (a->used_map == NULL)
    return false;
  size_t pages = (members*item_size + PGSIZE-1) / PGSIZE;
  a->items = palloc_get_multiple (userspace ? PAL_USER : 0, pages);
  if (!a->items)
    {
      bitmap_destroy (a->used_map);
      return false;
    }
  return true;
}
Example #5
0
/* Obtains a single free page and returns its kernel virtual
   address.
   If PAL_USER is set, the page is obtained from the user pool,
   otherwise from the kernel pool.  If PAL_ZERO is set in FLAGS,
   then the page is filled with zeros.  If no pages are
   available, returns a null pointer, unless PAL_ASSERT is set in
   FLAGS, in which case the kernel panics. */
void *
palloc_get_page (enum palloc_flags flags) 
{
  return palloc_get_multiple (flags, 1);
}