void pt_page_in(vaddr_t vaddr, struct segment *s) { int spl = splhigh(); _vmstats_inc(VMSTAT_TLB_FAULT); //get the page detail int pt_offset_id = (vaddr - s->vbase) / PAGE_SIZE; struct page_detail *pd = &(s->pt->page_details[pt_offset_id]); if (pd->valid && pd->pfn != -1){ pd->use = 1; _vmstats_inc(VMSTAT_TLB_RELOAD); tlb_add_entry(vaddr, pd->pfn*PAGE_SIZE, s->writeable, 1); splx(spl); return; }else if(pd->sfn != -1){ splx(spl); pd->use = 1; pd->pfn = cm_getppage(); swap_read(pd->pfn,pd->sfn); pd->sfn = -1; //add the tlb entry tlb_add_entry(vaddr, pd->pfn*PAGE_SIZE, s->writeable, 1); //finish the load cm_finish_paging(pd->pfn, pd); }else{ splx(spl); pd->use = 1; pd->pfn = cm_getppage(); load_segment_page(curthread->t_vmspace->file, vaddr, s, pd->pfn*PAGE_SIZE); //add the tlb entry tlb_add_entry(vaddr, pd->pfn*PAGE_SIZE, s->writeable, 1); //finish the load cm_finish_paging(pd->pfn, pd); } }
int16_t whatsUpWithTheFrame(struct virtual_memory_manager *vmm, uint16_t pageNum) { int16_t frameNum = -1; frameNum = tlb_lookup (&vmm->tlb, pageNum); if (frameNum == -1) { //tlb lookup failed printf ("Page not in TLB. Bummer.\n"); vmm->tlb_miss_count++; if (vmm->page_table[pageNum].flags & 0x1) //if verification bit, aka if page is loaded { vmm->page_found_count++; frameNum = vmm->page_table[pageNum].frame_number; tlb_add_entry (&vmm->tlb, pageNum, frameNum); } else { /* page fault 1. find free frame 2. read page from backing store 3. place read page in frame 4. set page verification flag */ printf ("This page seems to be all hidey and not loaded. Let's take care of that...\n"); frameNum = pm_demand_page (&vmm->pm, pageNum); // pm_backup_frame(&vmm->pm,frameNum,pageNum); vmm->page_table[pageNum].frame_number = frameNum; vmm->page_table[pageNum].flags |= 0x1; //page is loaded. set verification bit vmm->page_fault_count++; } } else { vmm->tlb_hit_count++; vmm->page_found_count++; } return frameNum; }