0

//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?

n0p
  • 3,399
  • 2
  • 29
  • 50
  • 4
    possible duplicate of [Calculating number of page faults for 2-d array](http://stackoverflow.com/questions/15961582/calculating-number-of-page-faults-for-2-d-array) – n. m. could be an AI Dec 16 '14 at 15:07
  • How many people will consider this as a homework you did not give a try to ? – n0p Dec 16 '14 at 15:08
  • 1
    Even if this were an appropriate question here, and if you had shown your own effort first, there is not enough information here to resolve this question. The number of page faults would depend highly on the number of physical pages you actually have, for example - if you have a sufficient number of pages, there will only be one fault per page, because nothing will ever be evicted. You would only get multiple faults per page if you have fewer physical pages than your working set size... – twalberg Dec 16 '14 at 16:29
  • Does the processor have an instruction cache that holds the loop code? – Armali Mar 10 '17 at 13:52

1 Answers1

-1
  1. 256 (1024 * 1024 / 4096)
  2. 1024 * 256 (1024 * (1024 * 1024 / 4096))
Elton
  • 9
  • @Elton-- please add to your answer an explanation of how it solves OP's problem. Make it easier for those less experienced than you to understand. – ad absurdum Dec 22 '16 at 07:31