Calculating number of page faults in two dimensional array

1.1k Views Asked by At

//1)

#include <stdio.h>
int A[1024][1024];
int main(void)
{
    int i, j=0;
    for (i=0 ; i < 1024 ; i++)
    {
        for (j=0 ; j < 1024 ; j++)
        {
            A[i][j] = 0; // 
        }
    }
}

// 2)

#include <stdio.h>
int A[1024][1024];
int main(void)
{
    int i, j=0;
    for (i=0 ; i < 1024 ; i++)
    {
        for (j=0 ; j < 1024 ; j++)
        {
            A[j][i] = 0; //
        }
    }
}

Consider the two-dimensional array A: int A[1024][1024]; Each pages has 4kb(while size of int is 4byte). A small process that manipulates the matrix resides in the page 0 (location 0 to 1023). Thus every instruction fetch will be from page 0.

For two page frames, how many page faults are generated by the following array-initialization loops, using FIFO,LRU and Optimal replacement and assuming that the first page frame contains the process and the other is initially empty?

1

There are 1 best solutions below

1
On
  1. 256 (1024 * 1024 / 4096)
  2. 1024 * 256 (1024 * (1024 * 1024 / 4096))