edited by
681 views
0 votes
0 votes

Assume that pages are $128$ words in size. Consider below code snippet whose function is to initialize to $0$ each element of a $128$ – by – $128$ array. Then number of page faults generated by the following Code  snippet is:

Assume  the array is stored row major order, For pages of $128$ words, each row takes one page.

int A[128][128];
for( int j=0; j<128; j++)
for( int i=0; i<128; i++)
A[i][j] = 0;
  1. $128$
  2. $16384$
  3. $0$
  4. $16378$
edited by

2 Answers

Best answer
2 votes
2 votes
Note that the array is stored in row major form. That is, the array is stored A[0][0], A[0][1], A[0][2], ......., A[0][127],

A[1][0], A[1][1], A[1][2], ........, A[127][127].

For pages of 128 words, each row takes one single page.

Thus, the preceding code zeros one word in each page, then another word in each page, and so on. If the operating system allocates fewer than 128 frames to the entire program, then its execution will result in 128 × 128 = 16,384 page faults.
selected by
0 votes
0 votes
int A[128][128];
for( int j=0; j<128; j++) // One page fault per value => 128 Page Faults.
for( int i=0; i<128; i++) // One page fault per value => 128 Page Faults.
A[i][j] = 0;

So, $128*128=2^{14}=16384$ $page$ $faults.$


This is so because the array is stored in RMO, but we're looping j first (which is for columns).

So, essentially we're accessing an array in CMO that's stored in RMO. So, for each j we'll eventually get 128 page faults. (Visualise CMO and RMO)

Answer:

Related questions

2 votes
2 votes
1 answer
1
Bikram asked Dec 26, 2016
262 views
Consider the following 3 processes with 3 binary semaphores with initial values $S_{0}=0, S_{1}=0, S_{2}=1$$$ \begin{array}{|c|c|c|} \hline \textbf{P} & \textbf{Q} & \tex...
2 votes
2 votes
3 answers
2
Bikram asked Dec 26, 2016
1,050 views
In a paged memory, the page hit ratio is $0.35$. The time required to service the page fault is $100$ ns. Time required to access a page in primary memory is $10$ ns.The ...
1 votes
1 votes
1 answer
4
Bikram asked Dec 26, 2016
201 views
A counting semaphore is initialized to $10$. The $6$ P(wait) operations and $4$ V(signal) operations were completed in this semaphore. The resulting value of semaphore is...