コード例 #1
0
        //reference a page which is already in the page table
        public void reference(int frameId, int step)
        {
            foreach (PageTableEntry pte in entryList)
            {
                if (pte.getFrame() == frameId)
                {
                    pte.setModified(step);

                    //see if the page table entry is not in physical mem
                    if (!pte.isResident())
                    {
                        pm.addPage(pte, step);
                    }

                    break;
                }
            }
        }
コード例 #2
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());
        }