The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
+6 votes
Consider the two-dimensional array A:
int A[][] = new int[100][100];
where A[0][0] is at location 200 in a paged memory system with pages of size 200. A small process that manipulates the matrix resides in page 0 (locations 0 to 199). Thus, every instruction fetch will be from page 0. For three page frames, how many page faults are generated by the following array-initialization loops, using LRU replacement and assuming that page frame 1 contains the process and the other two are initially empty?
for (int j = 0; j < 100; j++)
for (int i = 0; i < 100; i++)
    A[i][j] = 0;


for (int i = 0; i < 100; i++)
for (int j = 0; j < 100; j++)
    A[i][j] = 0;
asked in Operating System by (211 points) | 2.4k views

1 Answer

+14 votes
Best answer

First of all I am assuming some of the facts because the question does not state them.

I assume array is stored in row major order and i is used for accessing row and j is used for accessing column. As page size is specified in number I am assuming it is going to hold 200 elements of the array.

Now it is saying memory has 3 frames and as said earlier 1 frame will be always occupied by the process so we have left with 2 frames.


Lets analyse second loop first as it will be easy:


Total number of elements will be =100*100=10000. 
So 10000 contiguous memory will be allocated to array in the form R1, R2... where R stand for row. As the page size is 200,  at the start of loop 0-199 elements will come to main memory in one page after an initial page fault. After that when we reach 200 the second page fault occurs. Thus for every 200 element 1 page fault is occurring. So 10000/200 = 50 page faults


For 1st loop, I am drawing the image diagram.

You may guess that now blue element will be needed for which another page fault will occur and we will be accessing only 2 element per page fault. So number of page faults =10000/2=5000.

This concept can be extended if page size is given in kB and array element size is taken as 4B- just count number of array elements in one page. I think now you have understood the concept.

answered by Boss (16.1k points)
selected by
You got it perfect..
I didnt get it for the first loop...where is the diagram u mentioned? Please explain the first loop.

i have posted a image i think u didn't get it . 

Related questions

+1 vote
1 answer
0 votes
0 answers
asked Jun 20, 2018 in Digital Logic by I_am_winner Active (1.9k points) | 201 views
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
48,411 questions
52,746 answers
68,213 users