예제 #1
0
/* Frees the PAGE_CNT pages starting at PAGES. */
void
palloc_free_multiple (void *pages, size_t page_cnt) 
{
  struct pool *pool;
  size_t page_idx;

  ASSERT (pg_ofs (pages) == 0);
  if (pages == NULL || page_cnt == 0)
    return;

  if (page_from_pool (&kernel_pool, pages))
    pool = &kernel_pool;
  else if (page_from_pool (&user_pool, pages))
    pool = &user_pool;
  else
    NOT_REACHED ();

  page_idx = pg_no (pages) - pg_no (pool->base);

#ifndef NDEBUG
  memset (pages, 0xcc, PGSIZE * page_cnt);
#endif

  ASSERT (bitmap_all (pool->used_map, page_idx, page_cnt));
  bitmap_set_multiple (pool->used_map, page_idx, page_cnt, false);
}
예제 #2
0
/* Makes CNT sectors starting at SECTOR available for use. */
void
free_map_release (block_sector_t sector, size_t cnt)
{
  ASSERT (bitmap_all (free_map, sector, cnt));
  bitmap_set_multiple (free_map, sector, cnt, false);
  bitmap_write (free_map, free_map_file);
}
예제 #3
0
// all the used swap slots are set to TRUE
void
swap_read_and_free (disk_sector_t idx, void *upage)
{
  lock_acquire (&swap_table_lock);
  // all the swap sectors must be in use
  // bitmap_all returns true if all pages are in use (i.e. TRUE)
  // take care of the edge cases
  ASSERT (idx != SECTOR_ERROR);
  ASSERT (bitmap_all (swap_table, idx, SLOT_SIZE));

  struct disk *swap = disk_get (1,1);
  if (!swap)
    PANIC ("No swap disk found\n");

  // read in the upage buffer
  int offset;
  for (offset = 0; offset < SLOT_SIZE; offset++) {
  //  printf ("Swap read sector %d at address %p\n",idx+offset, upage +(offset * DISK_SECTOR_SIZE));
    disk_read (swap, idx + offset, upage + (offset * DISK_SECTOR_SIZE));
  }

  // vacant the swap slot
  bitmap_set_multiple (swap_table, idx, SLOT_SIZE, false);

  lock_release (&swap_table_lock);
//  printf ("Swap read called at %d for %p\n",idx,upage);
}
예제 #4
0
파일: swap.c 프로젝트: xuruiyang/CS5600
/*
 * reload page back to a frame, given the slot index.
 * re-establish page mapping from given page user
 * virtual memory to the frame.
 */
struct frame_table_entry* swap_reload_pg(uint32_t slot_idx, uint8_t* pg_vaddr){
	ASSERT(swap_blk!=NULL);
	bool already_locked = lock_held_by_current_thread (&swap_lock);
	if(!already_locked){
		lock_acquire (&swap_lock);
	}
//	printf("reload> id=%d , slot_idx = %d\n",thread_current()->tid, slot_idx);
	ASSERT (bitmap_all (swap_table, slot_idx, 1));
	struct frame_table_entry* fte = frame_get_new_page(true);
	fte->pg_vaddr = pg_vaddr;
	int i;
	for(i=0;i<8;i++){
		block_read (swap_blk,
				slot_idx*8+i,
				fte->kpg_vaddr+i*BLOCK_SECTOR_SIZE);
	}
//	printf("swap_reload_pg An unassigned value look : %p\n",fte->pg_vaddr);
	if(!install_page (pg_vaddr, fte->kpg_vaddr, true))
		PANIC("Unable to restore page from swap space!");
	bitmap_set_multiple (swap_table, slot_idx, 1, false);
	if(!already_locked){
		lock_release (&swap_lock);
	}
	fte->pinned = false;
	return fte;
}
예제 #5
0
파일: swap.c 프로젝트: xuruiyang/CS5600
void swap_destroy_pg(uint32_t slot_idx){
	ASSERT(swap_blk!=NULL);
	lock_acquire (&swap_lock);
	ASSERT (bitmap_all (swap_table, slot_idx, 1));
//	printf("destroy> id=%d , slot_idx = %d\n",thread_current()->tid, slot_idx);
	bitmap_set_multiple (swap_table, slot_idx, 1, false);
	lock_release (&swap_lock);
}
예제 #6
0
파일: allocator.c 프로젝트: cmcgrady/Pintos
void allocator_free (struct allocator *a, void *base, size_t amount)
{
  ASSERT (a != NULL);
  if (base == NULL || amount == 0)
    return;
  ASSERT (base >= a->items);
  ASSERT (base <= item_pos (a, bitmap_size (a->used_map)-1));
  size_t pos = (uintptr_t) (base - a->items) / a->item_size;
  ASSERT (bitmap_all (a->used_map, pos, amount));
  bitmap_set_multiple (a->used_map, pos, amount, false);
}
예제 #7
0
/* Makes CNT sectors starting at SECTOR available for use. */
void
free_map_release (disk_sector_t sector, size_t cnt)
{
  // lås id 6
  lock_acquire(&free_map_lock);
  
  ASSERT (bitmap_all (free_map, sector, cnt));
  bitmap_set_multiple (free_map, sector, cnt, false);
  bitmap_write (free_map, free_map_file);
  
  lock_release(&free_map_lock);
}