Sub topic 15
GATE Problem-Solving Patterns
Assume you know binary arithmetic, powers of two, basic process concepts, and the meanings of pages, frames, page tables, TLBs, and page faults. This chapter organizes the calculations that commonly appear in GATE questions.
A fixed solving workflow
For most memory-management problems:
- Write down every given size and its unit.
- Convert powers of two into bit counts.
- Identify the address field being requested.
- Draw the translation or timing sequence.
- Check whether the result is a count, a size, a time, or a probability.
- Test boundary cases, such as a zero offset or a full page table.
| Problem type | Main operation | Common error |
|---|---|---|
| Paging | Split address into page number and offset | Using page size as the offset bit count |
| TLB timing | Weight hit and miss paths | Forgetting the TLB lookup on a miss |
| Segmentation | Check offset against limit | Translating an invalid offset |
| Replacement | Trace each reference | Counting a hit as a fault |
Address and page-table patterns
If the page size is 2^p bytes, the offset contains p bits. For an n-bit virtual address, the page number contains n − p bits.
For example, a 32-bit address with 4-KB pages has p = 12 offset bits. The page number is the upper 20 bits. A page-table entry stores the frame number and usually control bits such as valid, protection, and dirty bits.
For a single-level page table, the table size is:
number of virtual pages × size of one page-table entry.
If the virtual address has n bits and the page size is 2^p bytes, the number of virtual pages is 2^(n − p).
In a multilevel table, divide the virtual page number into fields from the top level downward. Each field selects one entry. The number of entries at a level is determined by the field width, not by the page size.
Timing patterns
With a TLB, let h be the hit ratio, t be TLB lookup time, and m be memory-access time. If a hit needs one memory access and a miss needs a page-table access plus the data access:
EAT = h(t + m) + (1 − h)(t + 2m)
Do not multiply the miss path by only the page-table time. The processor still performs the final data access.
With a page-fault probability f, let s be the normal memory-reference time and P be the page-fault service time. A basic model is:
EAT = (1 − f)s + fP
If the fault path also includes a restart or an additional memory reference, include that cost in P. Since P is usually millions of nanoseconds while s may be tens or hundreds, even a small f can dominate the result.
Replacement and working-set patterns
For FIFO, remove the page that entered memory first. FIFO can show Belady’s anomaly: adding a frame can increase the number of faults.
LRU removes the page that has not been used for the longest time. Optimal replacement removes the page whose next use is farthest in the future. Optimal is useful as a lower bound, but an operating system cannot know the future exactly.
The working set is the set of pages used during a recent window of references. If the total working-set demand exceeds available frames, processes fault repeatedly. This condition is thrashing.
Exercise
A 16-bit virtual address uses 1-KB pages. How many bits identify the page, and how many virtual pages exist?
Show answer
A 1-KB page is 2^10 bytes, so the offset has 10 bits. The page number has 16 − 10 = 6 bits, giving 2^6 = 64 virtual pages.
Exercise
Which replacement algorithms should be checked for Belady’s anomaly in a standard GATE question?
Show answer
Check FIFO first. FIFO can have the anomaly. LRU and Optimal are stack algorithms, so increasing the number of frames cannot increase their fault count.