edited by
1,054 views
3 votes
3 votes

Suppose a $32 K×8 K$ matrix A with $1$-byte elements is stored in row major order in virtual memory. Assume that only the program in question occupies space in physical memory.
Program $1$

for (i = 0; i < 32768; i++)
   for (j = 0; j < 8192; j++)
       A[i][j] = A[i][j] * A[i][j];



Program $2$

for (j = 0; j < 8192; j++)
 for (i = 0; i < 32768; i++)
      A[i][j] = A[i][j] * A[i][j];



If both program $1$ and program $2$ causes $8 K$ page faults, how many page faults would program $2$ experience if the physical memory can store only $1$ page?

$(A) 8M$
$(B) 16M$
$(C) 32M$
$(D) 64M$

edited by

2 Answers

Best answer
1 votes
1 votes

Given a matrix of size 32K*8K

also given that the page fault of both are equal, which is only possible if the whole matrix can be stored in memory.

Further its mentioned that the number of page fault is 8K which means the page size is 32K

Now we need to find out the number of page fault caused by program2 with page size 32K

Number of accesses in program2 for a single page = 4

for each iteration of for(i = 0; i < 32768; i++) loop there will be 32K/4 page faults = 8K page faults

This is repeated for(j = 0; j < 8192; j++) number of times.

Hence total number of page faults = 8K*8K = 64M

Option D is the correct answer

selected by

Related questions