Question

Consider a 32-bit system with 4 KB page size and page table entries of size 4 bytes each. Assume 1 KB=2101\text{ KB} = 2^{10} bytes. The OS uses a 2-level page table for memory management, with the page table containing an outer page directory and an inner page table. The OS allocates a page for the outer page directory upon process creation. The OS uses demand paging when allocating memory for the inner page table, i.e., a page of the inner page table is allocated only if it contains at least one valid page table entry.

An active process in this system accesses 2000 unique pages during its execution, and none of the pages are swapped out to disk. After it completes the page accesses, let XX denote the minimum and YY denote the maximum number of pages across the two levels of the page table of the process.

The value of X+YX+Y is ________

Official answer and solution
Official answer
1028
From
Official GATE 2024 answer key

Solution

Determine the number of PTEs per page (4 KB/4 B=10244\text{ KB} / 4\text{ B} = 1024), then find the minimum (22) and maximum (10241024) number of inner page table pages needed for 2000 valid PTEs, plus 1 outer page directory page each.

  1. Page table geometry:
    • Page size =4 KB=212= 4\text{ KB} = 2^{12} bytes; PTE size =4= 4 bytes.
    • Number of entries per page table page =2124=210=1024= \frac{2^{12}}{4} = 2^{10} = 1024 entries.
    • In the 32-bit virtual address (10+10+1210 + 10 + 12 split), the outer page directory occupies 1 page and points to up to 1024 inner page table pages, each holding up to 1024 PTEs.
  2. Minimum page table pages (XX):
    • To minimize the number of inner page table pages for 20002000 unique virtual pages, pack the 20002000 valid PTEs contiguously into ⌈2000/1024⌉=2\lceil 2000 / 1024 \rceil = 2 inner page table pages.
    • Including the 11 outer page directory page: X=1+2=3X = 1 + 2 = 3.
  3. Maximum page table pages (YY):
    • To maximize the number of inner page table pages, spread the 20002000 valid PTEs across as many inner page table pages as possible. Since there are only 10241024 possible inner page table pages in total and 2000≥10242000 \ge 1024, all 10241024 inner page table pages can contain at least one valid PTE.
    • Including the 11 outer page directory page: Y=1+1024=1025Y = 1 + 1024 = 1025.
  4. Sum:
    X+Y=3+1025=1028X + Y = 3 + 1025 = 1028
Final answer

1028

Common trap

Assuming the maximum number of inner page table pages is 2000 (one per accessed page) without noticing that the outer page directory has only 1024 entries.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2024 Computer Science and Information Technology - Set 2 (CS2)
Question
64 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.