CS FundamentalsVery hardWipro · Cognizant technical pattern

int A[256][256] is stored in row-major order, and a page holds 512 ints (two rows). The process has only ONE frame for A, initially empty. How many page faults does this loop cause?

int A[256][256] is stored in row-major order, and a page holds 512 ints (two rows). The process has only ONE frame for A, initially empty. How many page faults does this loop cause?
for (j = 0; j < 256; j++)
    for (i = 0; i < 256; i++)
        A[i][j] = 0;
  1. A. 32768
  2. B. 128
  3. C. 65536
  4. D. 256

Correct answer: A. 32768

The loop walks down a column. Rows i and i + 1 (for even i) share a page, so each column touches 128 pages, each faulting because the single frame was holding a different page: 128 × 256 = 32768. A row-wise loop would fault only 128 times; 65536 forgets that two rows share a page.

More Operating Systems questions

Exams that ask this topic