in Operating System edited by
724 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$
in Operating System edited by
by
724 views

2 Answers

2 votes
2 votes
Best answer
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

4 Comments

yes, now i add this line in the question  --> For pages of 128 words, each row takes one page.

That means number of page frames  in main memory is 1 .
2
2
@Bikram sir, But still it does not specify the number of frames.
6
6
@Bikram sir,  the number of frames ?.
0
0
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