499 views
1 1 vote

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? Use LRU replacement, and assume that page frame 1 contains the process and the other two are initially empty.

2 Answers

1 1 vote
There is space for 2 rows in one page frame, so If the architecture stores the array in row major order,

 The 'a' part code would require 50 page faults x 100 times = 5000 page faults.
Because in one complete iteration of the i loop, 100 different rows are accessed, since 2 rows are in one frame 50 times page fault will happen. And this happen for all the 100 column ( outer j loop). Thus 5000 faults.

But for 'b' code, 100 column are accessed of the same row, by the inner j loop, so no faults for column, only faults will be while trying to access different rows. again that will be only 50, since 2 rows are stored in a page, so always 2 adjacent rows will be available.

Also since we use LRU, the page for the instruction fetching will always stay in the memory, Because it is used in every instructions. Only the 2nd and 3rd pages be swapped for the matrix data storing.
0 0 votes
Here page size=200 means 1 page requires 200 locations of array to be stored.
Means-
page 1= 0 to 199 + 200 to 299 (200 locations)
page 2=300 to 499
page 3=500 to 799
...... and so on.

Given that there are 3 page frames to be used
a) for each column all rows are iterated => page 1 is stored in 2 rows i=0 & i=1 for j=0
    so page fault that can occur is 1 time
   2 rows-> 1 page fault
   100 rows-> 100/2 page faults=50 page faults
    and here j will run from 0 to 99 columns so total page faults occuring here will be 50*100=5000 page faults

b) here for every row columns from 0 to 99 will run
    For i=0, j=0 to 99 columns & i=1 j=0 to 99 will contain 1 page only as page requires 200 locations to be stored
   so page fault will occur one time for two iterations of i
   2 rows -> 1 page faults
   100 rows-> 100/2=50 page faults
    but here column have no role in generating page faults as same page is stored across all columns of a row
   Total page faults from both loops= 5000+50=5050 page faults
Position:
Show:

Related questions

0 0 votes
0 0 answers
226
226 views
tarunmundriya asked Dec 27, 2025
226 views
Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit, and worst-fit algorithms place processes ...
0 0 votes
0 0 answers
222
222 views
tarunmundriya asked Dec 27, 2025
222 views
Consider the page table for a system with 16-bit virtual and physical addresses and 4,096-byte pages.The reference bit for a page is set to 1 when the page has been ref- ...
0 0 votes
1 1 answer
205
205 views
tarunmundriya asked Dec 27, 2025
205 views
Consider the page table for a system with 12-bit virtual and physical addresses and 256-byte pages.The list of free page frames is D, E, F (that is, D is at the head of t...
0 0 votes
1 1 answer
2.6k
2.6k views
Harsh Kumar asked Aug 14, 2018
2,589 views
A simplified view of thread states is Ready, Running, andBlocked, where a thread is either ready andwaiting to be scheduled, is running on the processor, or is blocked (f...