Exemplo n.º 1
0
        //TODO: should return the frame number
        public void addPage(PageTableEntry pte, int step)
        {
            bool pageAdded             = false;
            int  longestDeltaTime      = 0;
            int  longestDeltaTimeIndex = 0;
            int  index = 0;

            //see if there is an empty slot
            foreach (PhysicalFrame pf in pfList)
            {
                int newDelta = step - pf.getStepLastModified();
                if (newDelta > longestDeltaTime)
                {
                    longestDeltaTime      = newDelta;
                    longestDeltaTimeIndex = index;
                }

                if (pf.isEmpty())
                {
                    pf.fillFrame(pte, step);
                    pageAdded = true;
                    break;
                }

                index++;
            }

            if (pageAdded)
            {
                return;
            }

            pfList[longestDeltaTimeIndex].fillFrame(pte, step);
        }
Exemplo n.º 2
0
        //returns the location of a page table entry in the physical mem
        public int inFrame(PageTableEntry pte)
        {
            int retVal = 0;

            foreach (PhysicalFrame pf in pfList)
            {
                if (pf.getEntry() == pte)
                {
                    return(retVal);
                }
                retVal++;
            }
            return(-1);
        }
Exemplo n.º 3
0
        public void addPage(PageTableEntry pte, int step)
        {
            bool pageAdded             = false;
            int  longestDeltaTime      = 0;
            int  longestDeltaTimeIndex = 0;
            int  index = 0;

            pte.setModified(step);

            //see if there is an empty slot (LRU algorithm)
            foreach (PhysicalFrame pf in pfList)
            {
                int newDelta = step - pf.getStepLastReferenced();
                if (newDelta > longestDeltaTime)
                {
                    longestDeltaTime      = newDelta;
                    longestDeltaTimeIndex = index;
                }

                if (pf.isEmpty())
                {
                    pageFaultCounter++;
                    pte.getPageTable().getOwningProcess().incrementPageFaultCounter();
                    pf.fillFrame(pte);
                    pageAdded = true;
                    break;
                }
                index++;
            }

            if (pageAdded)
            {
                return;
            }

            pageFaultCounter++;
            pte.getPageTable().getOwningProcess().incrementPageFaultCounter();
            pfList[longestDeltaTimeIndex].fillFrame(pte);
        }
Exemplo n.º 4
0
 //fills the physical memory frame with a page
 public void fillFrame(PageTableEntry _pte)
 {
     pte = _pte;
 }
Exemplo n.º 5
0
        public void addPage(int frameId, int step)
        {
            bool added = false;

            for (int x = 0; x < 16; x++)
            {
                //an empty valid frame was found in page table
                if (entryList[x].isEmpty())
                {
                    entryList[x].setFrame(frameId);
                    added = true;
                    pm.addPage(entryList[x], owningProcess.getPid());
                    break;
                }
            }

            if (added)
            {
                return;
            }

            //a valid page wasnt found, make room for the frame in valid page
            int leasedUsed      = 0;
            int leasedUsedIndex = 0;
            int index           = 0;

            foreach (PageTableEntry pte in entryList)
            {
                //find the page which was lease recently used
                int timeDelta = step - pte.getLastModified();
                if (timeDelta > leasedUsed)
                {
                    leasedUsed      = timeDelta;
                    leasedUsedIndex = index;
                }
                index++;
            }

            //save a copy of the frame being removed in next open space
            //TODO: if the frame being removed was in memory, do proper computations
            for (int x = 16; x < 64; x++)
            {
                if (entryList[x].isEmpty())
                {
                    //copy page info to new frame
                    PageTableEntry pte = entryList[x];
                    pte.setFrame(entryList[index].getFrame());
                    pte.setModified(step);
                    pte.setResident(false);
                    pte.setValid(false);
                    break;
                }
            }

            //overwrite the old valid page
            PageTableEntry npte = entryList[index];

            npte.setFrame(frameId);
            npte.setModified(step);
            pm.addPage(npte, owningProcess.getPid());
        }
