예제 #1
0
파일: swap.c 프로젝트: taeguk/OS-pintos
bool swap_store (struct frame *frame)
{
  //printf ("[Debug] swap_store ()! free_list : %s, slot_cnt : %d, max_slot_cnt : %d\n", list_empty (&free_list) ? "empty" : "something", slot_cnt, max_slot_cnt);

  struct swap_slot *slot;
  if (list_empty (&free_list))
    {
      if (slot_cnt >= max_slot_cnt)
        return false;
      slot = malloc (sizeof(struct swap_slot));
      slot->sec_no_start = slot_cnt * SECTORS_PER_SLOT;
      ++slot_cnt;
    }
  else
    {
      slot = list_entry (list_pop_back (&free_list), struct swap_slot, elem);
    }

  //printf ("[Debug]  kiki\n");

  slot->suppage = frame->suppage;
  slot->owner = frame->owner;
  
  swap_write (slot->sec_no_start, frame->kpage, PGSIZE);

  list_push_back (&slot_list, &slot->elem);

  //printf ("[Debug] success of swap_store ()!\n");
  return true;
}
예제 #2
0
void unloadAPage(){
	int pp_id = rand() % allocated_pages_capacity;

	page_virt pv = allocated_pages[pp_id];
	page_phys pp = page_table[pv].pp;

	swap_write(pv, pp);
	page_table[pv].status = SWAPPED;

	allocated_pages[pp_id] = INVALID;
	pm_freePage(pp);

	mmu_invalidatePage(pv);

	allocated_pages_free = pp_id;
}