function FIFO(accessPattern, frameCount): pageFrameList = array of size frameCount initialized to -1 nextToReplace = 0 pageFaults = 0
for page in accessPattern: if page not in pageFrameList: pageFrameList[nextToReplace] = page nextToReplace = (nextToReplace + 1) % frameCount pageFaults += 1
return pageFaults
function LRU(accessPattern, frameCount): pageFrameList = array of size frameCount initialized to -1 lastUsed = array of size frameCount to keep track of last access time pageFaults = 0 time = 0
for page in accessPattern: if page not in pageFrameList: replaceIndex = index of the minimum value in lastUsed pageFrameList[replaceIndex] = page lastUsed[replaceIndex] = time pageFaults += 1 else: index = index of page in pageFrameList lastUsed[index] = time
time += 1
return pageFaults
eddie@eddie-pcmasterrace:~/workplace/cs480/programming/four$ ls Makefile Readme testvm.c vmalgorithm.c vmalgorithm.h eddie@eddie-pcmasterrace:~/workplace/cs480/programming/four$ make cc -c -o testvm.o testvm.c testvm.c: In function ‘main’: testvm.c:35:4: warning: implicit declaration of function ‘initializePageFrame’ [-Wimplicit-function-declaration] 35 | initializePageFrame(); | ^~~~~~~~~~~~~~~~~~~ testvm.c:44:4: warning: implicit declaration of function ‘printAccessPattern’ [-Wimplicit-function-declaration] 44 | printAccessPattern(); // print the access pattern again ... | ^~~~~~~~~~~~~~~~~~ cc -c -o vmalgorithm.o vmalgorithm.c vmalgorithm.c: In function ‘generateAccessPattern’: vmalgorithm.c:18:11: warning: implicit declaration of function ‘time’ [-Wimplicit-function-declaration] 18 | srand(time(0)); | ^~~~ gcc testvm.o vmalgorithm.o -o testvm eddie@eddie-pcmasterrace:~/workplace/cs480/programming/four$ ./testvm 7 3 Running program using FIFO algorithm ... ... 5 -1 -1 5 2 -1 5 2 -1 5 2 0 4 2 0 4 6 0 4 6 0 4 6 0 4 6 1 3 6 1 3 4 1 3 4 5 0 4 5 0 4 5 0 4 5 0 6 5 0 6 2 0 6 2 0 6 2 1 6 2 Page Faults of FIFO: 13 page fault of FIFO: 13
The Same Access Pattern: 5 2 2 0 4 6 4 4 1 3 4 5 0 4 5 6 2 0 0 1 Running program using LRU algorithm ... ... 5 -1 -1 5 2 -1 5 2 -1 0 2 -1 0 4 -1 0 4 6 0 4 6 0 4 6 0 4 1 3 4 1 3 4 1 3 4 5 0 4 5 0 4 5 0 4 5 6 4 5 6 2 5 6 2 0 6 2 0 6 1 0 Page Faults of LRU: 13 page fault of LRU: 13 eddie@eddie-pcmasterrace:~/workplace/cs480/programming/four$
$: cd /home/cs/zhengli/cs480-02
$: ls
data.zip zero.zip
$: cp *.zip /home/cs/zhengli/cssc1710/programming
$: cd /home/cs/zhengli/cssc1710/programming
$: ls
data.zip zero.zip
$: scp cssc1710@edoras.sdsu.edu:/home/cs/zhengli/cssc1710/localpull/project.tar.gz ./
$: tar -xzvf project.tar.gz
$: unzip data.zip, zero.zip
$: rm project.tar.gz
$: zip -r project.zip programming
$: scp /home/eddie/workplace/cs480/prelimproj.zip cssc1710@edoras.sdsu.edu:~/programming