GATE / CS ARCHIVE

GATE CSE 2023 / QUESTION 57

GATE CSE 2023 Q57

Operating Systems · Virtual Memory & Paging · Full GATE CSE 2023 paper

GATE 2023, Q57 2 marks · NAT
Report issue

Virtual Memory & Paging

Question 57, GATE 2023: Row-major C array int D[128][128] is accessed by for i=0..127, for j=0..127, D[j][i]*=10. A page holds 512 array elements and 30 frames are available under LRU demand paging. Count faults in the intended page-aligned, initially nonresident array model; disclose these implicit assumptions.
Tap to enlarge
Answer & solution

Official answer: 4096

Under the usual page-aligned, initially nonresident array model, one page holds four complete rows because 512/128=4. The inner loop scans down a column and touches 32 pages in order, with four consecutive accesses per page. Only the first access of each four-row group faults. A cyclic traversal of 32 distinct pages with only 30 LRU frames has a miss on each page at every column: the reuse distance is 31 other pages. Hence 128 columns times 32 faults per column gives 4096. The standard answer implicitly assumes the array starts at a page boundary and ignores unrelated memory references. A non-page-aligned placement or a different initial residency can change the count; these are not specified explicitly.

Teaching detail. For aligned storage, element D[j][i] has page number floor((128j+i)/512)=floor(j/4) for each fixed i∈[0,127]. The page stream per column is therefore 0 repeated four times, 1 repeated four times, through 31 repeated four times. Only the first access to each repeated group faults. Between two uses of any page in successive columns are 31 distinct other pages, exceeding the 30-frame capacity, so no page survives until its next reuse. Multiplying 32 by 128 gives the count; multiplying 128² would ignore within-page hits.

Original paper, page 60 · Answer key