GateAI
Memory Management and Virtual Memory

GATE CSE 2023 · Q57

NAT2 marksMedium

Time

Consider the following two-dimensional array DD in the C programming language, which is stored in row-major order: int D[128][128]; Demand paging is used for allocating memory and each physical page frame holds 512 elements of the array DD. The Least Recently Used (LRU) page-replacement policy is used by the operating system. A total of 30 physical page frames are allocated to a process which executes the following code snippet:for (int i = 0; i < 128; i++) for (int j = 0; j < 128; j++) D[j][i] *= 10;The number of page faults generated during the execution of this code snippet is ___________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 4096 (±0)

Memory Management and Virtual Memory

To determine the total number of page faults:

  1. Array Layout and Page Size:

    • The array size is 128×128=16384128 \times 128 = 16384 elements stored in row-major order.

    • Each row has 128128 elements.

    • Each page frame holds 512512 elements, which corresponds to:

      512128=4 rows per page\frac{512}{128} = 4\text{ rows per page}
    • Total number of pages required to store array DD:

      16384512=32 pages (labeled P0,P1,…,P31)\frac{16384}{512} = 32\text{ pages (labeled } P_0, P_1, \dots, P_{31}\text{)}
  2. Access Pattern:

    • The nested loops access the array column by column: for a fixed outer index i, the inner loop iterates j from 00 to 127127, accessing D[j][i]D[j][i].

    • For j=0,1,2,3j = 0, 1, 2, 3, the elements belong to Page P0P_0.

    • For j=4,5,6,7j = 4, 5, 6, 7, the elements belong to Page P1P_1, and so on up to Page P31P_{31}.

    • Thus, for each value of i, the access sequence of pages is:

      P0,P0,P0,P0,P1,P1,P1,P1,…,P31,P31,P31,P31P_0, P_0, P_0, P_0, P_1, P_1, P_1, P_1, \dots, P_{31}, P_{31}, P_{31}, P_{31}
  3. Page Replacement Behavior:

    • A total of 3030 frames are allocated using the LRU replacement policy.

    • In each outer iteration (for a given i), 3232 distinct pages are accessed in sequential order (P0→P31P_0 \to P_{31}).

    • Accessing P0P_0 through P29P_{29} fills all 30 frames (3030 page faults).

    • Accessing P30P_{30} replaces the least recently used page P0P_0 (1 page fault).

    • Accessing P31P_{31} replaces P1P_1 (1 page fault).

    • Hence, each column traversal generates exactly 3232 page faults.

    • Because all 3232 pages are cycled through in each column traversal and only 3030 frames are available, every page is evicted before it can be reused in the next column traversal (i+1i+1).

  4. Total Page Faults:

    • Outer loop runs 128128 times.

    • Total page faults = 128×32=4096128 \times 32 = 4096.

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Memory Management and Virtual Memory previous year question is Q57 of the GATE CSE 2023 paper. Find more GATE CSE PYQs on Memory Management and Virtual Memory in Operating Systems, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Memory Management and Virtual Memory PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Memory Management and Virtual Memory in GATE CSE

Memory Management and Virtual Memory has 32 GATE CSE PYQs across 22 papers from 2011 to 2026. 15 of them are 2-mark NAT questions like this one, and GATE CSE 2023 has 2.

How GATE tests Memory Management and Virtual Memory

More from GATE CSE 2023

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2023 · Q57 · NAT

Consider the following two-dimensional array D in the C programming language, which is stored in row-major order: int D[128][128]; Demand paging is used for allocating memory and each physical page frame holds 512 elements of the array D. The Least Recently Used (LRU) page-replacement policy is used by the operating system. A total of 30 physical page frames are allocated to a process which executes the following code snippet: for (int i = 0; i The number of page faults generated during the execution of this code snippet is …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.