Exemplo n.º 6
0
        void updateGui(int _pid, Process p)
        {
            DataGridView          dgv  = this.dgvList[_pid - 1];
            List <VirtualFrame>   vfl  = p.getFrameList();
            List <PageTableEntry> ptel = p.getPageTable().getEntryList();
            List <PhysicalFrame>  pfl  = this.pm.getFrameList();

            //virtual memory
            for (int x = 0; x < LOGICAL_ADDR_SPACE; x++)
            {
                VirtualFrame vf = vfl[x];
                if (vf.isReferenced())
                {
                    dgv.Rows[x].Cells[1].Value           = "Yes";
                    dgv.Rows[x].Cells[1].Style.BackColor = Color.Gray;
                }
            }

            this.pageDataGridView.Rows.Clear();

            //page table
            int y = 0;

            foreach (PageTableEntry pte in ptel)
            {
                string frame     = pte.getFrame().ToString();
                string valid     = "Y";
                string resident  = "Y";
                string secondary = pte.getSecondary().ToString();

                if (pte.getFrame() == -1)
                {
                    frame = "";
                }

                if (pte.getSecondary() == -1)
                {
                    secondary = "";
                }

                if (!pte.isValid())
                {
                    valid = "N";
                }

                if (y < 16)
                {
                    if (!pte.isResident())
                    {
                        resident = "N";
                    }
                }
                else
                {
                    resident = "-";
                }


                this.pageDataGridView.Rows.Add(frame, valid, resident, secondary);
                y++;
            }

            this.pageGroupBox.Text = "Page Table (P" + _pid + ")";

            //physical memory
            for (int x = 0; x < PHY_MEM_SIZE; x++)
            {
                if (!pfl[x].isEmpty())
                {
                    PageTableEntry pteInMem       = pfl[x].getEntry();
                    int            framePID       = pteInMem.getOwnerPID();
                    int            pageTableFrame = pteInMem.getFrame();
                    this.phyDataGridView.Rows[x].Cells[1].Value           = "Frame: " + pageTableFrame;
                    this.phyDataGridView.Rows[x].Cells[1].Style.BackColor = getColorForPID(framePID);
                }
            }
        }
Exemplo n.º 7
0
 public void fillFrame(PageTableEntry _pte, int _stepLastModified)
 {
     empty            = false;
     pte              = _pte;
     stepLastModified = _stepLastModified;
 }
Exemplo n.º 8
0
        void updateGui(int _pid)
        {
            this.pageFaultLabel.Text = "Page faults: " + pm.getFaultCounter()
                                       + " (P1: " + processList[1].getPageFaultCounter() + " |"
                                       + " P2: " + processList[2].getPageFaultCounter() + " |"
                                       + " P3: " + processList[3].getPageFaultCounter() + " |"
                                       + " P4: " + processList[4].getPageFaultCounter() + " |"
                                       + " P5: " + processList[5].getPageFaultCounter() + ")";

            //update the VM data grid views
            for (int z = 0; z < PROCESS_NUM; z++)
            {
                DataGridView dgv = this.dgvList[z];
                for (int x = 0; x < LOGICAL_ADDR_SPACE; x++)
                {
                    List <VirtualFrame> vfl = processList[z + 1].getFrameList();
                    VirtualFrame        vf  = vfl[x];
                    if (vf.isReferenced())
                    {
                        dgv.Rows[x].Cells[1].Value           = "Yes";
                        dgv.Rows[x].Cells[1].Style.BackColor = Color.Gray;
                    }
                }
            }

            //update each page table data grid view
            int y = 0;

            foreach (DataGridView dgv in this.pageDVGList)
            {
                List <PageTableEntry> ptel = this.processList[y + 1].getPageTable().getEntryList();
                int ptIndex = 0;
                foreach (PageTableEntry pte in ptel)
                {
                    string frame    = pte.getFrame().ToString();
                    string valid    = "Y";
                    string resident = "Y";

                    if (pte.getFrame() == -1)
                    {
                        frame    = "";
                        valid    = "";
                        resident = "";
                    }
                    else
                    {
                        if (!pte.isValid())
                        {
                            valid = "N";
                        }

                        if (!pte.isResident())
                        {
                            resident = "N";
                        }

                        dgv[0, ptIndex].Value = frame;
                        dgv[1, ptIndex].Value = valid;
                        dgv[2, ptIndex].Value = resident;
                    }
                    ptIndex++;
                }
                y++;
            }

            //update physical memory data grid view
            List <PhysicalFrame> pfl = this.pm.getFrameList();

            for (int x = 0; x < PHY_MEM_SIZE; x++)
            {
                if (!pfl[x].isEmpty())
                {
                    PageTableEntry pteInMem       = pfl[x].getEntry();
                    int            framePID       = pteInMem.getOwnerPID();
                    int            pageTableFrame = pteInMem.getFrame();
                    this.phyDataGridView.Rows[x].Cells[1].Value           = pteInMem.getLastModified().ToString();
                    this.phyDataGridView.Rows[x].Cells[1].Style.BackColor = getColorForPID(framePID);
                }
            }
        }
Exemplo n.º 9
0
 public void removePage(PageTableEntry pte)
 {
 }