Unit II — Memory Management · Virtual Memory
Unit II

Memory Management, Paging, Segmentation & Virtual Memory

Sections A–U follow your Unit II syllabus line by line. Every question is tagged with the paper that actually asked it in 2023–2025 (OS Akash.pdf) or, where the recent papers are silent, with the older ETCS-304 paper that did. Answers are sized to the marks printed on the question; all arithmetic comes from the independently re-solved numbers, not from the book's own totals.

How this page is ordered A–H is the “memory hardware and allocation” half (organization, hierarchy, strategies, partitions, fragmentation, addresses, swapping). I–M is translation (paging, page table + TLB, segmentation, segmentation with paging). N–U is virtual memory (demand paging, page faults, replacement, performance, thrashing, demand segmentation, overlays). Worked numbers for first/best/worst fit and for every FIFO/LRU/Optimal string live on the Numericals page — they are not repeated here.

A. Memory Organization

Memory
Unit II · Memory Organization

Define the terms Caching and Buffering.

Recent PYQ — must do End Term Jan 2024 · Q.1(d) 3 Marks High
Asked in: End Term Jan 2024 · Q.1(d) (3 marks) — the printed answer is a two-column table with the feature rows Definition, Basic, Storage, Location. The coverage matrix also lists this as Oct-2024 Q.1(d); the paper split in the extraction notes puts caching/buffering in the Jan-2024 Q.1 set, so that is the attribution used here. Older papers: End Term Apr 2016 asked buffering/caching under device management (out of Unit II scope).
Show answer

What main memory is

Main memory (RAM) is the only storage area the processor can address and read directly. It is a large array of bytes, each with its own address, and it is random access — any location takes about the same time to reach as any other. Everything a running process needs — its instructions, its data and its stack — must be in main memory, because the CPU fetches operands and instructions from nowhere else. It is volatile: contents disappear on power-off, which is why permanent copies live on disk.

The operating system’s memory-related job therefore starts at organization level: it must keep track of which parts of memory are free, which are in use and by whom, decide how much memory each process gets, and decide what to move in and out of main memory when it fills up.

Memory organization summary

PropertyMain memory
Accessed directly by CPU?Yes — the CPU can only address registers, cache and main memory
Typical technologyIntegrated-circuit RAM (DRAM) modules
VolatilityVolatile — loses contents when power is removed
HoldsParts of the OS plus the currently active processes (code, data, stacks, page tables)
Problem it createsIt is much smaller and much more expensive per bit than disk, so it must be shared carefully

Caching vs buffering (the required table)

FeatureBufferingCaching
Definition A buffer is a block of memory used as a temporary holding area for data that is being moved between two things that work at different speeds (for example a slow device and a fast CPU). A cache is a small, fast memory that holds a copy of data which really lives elsewhere (main memory or disk) so that repeat accesses are served without going to the slow original.
Basic (purpose / idea) Smooths out a speed mismatch and lets the producer and consumer work independently; it is written once and read once — the data then leaves it. Exploits re-use: the same data is likely to be needed again soon, so a copy is kept close to the requester and hit rates decide the speed-up.
Storage A fixed-size area of main memory (or a register/FIFO inside the device controller). Contents are transient and there is exactly one copy of each item. High-speed memory (SRAM inside the CPU for a cache line; a reserved region of RAM for a disk or page cache). Contents are duplicate copies and must be kept coherent with the original.
Location Between two components in a data path — at the I/O interface, in the OS buffer pool, in the device controller. Between the CPU (or requester) and the slower memory it reads from — closest to the requester in the memory hierarchy.
Managed byDevice driver / OS I/O subsystemHardware (CPU cache) or OS (page/file cache)
ExampleKeyboard input queue; the block held while a printer is fed a line TLB holding recent page→frame translations; frequently used disk blocks kept in RAM
Exam tipFor 3 marks write the four required rows only (Definition, Basic, Storage, Location) and add one line each of example. One sentence worth of difference: a buffer holds data that is on its way somewhere; a cache holds a copy of data that already exists elsewhere.

B. Memory Hierarchy

Memory
Unit II · Memory Hierarchy

What is the utility of cache memory in the system?

Older PYQ — syllabus gap End Term May-June 2017 · Q.1(e) 2.5 Marks Medium
Asked in: End Term May-June 2017 · Q.1(e) (2.5 marks, cache vs main memory). No 2023–2025 paper asked memory hierarchy at all — the coverage matrix lists it as “cover for safety”, so the pyramid and the locality argument below are the insurance policy.
Show answer

The trade-off. No single technology can be fast, big and cheap at once. Speed and cost per bit track each other: the faster a memory is, the more it costs per bit and the smaller it can practically be. So a system is built as a hierarchy of levels — each level faster, smaller and dearer per bit than the one below it — with an automatic movement of data between adjacent levels so that the program sees one large, fast-looking store.

Level (top → bottom)Typical carrierSpeedSizeCost per bit
RegistersFlip-flops in the CPUFastest (< 1 CPU cycle)tens of bytesHighest
Cache (L1/L2/L3)SRAM on/near the CPUa few cyclesKB–MBVery high
Main memoryDRAM (RAM)tens–hundreds of nsGBModerate
Disk (HDD/SSD)Magnetic / flash storagemshundreds of GBLow
Tape / opticalSequential removable mediavery slow, archivalTBLowest
Fig B-1 · Memory hierarchy pyramid — speed, cost, size
R CACHE MAIN MEMORY DISK TAPE Registers — inside the CPU fastest, smallest, most expensive per bit; held in flip-flops Cache — SRAM copy of hot main-memory lines; hardware managed; a few cycles Main memory — DRAM the largest store the CPU can address directly Disk — magnetic / SSD backing store for swapping, paging and virtual memory Tape / optical archival, offline, slowest and cheapest faster, smaller, costlier per bit bigger, slower, cheaper per bit Rule of the hierarchy: as you move away from the CPU, access time, size and frequency of access all increase while cost per bit decreases.
How to draw this in exam
  1. Draw a triangle and cut it into five horizontal bands.
  2. Label from the apex down: Registers · Cache · Main memory · Disk · Tape.
  3. Put an upward arrow on the left edge: “faster, smaller, costlier per bit”.
  4. Write on the right: “as we go down, access time ↑, size ↑, access frequency ↑, cost per bit ↓”.
  5. Finish with one line: the hierarchy works because of locality — see below.

Why the hierarchy works — locality of reference

A program does not touch memory uniformly. During a short window it keeps returning to the same small region, so a fast, tiny upper level can serve most references:

  • Temporal locality — items accessed now are likely to be accessed again soon (loops, the just-executed instruction stream, a hot stack frame).
  • Spatial locality — items whose addresses are near each other are likely to be used near each other in time (sequential instructions, array traversal).
  • Because of this, moving blocks (cache lines, pages) rather than single words up the hierarchy gives a hit rate high enough that the average access time sits near the fast level while the capacity and price sit near the cheap level.

Utility of cache memory specifically: it hides the gap between CPU speed and main-memory speed. A CPU can finish an instruction in a cycle or two but a RAM access costs many such cycles; a cache keeps the frequently used instructions and data in SRAM so the CPU rarely waits for RAM. The same principle one level down justifies the TLB (caching page-table entries) and the disk/page cache.

Verification noteThis is the older-paper treatment of the syllabus point “Memory Hierarchy”. The recent 2023–2025 papers do ask the caching idea, but as Q.1(d) of Jan-2024 (caching vs buffering) and as the TLB in paging (Dec-2024 Q.5(c)) — never as a pyramid question. Expect it only as a safety answer.

C. Memory Management Strategies

Memory
Unit II · Memory Management Strategies

Explain memory management strategies.

Older PYQ — syllabus gap End Term May 2016 · Q.1(c) 2 Marks High
Asked in: End Term May 2016 · Q.1(c) (2 marks) · End Term May-June 2018 · Q.2(a) “Discuss the various memory management schemes.” (6.5 marks). In the recent papers the same syllabus point returns as Mid Term Oct 2025 · Q.3(b) on paging and segmentation (see card K).
Show answer

Main memory must hold both the operating system and the running user processes, and the OS’s job is to divide it up in the most efficient way possible. Three questions define any strategy: when are addresses fixed, must a process sit in one连续 block, and how is free space tracked.

1. Contiguous vs non-contiguous allocation

The memory is normally split into two partitions — one for the resident OS (usually low memory, because the interrupt vector lives there) and one for user processes. Into that user partition the OS places processes either contiguously (each process gets one single consecutive run of addresses, so a 20 KB process occupies 20 KB of adjacent memory) or non-contiguously (a process’s pieces may be scattered anywhere, and a table puts the pieces back together — this is paging, and in the pure sense segmentation with paging).

2. Absolute code, relocatable code, load-and-go

Kind of codeWhen addresses are decidedWhat the compiler/linker producesConsequence
Absolute codeCompile time — the programmer must already know the physical load addressInstructions that already contain real memory addresses No loader work and no hardware support needed, but the program can only ever run at that fixed address; to move it you must recompile. Used in the earliest simple batch systems.
Relocatable codeLoad time — the final start address is known only when the loader picks a free holeAddresses relative to a start of 0, plus a relocation table/bit-mapThe loader adds the load address to every relative reference (“relocates” the module) before starting it; a program can be loaded anywhere without recompiling.
Load-and-goLoad time, but with no separate loading pass An absolute machine-language object module produced by the assembler/compiler The loader simply places the object module in memory and jumps to its start address — one step, hence “load and go”. Typical of systems where the compiler itself produces absolute code.
Run-time (dynamic) bindingExecution time — every address is translated by hardwareLogical addresses plus an MMU with a base/relocation register Maximum flexibility: the process can be moved while it runs, swapping and virtual memory become possible. This is what modern systems use — see address-binding times.

3. Partitioning — the strategies built on contiguous allocation

  • Single contiguous allocation — OS in one part, one user process in the rest; no multiprogramming (MS-DOS).
  • Multiple fixed (static) partitioning — memory pre-cut into a fixed number of holes of fixed sizes; a process gets one whole hole. Degree of multiprogramming is capped by the number of holes and waste is internal fragmentation.
  • Multiple variable (dynamic) partitioning — holes are created exactly as processes arrive and leave; the OS keeps a free list. Waste is external fragmentation, cured by compaction.
  • Paging / segmentation — non-contiguous allocation; no external fragmentation under paging at all (see section F).

Two basic memory-management strategies are named in the printed May-2016 answer: paging, which permits the physical address space of a process to be non-contiguous, and segmentation, which supports the user’s view of memory as a collection of named, variable-length segments addressed as (segment name, offset).

Exam tipWrite the three headings (contiguous/non-contiguous · kind of code · partitioning) with two lines each. Adding the one-line definition of load-and-go usually fetches the last mark.

D. Contiguous vs Non-Contiguous Allocation

Memory
Unit II · Contiguous Allocation

Compare contiguous versus non contiguous memory allocation techniques.

Older PYQ — syllabus gap End Term May 2016 · Q.2(b) 6 Marks High
Asked in: End Term May 2016 · Q.2(b) (6 marks) only — the recent papers touch it implicitly in Mid Term Oct 2025 · Q.3(b) (paging and segmentation) but never as a comparison question. The printed 2016 answer opens with the relocation-register scheme: CPU logical address → compared against the limit register → added to the relocation register → physical address → memory.
Show answer

In contiguous allocation each process is contained in a single contiguous section of memory — consecutive blocks with consecutive addresses. In non-contiguous allocation the logical memory of a process is cut into pieces (pages, or segments-then-pages) and the pieces may be placed anywhere free; a per-process table records where each piece went.

BasisContiguous allocationNon-contiguous allocation
Placement of one processOne single adjacent block of memory big enough for the whole process Pieces scattered anywhere there is free space; the table stitches them back together
Unit of allocationThe whole process (or a fixed/variable partition sized to it) A page of fixed size (paging) or a segment of variable size, itself often paged
Address translationBase (relocation) register + limit register — one addition per reference Page table (page number → frame number) and/or segment table (base + limit) — index a table, then concatenate the offset
Hole / free-space managementOS must maintain a free list, merge adjacent holes, and search for a hole that fits (first / best / worst fit) Only a simple free-frame list is needed; any free frame will do, so allocation is O(1)-ish
FragmentationExternal fragmentation — enough total free memory but not contiguous; cured by compaction Paging removes external fragmentation entirely and leaves only bounded internal fragmentation in the last page
Process can move while running?Only with a relocation register scheme; moving a whole process is expensive Trivially — move one page/frame at a time; this is what makes swapping and virtual memory practical
Compaction costHigh — copying large amounts of memoryNot required (paging) / reduced (segmentation with paging)
Sharing & protection granularityWhole process, or a single base/limit pair — coarse Per frame or per segment flags — fine-grained sharing of a single page/segment between processes
Hardware / memory costCheap: two registers per processCostly: a page table per process, plus TLB for acceptable speed
Typical exampleMS-DOS, single-user systems, fixed-partition systemsUNIX/Linux, Windows — paging or segmentation with paging

The contiguous side, in the words of the printed 2016 answer

“The main memory must accommodate both the operating system and the various user processes. We therefore need to allocate the parts of the main memory in the most efficient way possible … In this contiguous memory allocation, each process is contained in a single contiguous section of memory … The relocation-register scheme provides an effective way to allow the operating system to change dynamically.”

Why it matters for the numericalsContiguous allocation is exactly where first / best / worst fit live, and that is the one place in Unit II where the recent papers do set a calculation: Numericals · first / best / worst fit (partitions 100K, 500K, 200K, 300K, 600K · processes 212K, 417K, 112K, 426K).

E. Partition Management Techniques

Memory
Unit II · Partition Management

Describe the function of operating system software in the following memory management scheme: (i) Multiple variable partition (ii) Buddy System (iii) Simple Paging

Older PYQ — syllabus gap End Term June 2019 · Q.3(a) 5 Marks High
Asked in: End Term June 2019 · Q.3(a) (5 marks) · End Term May-June 2018 · Q.2(a) “Discuss the various memory management schemes.” (6.5 marks). The 2019 answer spans three book pages and lists the advantages and disadvantages of variable partitioning including both internal and external fragmentation.
Show answer

Fixed vs variable partitioning

Multiple fixed partitioning: memory is divided once, at system generation time, into a fixed number of partitions whose sizes are then static. Each partition holds at most one process; a partition is either fully free or fully busy.

Multiple variable (dynamic) partitioning: there are no pre-set holes. The OS keeps a list of holes and, when a process of size n arrives, gives it a hole of exactly n (or n+something) and splits the remainder. When a process exits its space becomes a hole again and adjacent holes are merged.

BasisMultiple fixed (static) partitioningMultiple variable (dynamic) partitioning
Number & size of partitionsFixed at system generation; cannot change without a rebootCreated and destroyed at run time, sized to the process
Degree of multiprogrammingHard limit = number of partitionsVariable — limited only by how many holes currently fit
WasteInternal fragmentation — a 6 MB process in a 10 MB partition wastes 4 MB that nobody can useExternal fragmentation — many small holes whose total is large but none individually big enough
OS bookkeepingOne status flag per partition — very simpleA free (hole) list plus an allocation policy plus hole merging — much more work
Allocation policy needed?Choose a free partition; first-fit over partitions is normalFirst fit / best fit / worst fit over the hole list (see next card)
CompactionMeaningless — partitions are fixedAvailable cure for external fragmentation, but expensive
ProtectionBase + limit per partition is enoughBase + limit per process, changed on every context switch
Used byEarly multiprogrammed batch systems, some embedded/RTOS kernelsClassic time-sharing systems before paging took over

Buddy system (named in the same question)

Memory is repeatedly halved until a block is large enough to satisfy the request: free blocks are always powers of two, and splitting a block of size 2^U creates two “buddies” of size 2^(U−1). A request S is satisfied by the smallest power-of-two block with 2^(U−1) < S ≤ 2^U (that inequality is exactly as printed in the 2019 answer). When a block is freed, its buddy is merged back if it is also free. Cost: because the block is rounded up to a power of two, the wasted space is internal fragmentation.

Exam tipThree headings, three short paragraphs: variable partitioning → holes and external fragmentation + compaction; buddy → power-of-two splitting and internal fragmentation; simple paging → equal-size pages into equal-size frames with a page table, no external fragmentation, and the printed 2019 paging bullet “Due to equal size of the pages and frames, swapping becomes very easy.”
Unit II · Partition Management

Explain the concepts of the Virtual Memory. Describe First fit, Best fit and Worst fit mechanism for memory allocation.

Recent PYQ — must do End Term Dec 2025 · Q.5(a) 6 Marks Very high
Asked in: End Term Dec 2025 · Q.5(a) (6 marks) as theory · End Term May-June 2018 · Q.1(g) (5 marks) · End Term Jul 2023 · Q.2(b) (6.5 marks), End Term May-June 2017 · Q.2(b) (4 marks) and the 2016 paper Q.4 as the same data set worked numerically.
Show answer

All three are hole-selection policies used by variable-partition allocation. The OS holds a list of free holes; a process of size n must be placed in a hole with size ≥ n, and the policy decides which such hole to take.

PolicyRuleAdvantagesDisadvantages
First fit Scan the hole list from the beginning and allocate the first hole that is big enough; split the remainder and return it to the list. Simplest and fastest search — usually stops early; least likely to break up the largest hole needlessly. Produces fragmentation of the low end of memory: repeated first-fit scans bias allocation towards the start of the list and leave many small unusable holes (external fragmentation).
Best fit Search the whole list and allocate the smallest hole that is big enough — the hole whose size is closest to n. Wastes the least space on any single allocation, so it keeps large holes intact for future big requests; in practice the most frugal of the three. Slowest — a full list search every time; and the leftover slivers are so tiny that they are almost never usable, so it generates the largest number of small, un-reusable holes.
Worst fit Search the whole list and allocate the largest hole available, on the theory that the leftover piece is then still large enough to be useful. Never leaves a tiny, useless remainder from the biggest hole; suits systems where many small requests must all be served and small remainders can be re-used. Also needs a full search; rapidly destroys the large holes that a big process would later need, so in practice it is the worst of the three at admitting large processes.

Which one is best?

Simulation and the papers’ own data agree: first fit and best fit both beat worst fit, and best fit makes the most efficient use of memory overall — but no policy removes external fragmentation, because in all three cases a process needs one hole that is already big enough.

Worked placement for the exam-standard data set (partitions 100K, 500K, 200K, 300K, 600K · processes 212K, 417K, 112K, 426K): under first fit 212K → 500K, 417K → 600K, 112K → the 288K remainder, and 426K must wait; under worst fit 212K → 600K, 417K → 500K, 112K → the 388K remainder and 426K again must wait; under best fit all four are placed (212K → 300K, 417K → 500K, 112K → 200K, 426K → 600K, leaving 83K/88K/174K/88K remainders). → Full table on Numericals.

Verification noteThe May-June 2017 printing of this same numerical disagrees with the 2016 and Jul-2023 printings for identical data: it puts 212K into the 500K partition under best fit and then claims both 112K and 426K cannot be placed. That answer is arithmetically impossible (300K is a better fit for 212K than 500K, and 600K is still free). Do not copy it — the 2016 / Jul-2023 version, reproduced above, is the correct one, and “best fit is the only policy that places all four processes” is the conclusion to write.

F. Internal vs External Fragmentation

Memory
Unit II · Fragmentation

Explain the difference between External fragmentation and Internal fragmentation. Explain Paging and how to solve the fragmentation problem using paging.

Recent PYQ — must do Mid Term Oct 2024 · Q.3(a) 5 Marks Very high
Asked in (merged): Mid Term Nov 2023 · Q.1(b) “Differentiate between internal and external fragmentation.” (2 marks) · Mid Term Oct 2024 · Q.3(a) (5 marks — same question plus the paging follow-up) · Mid Term Oct 2025 · Q.1(e) “Explain internal and external fragmentation in memory.” (2 marks) · older papers: First Term Feb 2018 · Q.1(b) (2 marks) and End Term May-June 2018 · Q.2(b) (3 marks). Three of the six recent papers — highest-frequency theory question in Unit II after page replacement.
Show answer

Internal fragmentation is waste inside an allocated block: the OS gave the process more memory than it asked for, and the extra sliver is unusable by anyone else because it belongs to that process. External fragmentation is waste between allocated blocks: free memory exists in plenty but it is chopped into non-adjacent holes, so no single hole is large enough for the next process.

BasisInternal fragmentationExternal fragmentation
When it occursWhenever the allocated unit is fixed in size and larger than the request Whenever free memory is repeatedly allocated and freed in variable-sized chunks
Where the waste sitsInside the space already given to a process (the slack in the last block/page/partition)Outside every process — in the gaps between allocated blocks
Is the wasted memory usable by someone else?No — it is owned by that process Yes in total, but not in any single hole: 5 KB free in total yet a 6 KB process fails
Schemes that sufferFixed partitions, paging, buddy system Variable/dynamic partitioning, pure segmentation, contiguous allocation in general
Schemes that avoid itByte-exact variable allocation (no rounding) Paging (any frame will do — holes need not be adjacent)
Size of the lossBounded: at most one page/partition minus one byte per process Unbounded in principle: it can grow to the whole free memory
CureChoose a smaller page size, or use variable-sized allocation Compaction, or move to non-contiguous allocation (paging)
Cost of the cureSmaller pages ⇒ bigger page tables and more address-translation work Compaction costs a full memory copy of every live process
Numeric examplePage size 4 KB, process 9 KB ⇒ 3 pages = 12 KB allocated, 3 KB wasted inside the last page 10 KB free as 2 KB + 5 KB + 3 KB holes; a 6 KB request is refused although 10 KB is free

How paging solves external fragmentation

  1. Logical memory is cut into equal-sized pages; physical memory is cut into the same sized frames. Because page size = frame size, any free frame can hold any page.
  2. A process of 9 KB with 4 KB pages needs three frames — they may be frames 7, 2 and 11, in any order. Nothing has to be adjacent, so “no hole big enough” simply cannot happen.
  3. The page table turns the scattered frames back into a contiguous-looking address space at run time.
  4. The cost is that external fragmentation is traded for a small, bounded amount of internal fragmentation in the last page (the Oct-2024 answer names exactly this trade: paging → fixed-size blocks → internal fragmentation; segmentation → variable-size blocks → external fragmentation).

How compaction solves external fragmentation

Compaction shuffles the allocated blocks so that all the free holes merge into one contiguous block at one end of memory. It works only when relocation is possible at execution time — i.e. with dynamic relocation via a base/relocation register, because then moving a process just means changing its base value, not rewriting its code. Total free memory does not change; what changes is that it becomes one hole instead of ten, so the large waiting process can be admitted. The price is that it is pure overhead: potentially gigabytes copied while the system is otherwise idle.

Exam tipFor 5 marks: table (6–7 rows) + the 4-step paging argument + a two-line compaction paragraph. Draw one strip of memory with three holes and label the middle-sized gap “external fragmentation” — diagrams carry the marks on this question.

G. Logical vs Physical Address Space

Memory
Unit II · Address Spaces

Differentiate between Logical and Physical Address with the help of diagram.

Recent PYQ — must do End Term Dec 2025 · Q.1(c) 5 Marks Very high
Asked in: End Term Dec 2025 · Q.1(c) (5 marks) · Mid Term Nov 2023 · Q.1(c) “Explain logical and physical address space in paging.” (2 marks) · older papers: End Term May 2016 · Q.1(d) (2 marks), End Term Jul 2023 · Q.3(a) (3 marks) and a 2016-section item “Logical addresses vs Physical addresses.” whose marks are not printed.
Show answer

Every instruction that a CPU executes generates an address. The set of all addresses the CPU can generate is the logical (virtual) address space; the set of addresses the memory hardware actually sees is the physical address space. The logical space is normally 0 … 2m−1 for an m-bit address bus, and it is not the same thing as where the process really sits in RAM.

BasisLogical (virtual) addressPhysical address
Who sees itThe program / the CPU — the value inside the instruction and the registers The memory bus and the RAM chips
Generated byCPU at run time while executing instructions The MMU, after translation, at the moment the reference leaves the CPU
Space nameLogical / virtual address spacePhysical address space
Typical rangeAlways starts at 0 for each process and may be larger than RAM Sits somewhere inside real RAM, and can be smaller than, equal to, or larger than the logical space
Compile/load timeFixed by the compiler and the linker, independent of where the process is loaded Decided by the loader, and may change again while the process runs (swapping / paging)
Do they match?Identical only in systems with no hardware translation (absolute code, MS-DOS style). In every paged or MMU-based system they are different values, and the difference is invisible to the program.
ProtectionCannot by itself stop a program touching another’s memory Gated by base + limit registers, so a process can be physically fenced in

The MMU, the relocation register, base and limit registers

  • MMU (memory-management unit) — the hardware device that performs the run-time mapping from logical to physical addresses. The Dec-2025 answer prints the whole chain explicitly: CPU → logical address 150 → MMU adds the base address 1000 → physical address 1150 → main memory.
  • Relocation register = base register — holds the smallest physical address of this process. Its value is added to every address the CPU generates. If the base is 14000, an attempt to address location 0 is relocated to 14000, and location 346 becomes 14346 (the May-2016 printed example).
  • Limit register — holds the size of the logical address space of the process. Before adding the base, the MMU compares the generated address with the limit; if the address is greater than or equal to the limit it is illegal and the CPU traps to the OS — this is hardware protection with one register pair per process, which is why a context switch only has to reload two registers.
  • Changing the base register lets the OS move a running process in memory without touching its code — the flexibility that makes swapping and compaction possible.
Fig G-1 · MMU translation: logical 150 → physical 1150 (Dec-2025 Q.1(c))
CPU logical address 150 MMU limit check 150 < limit ? + base / relocation register = 1000 physical address 1150 Main memory … 1150 … 150 (what the program thinks it touched) + 1000 (where the loader put it) = 1150 (the cell of RAM used). If 150 had been greater than or equal to the limit register, the MMU raises a trapping error instead of accessing memory. Same arithmetic with the May-2016 base of 14000: logical 0 → physical 14000, logical 346 → physical 14346.
How to draw this in exam
  1. Box on the left labelled CPU, box on the right labelled Main memory.
  2. Big box in the middle labelled MMU; draw the limit check and the “+ base register” inside it.
  3. Arrow CPU → MMU carrying “logical address = 150”; arrow MMU → memory carrying “physical address = 1150”.
  4. Show the base register as 1000 and state the addition 150 + 1000 = 1150.
  5. Add one sentence on the limit register giving protection.
Address-binding timesCompile-time, load-time and execution-time binding are asked as their own older question — see card: role of compiler, loader and MMU.
Unit II · Address Binding

Briefly explain the role of compiler, loader and memory management hardware in the following address binding schemes: (i) Compile time binding (ii) Load time binding (iii) Run time binding.

Older PYQ — syllabus gap End Term May-June 2018 · Q.1(b) 4.5 Marks High
Asked in: End Term May-June 2018 · Q.1(b) (4.5 marks). No 2023–2025 paper asks binding times directly, but the Dec-2025 Q.1(c) MMU diagram on the previous card is run-time binding in pictures — the two answers belong together in revision.
Show answer

Binding = deciding which memory address a logical address refers to. If it happens before the program starts, addresses are fixed; if it happens during execution, they can still change.

SchemeWhen the mapping is fixedCompiler’s roleLoader’s roleMMU hardware’s role
(i) Compile-time bindingDuring compilation Must be told the physical start address in advance; it emits absolute code — instructions already containing real addresses Reads the binary and places it byte-for-byte at that same address; nothing to relocate None — no translation hardware needed
(ii) Load-time bindingWhen the loader picks a free hole, just before the first instruction Emits relocatable code — addresses relative to location 0 plus a relocation table telling which words need adjusting Adds the chosen load address to every relative address in the module, then produces an absolute image in memory (load-and-go = the loader places the object module and jumps to its start address without a separate relocation pass) None at run time — translation is finished before execution starts
(iii) Run-time / execution-time bindingEvery single memory reference, while the process runs Emits logical addresses that never resolve to a physical location at all Loads the program anywhere; keeps only the logical image plus its base/limit values in the PCB Essential. The MMU adds the base (relocation) register to each address and checks it against the limit register — see Fig G-1

Why only run-time binding is used today

  • A process can be moved in physical memory while it is executing — swap-out/swap-in, compaction, page-level replacement, all need this.
  • A program larger than RAM can run at all, since its logical space need never be laid down contiguously — the basis of virtual memory (section N).
  • Protection and sharing become per-process register settings instead of per-program recompilation.
  • Cost: an extra hardware step on every memory reference, which is exactly why the TLB exists.

H. Swapping

Memory
Unit II · Swapping

Swapping — meaning, the medium-term scheduler, and swap cost

Syllabus only — no direct PYQ Not asked in either book Safety
Show answer
Why this section is hereSwapping is a named line of your Unit II syllabus, yet it is not asked as a question in either book. The coverage matrix marks it “cover for safety”. The word does appear inside other answers — the May-2016 thrashing answer speaks of a “swap-in, swap-out level of intermediate CPU scheduling”, and the June-2019 paging answer says “Due to equal size of the pages and frames, swapping becomes very easy” — so one paragraph plus the scheduler link is enough insurance.

Swapping is the movement of an entire process (its code, data and stack) out of main memory onto a bulk storage area called the swap space (or backing store), and later back into memory so it can continue exactly where it stopped. It is a whole-process operation, unlike paging, which moves one page at a time.

Why swap at all

  • To free memory for other processes when main memory is oversubscribed.
  • To raise or lower the degree of multiprogramming according to load.
  • Roll out / roll in: a lower-priority process is rolled out so a higher-priority one can be rolled in and run immediately — the classic priority-based use of swapping.

The medium-term scheduler’s role

The medium-term (intermediate) scheduler is the piece of the OS that decides swapping. The three schedulers divide the work as printed in the Oct-2024 Q.1(e) table — long term admits processes to the ready queue, short term chooses which ready process gets the CPU, and the medium term “swaps processes in/out of memory”, focusing on memory management. Concretely it:

  1. Watches memory pressure and CPU utilisation.
  2. Selects a victim process — usually one that is blocked or low priority — and issues the swap-out, saving its PCB state.
  3. Later, when a hole large enough exists, swaps it back in and puts it on the ready queue for the short-term scheduler.
  4. Thereby controls the degree of multiprogramming; the long-term scheduler does the same job at job entry, but the medium-term does it dynamically.

Swap cost — the number that makes swapping unpopular

Swap time is dominated by transfer, not by the decision. A standard worked case: a 10,000-word process swapped over a device that moves 1,000 words per millisecond needs 10 ms just for the transfer — plus positioning latency. Since swapping moves the whole process, a large process is expensive to swap, which is why demand-paged systems swap single pages instead and reserve whole-process swapping for the medium-term scheduler’s load control.

Swapping (whole process)Paging (one page)
Moves a process’s complete image; must be contiguous when it comes backMoves one fixed-size page; any frame will accept it
Decided by the medium-term schedulerDecided by the page-fault handler + replacement algorithm
Cost ∝ process sizeCost ∝ page size, so it is bounded and predictable
Needs a hole the size of the process ⇒ external fragmentationNo external fragmentation

I. Paging

Translation
Unit II · Paging

Why are page sizes always power of 2? Explain.

Recent PYQ — must do End Term Dec 2024 · Q.1(d) 5 Marks Very high
Asked in: End Term Dec 2024 · Q.1(d) (5 marks) · End Term Jul 2023 · Q.3(b) (3 marks) · End Term May-June 2018 · Q.2(c) “Why page size is always a power of 2? In paging schemes, what are pages, frames and page table?” (3 marks) · End Term May-June 2017 · Q.1(i) (2.5 marks) · End Term Jul 2016 · Q.1(a) (marks not printed). Paging itself also returns as Oct 2025 · Q.3(b) (5 marks).
Show answer

Page, frame, page size = frame size

  • Page — a fixed-size block of the logical memory of a process.
  • Frame — the same fixed-size block of physical memory, i.e. after RAM is cut into equal chunks.
  • The two sizes are deliberately made equal, so that any page fits in any frame and physical memory never has to be searched for a hole of a particular size. External fragmentation disappears; the only waste is the slack in the last page (internal fragmentation).
  • Typical page sizes: 512 B, 1 KB, 4 KB (very common), 8 KB, up to 16 MB huge pages. Larger pages ⇒ smaller page tables but more internal fragmentation; smaller pages ⇒ the reverse.
Logical memory → pages
Page 0
Page 1
Page 2
Page 3
Cut to the same size
page size = 2m words
frame size = 2m words
page size = frame size
so any page fits any frame
Physical memory → frames
Frame 5
Frame 2
Frame 0
Frame 9

The page table

Each process has a page table: one entry per page, mapping page number → frame number (plus valid bit and protection bits). The physical memory “hole” problem is converted into a table look-up. The number of entries in a process’s page table equals its number of pages, so a page table can be very large — which is the price of paging and the reason for the TLB and for inverted page tables.

Why page sizes are powers of 2 — the real reason

Because then splitting an address into page number and offset needs no division at all — it is a pure bit-field operation. Write the address in binary and cut it after m bits, where page size = 2m:

  • the low m bits are the offset — mask them out with AND;
  • the remaining high bits are the page number — shift them right by m.
page number = address >> log2(page size)   /* shift, not divide */
offset      = address & (page size - 1)      /* mask,  not modulo */
physical    = (page_table[page number] << log2(page size)) + offset

example, page size 4096 = 2^12, address 8200:
  page number = 8200 >> 12 = 2        offset = 8200 & 4095 = 8
  check: 2 × 4096 + 8 = 8200  ✔   (a division-free split — just a shift and a mask)

If the page size were, say, 1,000 bytes, the CPU would have to divide by 1000 to get the page number and take a remainder for the offset on every single memory reference. A division is many times slower than an AND and a shift, and it would sit on the critical path of every instruction. Making the page size 2m turns the boundary between the two fields into a fixed bit position, so the hardware is a wire split — no arithmetic.

The Dec-2024 printed answer says the same thing in one sentence: “it is most efficient to break the address into X page bits and Y offset bits rather than perform arithmetic on the address to calculate the page number and offset. Because each bit position represents a power of 2, splitting an address between bits results in a page size that is a power of 2.”

Address-translation arithmetic you must be able to do

QuantityFormulaNotes
Offset bits dlog2(page size)Same number of bits in logical and physical address
Pages in a process⌈logical address space ÷ page size⌉Page-table entries = this number
Page-number bits mlogical address bits − dLogical address space = 2m+d
Frames in memoryphysical memory size ÷ frame sizeFrame-number bits = log2(frames)
Physical address bitslog2(frames) + dAlways ≥ logical bits? No — smaller, equal or larger
Internal fragmentationpage size − (process size mod page size) when the remainder ≠ 0, else 0Only ever in the last page

Advantages of paging as printed in the Oct-2025 answer: eliminates external fragmentation, allows non-contiguous allocation, simplifies memory management, supports virtual memory. Problems named in the same answer: internal fragmentation, large page tables, an additional memory access per reference, page faults.

Unit II · Paging Arithmetic

Consider a logical address space of eight pages of 1024 words each, mapped onto a physical memory of 32 frames. (i) How many bits are there in the logical address? (ii) How many bits are there in physical address?

Recent PYQ — must do End Term Dec 2024 · Q.5(b) 3 Marks Very high
Asked in: End Term Dec 2024 · Q.5(b) (3 marks) · the same shape of arithmetic as First Term Feb 2019 · Q.4 (10 marks) and First Term Feb 2018 · Q.4 (10 marks, whose printed answer contains two arithmetic slips — see the verification note).
Show answer

(i) Logical address — 8 pages × 1024 words each = 8192 words of logical address space.

8 pages × 1024 words = 8192 words = 2^13
⇒ logical address = 13 bits   (3 bits page number + 10 bits offset)

(ii) Physical address — 32 frames, each of the same 1024 words (frame size = page size) = 32768 words of physical memory.

32 frames × 1024 words = 32768 words = 2^15
⇒ physical address = 15 bits   (5 bits frame number + 10 bits offset)
FieldLogical address (13 bits)Physical address (15 bits)
High fieldpage number — 8 pages ⇒ log2 8 = 3 bitsframe number — 32 frames ⇒ log2 32 = 5 bits
Low fieldoffset — 1024 words ⇒ log2 1024 = 10 bitsoffset — unchanged, 10 bits (copied straight through)
Total3 + 10 = 13 bits5 + 10 = 15 bits

The same method on the Feb-2019 data (older paper, 10 marks)

Given: logical address space 4096 bytes, main memory 512 bytes, page size 16 bytes.

AskedWorkingAnswer
(a) offset / displacement bitspage size 16 = 24 bytes4 bits
(b) number of pages4096 ÷ 16 = 212 ÷ 24256 pages
(c) internal fragmentation4096 = 256 × 16 exactly, so the last page is full0 bytes
(d) entries in the (general) page tableone entry per page = 256256 entries
(e) entries if the page table is invertedone entry per frame: 512 ÷ 16 = 29 ÷ 24 = 2532 entries
physical address width512 bytes = 299 bits
Verification noteBoth parts of the Dec-2024 answer above were re-checked and match the printed solution (13 and 15 bits). Where the older books differ: the Feb-2019 paper prints no numeric value at all for internal fragmentation — the correct value is 0, because 4096 is an exact multiple of 16. And the Feb-2018 printing (logical address space 4050 bytes, main memory 1024 bytes, page size 16 bytes) prints “4050/16 = 253.125 = 28” and “16 − 2 = 8 byte”. Both lines are wrong. Re-solved: pages needed = ⌈4050 ÷ 16⌉ = 254 (not 253, because the 254th page holds the leftover bytes), frames = 1024 ÷ 16 = 64, and the last page holds 4050 mod 16 = 2 of its 16 bytes, so internal fragmentation = 16 − 2 = 14 bytes.

J. Page Table and TLB

Translation
Unit II · TLB

Describe the role of TLB in address translation with the help of a suitable diagram?

Recent PYQ — must do End Term Dec 2024 · Q.5(c) 3 Marks High
Asked in: End Term Dec 2024 · Q.5(c) (3 marks) · End Term May-June 2017 · Q.1(d) “Describe the role of TLB in address translation.” (2.5 marks) — the numerical side of the same topic is on the next card.
Show answer

The two-step memory access problem

Under run-time mapping with a page table kept in main memory, one logical reference becomes two physical accesses:

  1. access the page table (using the page number) to obtain the frame number;
  2. access the actual word in that frame using the physical address.

That roughly halves instruction-execution speed — a 100 ns memory turns into an effective 200 ns per reference. The fix is to cache the translations, not the data.

TLB — what it is

A Translation Look-aside Buffer is a small, fast, hardware cache — typically 64 to 1024 entries — holding the most recent page-number → frame-number translations. It is associative: the whole page number is compared with all entries in parallel (which is why the older papers call these registers “associative registers”). It is per-process, so it is flushed or tag-guarded on a context switch, and the OS must invalidate entries when it changes a mapping.

Its role, step by step (as printed in the Dec-2024 answer)

  1. CPU generates a logical address; its page-number field is searched in the TLB at the same time as the offset field is held aside.
  2. TLB hit — the frame number is delivered immediately, combined with the offset, and only one main-memory access is made.
  3. TLB miss — the memory-resident page table is looked up (first memory access) to get the frame number, the reference itself is then served (second access), and the freshly found translation is loaded into the TLB, replacing an older entry.
  4. Because of locality, hit ratios of 80–99% are normal, so the average cost falls back to near one access per reference.
Fig J-1 · Paging address translation: page number + offset → frame number + offset
LOGICAL ADDRESS generated by the CPU page no p offset d split by bit position only — page size = 2^d TLB associative, ~20 ns PAGE TABLE (in RAM) 0 → frame 8 p → frame f 2 → frame 0 3 → frame 5 searched in parallel frame f offset d offset d is never translated — it is copied straight through PHYSICAL ADDRESS = f × frame size + d TLB hit : 1 memory access (frame from TLB) → fast TLB miss : 2 memory accesses (page table, then data) → slow
How to draw this in exam
  1. Top-left box: Logical address, drawn as two cells “page number | offset”.
  2. Page-number line goes to a TLB box above and to the page table box below.
  3. Page table = column of pairs “page → frame”, one row highlighted.
  4. Right side: two cells “frame number | offset”, arrows joining both sources into it.
  5. Below it, box Physical address, with a note that the offset is copied unchanged.
  6. Write the hit/miss line: 1 access on a hit, 2 accesses on a miss.

Effective access time with and without a TLB

CaseMemory accesses per referenceEAT model (α = TLB hit ratio)
No TLB at all — page table lives in RAM2 always EAT = 2 × tmem  (with tmem = 100 ns → 200 ns)
TLB present, its search time counted separately1 on a hit, 2 on a miss EAT = α(tTLB + tmem) + (1 − α)(tTLB + 2·tmem) — the form used by the Feb-2019 answer on the next card
TLB searched concurrently with main memory, so its time is free1 on a hit, 2 on a miss EAT = α·tmem + (1 − α)·(2·tmem) = (2 − α)·tmem
Exam tipThree marks = 3 sentences + the diagram. Say “small hardware cache of recent page→frame translations, searched by content in parallel”, give hit and miss paths, and finish with “because of locality the hit ratio is high, so the average cost is close to one memory access”.
Unit II · TLB Numerical

For a paged system, TLB hit ratio is 0.8. Let the RAM access time 't' be 100ns and the TLB access time 'T' be 50 ns. Calculate effective memory access time (with TLB).

Older PYQ — syllabus gap First Term Feb 2019 · Q.3(a) 5 Marks High
Asked in: First Term Feb 2019 · Q.3(a) (5 marks) · End Term Jul 2016 · Q.2(b) (associative registers 100 ns / page table 180 ns, find the hit ratio for EAT 125 ns — marks not printed, and its printed answer is impossible, see the note below).
Show answer

Given: hit ratio α = 0.8, main-memory (RAM) access time t = 100 ns, TLB access time T = 50 ns.

Model. The TLB is read on every reference, so T appears in both branches. On a hit, one memory access follows. On a miss, the page table is read from memory and then the word itself is read — two memory accesses.

EAT = α(T + t)      +  (1 − α)(T + 2t)
    = 0.8(50 + 100)  +  0.2(50 + 2 × 100)
    = 0.8(150)       +  0.2(250)
    = 120.0 + 50.0
    = 170.0 ns
BranchProbabilityTimeContribution
TLB hit → 1 memory access0.850 + 100 = 150 ns120.0 ns
TLB miss → page-table access + data access0.250 + 200 = 250 ns50.0 ns
Effective access time170.0 ns

Sanity check: 170 ns sits between the 1-access cost (150 ns) and the 2-access cost (250 ns), and it is much better than the 2 × 100 = 200 ns you would pay with no TLB at all.

Verification note170 ns is both the re-solved value and the value printed in the Feb-2019 answer, so this one is safe to reproduce. The Jul-2016 companion question is not: its printed working is EAT = [x(100+180)] + [(1−x)(180+100+180)] ⇒ 125 = 460 − 180x ⇒ x = 1.86, i.e. a “hit ratio” greater than 1, which cannot exist. With the same model re-solved from the given numbers — 100 ns for a reference satisfied by the associative registers and 180 ns for one that must go through the main-memory page table — the equation is 125 = 100x + 280(1 − x), which gives x ≈ 0.861. Write the 170 ns answer here and, if the 2016 data appear, write ≈ 0.861 and note that the book’s 1.86 is impossible.

K. Segmentation

Translation
Unit II · Segmentation

Explain paging and segmentation memory management techniques. Also, discuss the problems associated with paging and segmentation.

Recent PYQ — must do Mid Term Oct 2025 · Q.3(b) 5 Marks Very high
Asked in: Mid Term Oct 2025 · Q.3(b) (5 marks — the segmentation half is answered here, the paging half in section I, the comparison in section L) · End Term Jan 2024 · Q.5(a) (7 marks, segmentation with paging) · Mid Term Oct 2024 · Q.1(c) · older: End Term May-June 2018 · Q.3(a).
Show answer

Segmentation is a memory-management scheme that supports the user’s view of memory. A logical address space is a collection of segments — each a named, variable-length logical unit: the main program, a procedure, a function, an array, a stack, a symbol table, a set of parameters. A logical address is a two-tuple <segment-number, offset>: “which piece”, and “how far into it”.

The segment is not a page in disguise: it has meaning to the programmer and the compiler, it grows and shrinks at run time, and its length is bounded by the address bits (s bits segment number, d bits offset ⇒ 2s segments of up to 2d bytes each).

The segment table: base + limit

Each process has a segment table holding two numbers per segment:

  • Base — the starting physical address where that segment lives in memory;
  • Limit — the length of the segment (its legal offset range).

Translation of logical address <s, d>: index entry s of the segment table, perform the limit check d < limit; if it passes, physical address = base(s) + d. If it fails, the reference is illegal and a segmentation-fault trap is raised — note that this hardware check is nothing to do with the “segmentation fault” of a badly written C program, it is the OS refusing an out-of-range address.

Protection and sharing fall out for free

  • Protection: because segments are logical units, per-segment control bits make sense — code segment read/execute-only, data segment read/write, stack read/write/expand. Any attempt to write the code segment or to execute the stack faults.
  • Sharing: two processes that use the same routine need only store the same base and limit in their segment tables, so a single physical copy is shared with segment-number agreement. Sharing a page is possible in paging too, but you cannot share “just the code part” of a page that also holds data.

Worked example (printed in the Oct-2025 answer)

Segment numberBaseLimit
01000500
13000700
250001000
Logical address (1, 200):
  check  200 < limit(1) = 700  → legal
  physical = base(1) + 200 = 3000 + 200 = 3200

Two more references on the same table, to show the check: (0, 431) is legal — 431 < 500 — and maps to 1000 + 431 = 1431; (2, 1400) is illegal because 1400 ≥ limit(2) = 1000, so the hardware traps instead of producing an address.

Fig K-1 · Segmentation: logical <s, d> → segment table → base + d
LOGICAL SPACE Segment 0 (500) Segment 1 (700) Segment 2 (1000) address = (s, d) = (1, 200) s = 1 SEGMENT TABLE segbaselimit 0 | 1000 | 500 1 | 3000 | 700 2 | 5000 | 1000 limit check: 200 < 700 ✔ else trap (segmentation fault) base + d PHYSICAL MEMORY 1000 – 1499 seg 0 3000 + 200 = 3200 free hole (external frag.) 5000 – 5999 seg 2 segments are variable size One reference, one table look-up, one addition — but the segments must each fit into ONE contiguous run of free memory, which is why pure segmentation needs dynamic storage allocation and suffers external fragmentation (the gap between segment 1 and segment 2 above). The cure is to page the segments — Fig M-1.
How to draw this in exam
  1. Three columns: Logical address space (stacked variable-height segments), Segment table (three columns: seg · base · limit), Physical memory (segments placed wherever there is room).
  2. Arrow from the segment number into the table, arrow out of the table labelled “base + offset”.
  3. Write the check “d < limit, else trap” beside the table.
  4. Leave a visible unused gap in the memory column and label it external fragmentation.

Problems associated with segmentation (as printed in the Oct-2025 answer)

ProblemWhy it happens
External fragmentationSegments are variable-sized, so free memory breaks into holes that no single segment can use; compaction is needed.
Complex memory allocationThe OS must search the hole list for a block that fits each segment exactly (first / best / worst fit), unlike paging’s “any frame”.
Compaction overheadGathering the holes means copying live memory while the system waits.
Variable segment sizesDifferent segments grow at run time (stacks, heaps), so their base and limit must be re-checked and re-loaded, and swapping a whole segment is expensive.
Exam tipFor 5 marks on “problems”: one line per row above, and one line naming the paging problems too (internal fragmentation, large page tables, the extra memory access per reference, page faults). The worked (1, 200) → 3200 example is worth writing even when the question asks only for theory.

L. Paging vs Segmentation

Translation
Unit II · Paging vs Segmentation

What is the difference between paging and segmentation?

Recent PYQ — must do Mid Term Oct 2024 · Q.1(c) Marks: not clearly visible Very high
Asked in: Mid Term Oct 2024 · Q.1(c) — the marks digit is not legible on the question line · End Term May-June 2017 · Q.2(a) “Describe working of paging memory management scheme. Compare paging with segmentation.” (6.5 marks) · End Term Jun 2019 · Q.3(c) “Why is Paging faster than Segmentation?” (2.5 marks) · the four rows the Oct-2024 answer prints are Basic/Fragmentation, Address, Size, Table.
Show answer
BasisPagingSegmentation
Basic idea / fragmentation produced Memory divided into fixed block size units (pages into frames) → internal fragmentation only (slack in the last page) Memory divided along the program’s own variable-size logical units → external fragmentation
Address The CPU splits the user’s single linear address into page number + offset; the user never names a page The user (compiler/linker) supplies segment number + offset — the address is explicitly two-dimensional
Size Page size is decided by the hardware and is a power of 2; identical for every page Segment size is specified by the user/programmer and varies with the module — a stack segment can grow at run time
Table Page table holds the base address (frame number) of each page Segment table holds segment number + segment length (base and limit) for each segment
Visible to the programmer?No — invisible; pages have no meaning to the program Yes — a programmer naturally thinks in main routine, functions, arrays, stack
DimensionOne-dimensional address spaceTwo-dimensional address space
Where placedAny free frame — no adjacency required, no compaction Each segment needs one contiguous run of free memory — dynamic allocation, compaction
Offset legalityOffset is always < page size by construction, so no size check is needed Every reference must be checked against the limit: d < limit, or trap
Protection / sharingCoarse — flags are per page, so code and data can end up in the same page Natural — per-segment read/execute/write flags, and identical base+limit entries give shared segments
Programming/OS effortEntirely the OS’s problem; the program needs no changes Requires the compiler/linker to produce the segment structure
SpeedFaster in practice — fixed sizes make allocation and replacement simple Slower — variable sizes force a hole search and compaction (Jun-2019 Q.3(c) asks exactly this)
Virtual memoryDirectly supports demand paging (the usual route to VM) Supports VM too, but pure demand segmentation is impractical — hence segmentation with paging
ExamplesPaging only: Cray-1, Convex-1 — and any modern x86/ARM kernel running a flat, paged address spacePure segmentation: Intel 8086 segment registers, iAPX 432. Both together (segmentation with paging): IBM 370/380, DEC VAX, AT&T UNIX System III, SPARC — see section M

The four rows the Oct-2024 answer prints, in its own order

  1. Basic / fragmentation — fixed block size → internal fragmentation vs variable size → external fragmentation.
  2. Address — CPU splits the user address into page number + offset vs the user supplying segment number + offset.
  3. Size — hardware decides the page size vs the user specifies the segment size.
  4. Table — page table holds the base address of each page vs segment table holds segment number and segment length.

Which one is better, and why — the Dec-2025 Q.4(a) answer

For modern operating systems, paging is generally considered better because:

  1. It eliminates external fragmentation.
  2. Memory allocation is simpler.
  3. It works efficiently with virtual memory.
  4. It is easier for the operating system to manage.

The same answer then adds the honest counterpoint, which is worth one line for full marks: however, segmentation is better for representing the logical structure of programs (code segment, data segment, stack segment) and provides more natural protection and sharing mechanisms — which is why real systems end up using segmentation with paging rather than choosing between them.

Exam tipWrite the table first — it is the whole answer. Then one summary line: “Paging is an artifact of the hardware designed to fit memory; segmentation is an artifact of the user’s view of memory designed to fit the program.” If asked “why is paging faster than segmentation?” (Jun-2019 Q.3(c), 2.5 marks), the three points are: fixed-size frames need no hole search, no compaction is ever required, and the offset needs no limit check because it is bounded by the page size by construction.

M. Segmentation with Paging

Translation
Unit II · Segmentation with Paging

Explain with a neat diagram the concept of segmentation with paging in virtual memory. What problem does it solve?

Recent PYQ — must do End Term Jan 2024 · Q.5(a) 7 Marks Very high
Asked in: End Term Jan 2024 · Q.5(a) (7 marks) · End Term May 2016 · Q.2(c) “Explain the address generation in segmentation with paging.” (4 marks) · First Term Feb 2018 · Q.3(a) “Why are segmentation and paging sometimes combined into one scheme? Explain with suitable diagram.” (5 marks) · End Term Jun 2019 · Q.2(b) (4 marks, the bit-field numerical solved inside this card).
Show answer

The problem it solves. Pure segmentation gives the user what they want — named, variable-length, separately protected and shareable logical units — but it inherits every ill of contiguous allocation: each segment must land in one contiguous run of free memory, so external fragmentation and compaction come back. Pure paging fixes placement (any frame will do) but destroys the user’s view: a page is a meaningless fixed-size slice that can straddle the end of one routine and the start of the next, so per-module protection and sharing get blunt.

The two-level scheme keeps both benefits. The address space is still divided into segments, but each segment is now paged into fixed-size pages, and those pages are allocated into any free frames. Segmentation supplies the programming-in-the-large structure; paging supplies the allocation mechanism underneath it.

In the words of the printed May-2016 answer“Segments can be of different lengths, so it is harder to find a place for a segment in memory than a page … it is possible to combine segmentation and paging into a two-level virtual memory system. Each segment descriptor points to a page table for that segment. This gives some of the advantages of paging (easy placement) with some of the advantages of segments (logical division of the program).”

Address generation, step by step

  1. The CPU produces a logical address of the form <segment-number s, page-number p, offset d>.
  2. Entry s of the segment table is fetched. It holds a segment-table entry (STE): a base that now points at the page table for that segment, plus the segment limit and protection bits.
  3. Entry p of that segment’s page table is fetched. It holds a page-table entry (PTE): the frame number (plus a valid bit — the page may be out on disk).
  4. The physical address is formed by concatenating the frame number with the offset: frame × frame size + d.
Fig M-1 · Segmentation with paging: segment table → page table → frame
LOGICAL ADDRESS (3 fields) segment number | page number | offset seg = 4 page = 2 off = 64 May-2016 figure: address 4 | 2 | 64 = page 2 of segment 4 SEGMENT TABLE STE 0 → page table 0 STE 1 → page table 1 STE 2 → page table 2 STE 3 → page table 3 STE 4 → page table 4 a table per segment page table for seg 0 PTE0 PTE1 PTE2 … page table for seg 4 PTE 2 → frame # 1 f = 1 PHYSICAL MEMORY (frames) frame 0 — free frame 1 = Page 2 of seg 4 frame 2 — free frame 3 = Page 0 of seg 0 frame 4 … 6 — other pages pages of one segment are scattered offset passes untouched Physical address = frame number ‖ offset = 1 ‖ 64 → frame 1, byte 64. Two table look-ups (segment table, then that segment’s page table) — so this scheme wants a TLB even more than plain paging does.
How to draw this in exam
  1. Top box: the logical address split into three fields — segment | page | offset.
  2. Left column: segment table whose entries are labelled “STE 0 … STE n → page table for that segment”.
  3. Draw two page tables hanging off the segment table (this is the “two-level” the examiner looks for) and arrow the chosen STE into its page table.
  4. One PTE carries a frame number; arrow it into a physical-memory column of frames.
  5. Show two frames holding pages of different segments — “frame 1 = page 2 of segment 4”, “frame 3 = page 0 of segment 0” — that is the whole point of the scheme.

What it buys, and what it costs

BuysCosts
No external fragmentation — the allocation unit is now a page, and any frame will do Two-level look-up: segment-table entry plus page-table entry before the data itself
Segments keep their names, their own growth and their own protection/sharing bits One page table per segment — more memory for tables, especially for tiny segments
A segment can be partially resident: some of its pages in, some on disk A TLB is effectively mandatory, otherwise the average access becomes three memory references
Only bounded internal fragmentation, in the last page of each segment More complex OS and hardware than plain paging

Worked bit-field numerical (Jun-2019 Q.2(b), 4 marks)

Given: a system using paging and segmentation with a virtual address space of up to 8 segments, each segment up to 229 bytes long, the hardware paging each segment into 256-byte pages.

Field askedWorkingBits
(i) Segment number8 segments = 233 bits
(ii) Page numberpages per segment = 229 ÷ 28 = 22121 bits
(iii) Offset within pagepage size 256 = 28 bytes8 bits
(iv) Entire virtual address3 + 21 + 832 bits

More page/frame arithmetic (Feb-2019 Q.4, Feb-2018 Q.4, Jun-2019 Q.2(b) variants) is worked on Numericals.

N. Virtual Memory

Virtual memory
Unit II · Virtual Memory

Write two advantages of virtual memory concept.

Recent PYQ — must do End Term Jan 2024 · Q.1(c) 3 Marks Very high
Asked in: End Term Jan 2024 · Q.1(c) (3 marks) · Mid Term Oct 2024 · Q.1(c) (paging/segmentation under virtual memory) · End Term Dec 2025 · Q.5(a) · First Term Feb 2019 · Q.2(b) “What is Virtual memory and how Overlay concept works, explain in short with example.” (4 marks), whose second half is answered in section U.
Show answer

Definition. Virtual memory is a memory-management technique that lets a system run a process even when not all of that process is in main memory. It does this by separating the logical address space — the program’s own view, which may be enormous — from physical memory, which is limited, and by bringing pages in from the backing store only when they are actually referenced (demand paging). The programmer sees a contiguous address space of 2m words; the hardware only ever holds the active subset.

The two advantages asked for (3 marks)

  1. A program bigger than physical memory can run, and more programs fit at once. Only the pages currently needed occupy RAM, so the sum of the logical address spaces of all processes may greatly exceed the size of main memory. Memory that would otherwise sit idle holding not-yet-used parts of a program is released for other work, which raises the degree of multiprogramming and therefore CPU utilisation and throughput.
  2. Faster start-up and cheaper, simpler programming. Loading a program no longer waits for its whole image to be read from disk — execution can begin as soon as the first page(s) are present, so response and load times drop, and the I/O per job falls too. Programs may also be written against a large, uniform, private address space, with code, data and stack segments protected and shared through the MMU, instead of the programmer having to fit inside the RAM that happens to be free.
Verification noteThe Jan-2024 printed answer is very thin and its wording is garbled in the scan — it reads roughly “allows too fast and easy processes” and “not need more memory space”. The two advantages above are the same two ideas (speed/ease of execution and not needing the whole program in memory) stated completely and correctly; the extraction notes flag this answer as “rewrite clearly”, so the book’s phrasing should not be copied into your paper.

Separation of logical from physical — the mechanism in one paragraph

  • Compile/link produces a logical address space that starts at 0 and is as large as the address width allows.
  • Run-time mapping by the MMU (Fig G-1) turns each reference into a physical one; with paging the mapping is per page, so a process’s physical footprint can be a scattered, partial subset of RAM.
  • A page not present in RAM is not an error — it is a page fault, and the OS brings it in (section P). That trap-and-fetch behaviour is precisely what makes the logical space bigger than physical memory without the program noticing.
  • Consequence for the OS: memory management becomes a policy problem — which pages to bring in (fetch policy: demand or prepaging) and which to throw out (placement policy: where in memory; replacement policy: which page).
Exam tip3 marks = one-line definition + two headed advantages + one closing line (“the logical address space is therefore decoupled from the size of RAM”). Do not spend time on overlays here — that is a separate 4-mark older question.

O. Demand Paging

Virtual memory
Unit II · Demand Paging

Explain what is Demand Paging? Differentiate between Paging and Segmentation and explain which one is better and why?

Recent PYQ — must do End Term Dec 2025 · Q.4(a) 4 Marks Very high
Asked in: End Term Dec 2025 · Q.4(a) (4 marks). The second half of this question is the paging-vs-segmentation table already answered at Paging vs Segmentation; the book itself sends you there with “Refer Q.1(c) from Mid Term Exam Oct. 2024 (Pg. 1-2024)”. Older papers touch demand paging only inside numericals: End Term Jun 2019 · Q.3(b) says “Assuming demand paging with three frames, how many page faults would occur …” (5 marks).
Show answer
Why this is on the Unit II memory pageThe book files the Dec-2025 demand-paging question under UNIT-III, but demand paging is explicitly a named line of your Unit II syllabus (“Virtual Memory: Demand Paging, Page Replacement, …”), and the coverage matrix lists it under Unit II. It is answered here, immediately before page faults and page replacement, which is where it belongs in the revision order.

Definition as printed in the Dec-2025 answer

Demand paging is a virtual memory technique in which a page is loaded into main memory only when it is required by a process. Instead of loading the entire program into memory at once, pages are brought into RAM on demand.

Working of demand paging (the five steps to write)

  1. A process starts execution.
  2. If the required page is already in memory, execution continues.
  3. If the page is not in memory, a page fault occurs.
  4. The operating system loads the required page from secondary storage (disk) into a free frame in RAM.
  5. The page table is updated and execution resumes.

Demand paging is a lazy form of paging: a process is not loaded page by page in advance. Only the pages actually needed at this moment are brought into memory, and a page is fetched only when it is referenced — on demand. The loader never reads the disk blocks of a page that is not yet needed, so a job can start executing with only its first page (or even nothing) resident. Because it swaps pages rather than whole processes, demand paging is also called lazy swapping.

The valid / invalid bit

  • Every page-table entry carries one extra bit: v (valid) or i (invalid).
  • valid — this page is currently in memory; the frame number in that entry is real and usable.
  • invalid — this page is not in memory right now (it was never brought in, or it was swapped out). Any reference to it must not use that entry’s frame number.
  • At the very start of a demand-paged process all entries are marked invalid, which is exactly the trick that allows a program to be “loaded” with zero page reads.
  • An attempted reference to an invalid page generates a trap to the operating system — this is the page fault handled in section P. The OS finds a free frame, reads the page from the backing store, changes the entry to valid with that frame number, and restarts the instruction.
  • Once every page of a process is valid, the process’s memory can no longer grow by faulting — that boundary is what limits a purely paged, non-virtual system.

Pure paging vs demand paging

BasisPure paging (load the whole process)Demand paging
What is brought in at startEvery page of the process, whether it is used or not Only the page(s) needed now; the rest stay on the backing store and are marked invalid
Startup I/OProportional to the full process size — many page reads before the first instruction Almost none — execution can begin immediately, hence “faster response”
Memory used per processThe process’s complete logical size Only its active subset (its working set), so it is much smaller
Degree of multiprogrammingLimited by total process sizes Higher — more processes fit, because each occupies less RAM at any instant
Page faultsNone during execution (all pages already valid) Inherent — every first reference to a page costs one fault, so the fault rate must be kept low
Wasted workPages that are never referenced (error handlers, rare branches) still occupy memory Nothing is loaded that is never used — but the loading cost is paid later, inside execution
Hardware neededPage table + MMUPage table with a valid/invalid bit + MMU + a way to trap on an invalid reference + replacement policy
Address space vs RAMSum of all processes must fit in RAM Logical address space may exceed RAM — this is virtual memory
Uses of codePrepaging: the OS guesses and pre-loads pages (pure paging is prepaging with all pages) Fetch policy “demand paging” + replacement policy (FIFO / LRU / Optimal) decide what leaves

When demand paging pays off — locality

A typical process references a small fraction of its pages most of the time (loops, hot functions, the active part of the stack). Because of that locality of reference, a modest number of frames can serve a huge address space with a low fault rate. If the fault rate p is small, the cost of virtual memory is nearly invisible; if p grows, the system collapses into thrashing — see the EAT formula in section R.

Exam tipFor 4 marks: definition (2 lines) → valid/invalid bit as its own headed paragraph with the trap sentence → a 6–8 row comparison table → one closing line on locality. Drawing the two-state entry (valid with a frame number / invalid pointing at a disk address) is a cheap extra.

P. Page Fault and Page-Fault Handling

Virtual memory
Unit II · Page Fault

What do you mean by a page fault? What actions are taken by the operating system when a page fault occurs?

Older PYQ — syllabus gap End Term May-June 2017 · Q.3(b) 3.5 Marks High
Asked in: End Term May-June 2017 · Q.3(b) (3.5 marks) — the printed answer gives a numbered 19-step handling sequence, condensed into the flowchart below · End Term Jun 2019 · Q.1(d) “What is hard page fault and soft page fault?” (2.5 marks). Demand-paging numericals that depend on this mechanism are on Numericals.
Show answer

Page fault — in a demand-paged system, an attempted reference to a page whose page-table entry is marked invalid, i.e. the page is not currently in a physical frame. The hardware traps to the operating system, which brings the page in from the backing store and then lets the same instruction run again. A page fault is not an error; it is the normal working mechanism of virtual memory.

Handling sequence (write these steps in this order)

  1. The CPU generates a logical address and the MMU consults the page table.
  2. The valid/invalid bit for that page is checked. If valid → nothing unusual happens; the memory reference is completed normally and execution continues.
  3. If invalid → the hardware raises a trap to the OS: the page-fault trap handler takes over and saves the process state.
  4. The handler examines the trap to confirm it really is a page fault (not an illegal address and not an I/O trap), and identifies which page is needed.
  5. The handler checks the page is a legal one for this process (in its address space and within its limits). An illegal reference means the process is terminated; a legal one continues below.
  6. A free frame is taken from the free-frame list. If there is no free frame, the page replacement algorithm picks a victim page.
  7. If that victim has been modified (its dirty bit is set) it is first written back to the backing store — one extra swap-out; if it is clean it can simply be overwritten.
  8. The needed page is scheduled for a disk read into the chosen frame; the faulting process is blocked and the CPU scheduler switches to another ready process (this idle time is what paging hardware exists to exploit).
  9. On completion of the I/O the frame is filled; if the frame is shared, the OS copies the new page into each private copy.
  10. The page-table entry (and usually the TLB) is updated: frame number written in and the valid bit set.
  11. The faulting instruction is restarted exactly where it left off — the program never learns that a fault happened, and this time the reference hits memory.
Fig P-1 · Page-fault handling flowchart
1 · Memory reference CPU → MMU → page table 2 · Page present? valid / invalid bit YES (valid) Normal access 1 memory access, continue NO (invalid) → trap 3 · Trap to the OS page-fault handler runs 4 · Find a free frame none? evict a victim page 5 · Victim dirty? write it back first 6 · Schedule disk read block this process, run another 7 · Update page table frame number + set valid bit, fix TLB 8 · Restart the instruction the same reference now succeeds — 1 access instead of a fault Cost of one fault = service interrupt + find frame + read page + restart ≈ 8–10 ms on a typical disk, against ~100 ns for an ordinary access — which is why the fault rate p must stay tiny (section R).
How to draw this in exam
  1. Start with a box Memory reference, then a diamond Page in memory?.
  2. YES goes right to “normal access”; NO goes down into the OS column.
  3. Below the diamond draw the four OS boxes in a row: find free frame / evict → swap out if modified → disk read → update page table.
  4. End with Restart the instruction and an arrow back to the top of the diagram.
  5. Label the whole path “trap” on the NO branch — that word carries marks.

Hard vs soft page fault (Jun-2019 Q.1(d), 2.5 marks)

TypeMeaningWhat the OS does
Hard page fault (major) The page is genuinely not in memory — it has to be read in from the backing store / disk. The whole sequence above, including the disk I/O; costs milliseconds.
Soft page fault (minor) The page is already somewhere in physical memory (it is in the page cache, or is shared and already resident) but this process’s page-table entry does not yet point at it. No disk read — the OS just maps the existing frame and marks the entry valid; costs microseconds.
Verification noteThe May-June 2017 printing expands this answer into 19 numbered micro-steps (state save, trap-table inspection, legal-address test, free-frame list, disk read, shared-page copying, table update, restart). The eleven steps written above carry the same content in the order the examiner can tick; if you can recall the 19-step form, write it — but never omit restart the instruction, which is the step students most often forget and which is printed explicitly in the source answer.

Q. Page Replacement

Virtual memory
Unit II · Page Replacement

Explain any two page replacements algorithms. Give an illustration.

Recent PYQ — must do Asked numerically in EVERY recent paper Very high
Asked in: Mid Term Nov 2023 · Q.2(a) (marks not clearly visible) · End Term Jan 2024 · Q.5(b) (8) · Mid Term Oct 2024 · Q.2(b) (5) · End Term Dec 2024 · Q.5(a) (6.5) · Mid Term Oct 2025 · Q.4(b) (5) · End Term Dec 2025 · Q.4(b). The wording above is printed verbatim in End Term May 2016 · Q.3(a) (5 marks), where FIFO and LRU were illustrated. The frame-by-frame tables are solved on Numericals — this card is the theory only.
Show answer

Why page replacement is needed

A process is given fewer frames than it has pages, and the total demand of all processes exceeds physical memory. So when a page fault occurs and the free-frame list is empty, the OS cannot simply read the page in — it must first choose a page that is already resident and evict it. If the victim is clean it can be discarded and its frame reused; if it is dirty (modified bit set) it must be written back to backing store first, so a fault costs two memory transfers instead of one. The rule for picking the victim is the page-replacement algorithm.

The reference-string model

  • A process’s page accesses are abstracted into a string of page numbers — e.g. 7, 0, 1, 2, 0, 3, 0, 4, … Each number is a reference to that page.
  • The process is given n frames, all empty to start with (an empty frame is always used first, and that still counts as a fault).
  • Walk the string left to right: a reference to a page already in a frame is a hit; otherwise it is a page fault and, when there is no free frame, the algorithm names the victim.
  • The score of an algorithm is the total number of page faults it produces on the string — fewer faults means a lower effective access time.
  • The model assumes all frames are empty at the start, references the same string for every algorithm so the comparison is fair, and ignores the cost of a modified victim (which in reality makes FIFO look worse than it scores here).

FIFO — First-In, First-Out

Replace the page that has been in memory longest. Keep the resident pages in load order and evict the head; conceptually it needs one register per page holding its load time, or a queue.

  • Merits: trivially easy to understand and to implement — a queue or a clock-hand variant is enough; no per-reference updates, so no extra hardware cost.
  • Demerits: age is a poor guide to future use — an old page inside a hot loop gets thrown out and faults straight back; and it suffers Belady’s anomaly (more frames, more faults).

LRU — Least Recently Used

Replace the page that has gone longest without being referenced. It is the reverse of FIFO in one important respect: it uses the past usage order as a prediction of future use, which is justified by locality of reference — a page not touched for a long time is unlikely to be touched soon.

  • Merits: usually far fewer faults than FIFO on real strings; it never suffers Belady’s anomaly, because it is a stack algorithm — the set of pages LRU would hold in n − 1 frames is always a subset of the set it holds in n frames, so adding frames can never increase faults. Implemented by counters (load the smallest counter on a fault), a stack (move the referenced page to the top), or the clock/second-chance approximation used by real OSs.
  • Demerits: expensive in pure hardware — every memory reference must reorder the structure, so it needs special registers or frequent timer updates; OSs therefore approximate it.

Optimal (MIN / Belady’s algorithm) — replace the page used farthest in the future

Look forward along the reference string and evict the page that will not be needed for the longest time (a page never used again is the perfect victim).

  • Merits: provably the fewest faults of any algorithm for the same number of frames and the same string, so it is the benchmark the others are measured against. It also never suffers Belady’s anomaly.
  • Demerits: requires future knowledge of the reference string, so it is not implementable in a real OS (only approximable, e.g. by a working-set model).

The ordering rule to remember

On every string re-solved from these papers (3 or 4 frames, all empty)Result
Faults by Optimal vs LRU vs FIFOOptimal ≤ LRU ≤ FIFO — Optimal is never worse than any other algorithm, and LRU is never worse than FIFO on these data
Oct-2024 Q.2(b), 3 framesFIFO 13 · LRU 12 · Optimal 9 → Optimal is “most efficient”
Dec-2024 Q.5(a) ≡ Nov-2023 Q.2(a), 3 framesFIFO 16 · LRU 15 · Optimal 11
Oct-2025 Q.4(b), 3 framesFIFO 9 · LRU 10 · Optimal 7 — this is the one string where LRU loses to FIFO; Optimal is still the minimum
Dec-2025 Q.4(b), 4 frames (A–G)FIFO 13 · LRU 10 · Optimal 8
Jan-2024 Q.5(b), 4 framesFIFO 10 · LRU 8 = Optimal 8 — so the answer to “which gives the minimum” is both LRU and Optimal, not Optimal alone

So the safe wording is: “Optimal is always ≤ the others; LRU is normally better than FIFO but not guaranteed — check the string.” The full traces and Gantt-style frame grids are on Numericals · page replacement.

Verification noteTwo printed totals in the recent papers disagree with the re-solved traces and must not be copied: Oct-2024 Q.2(b) prints FIFO = 12 although its own step table lists 13 “Yes” rows (faults land on references 1, 2, 3, 6, 7, 9, 10, 12, 13, 15, 16, 17, 18 = 13), and Jan-2024 Q.5(b) prints a single trace totalling 16 faults although three algorithms are asked — re-solved with 4 frames the answers are FIFO 10, LRU 8, Optimal 8. Every number in the table above is the independently re-solved one.
Unit II · Belady’s Anomaly

What is Belady's Anomaly? Explain with the help of suitable examples.

Older PYQ — syllabus gap End Term Jul 2016 · Q.2(c) Marks: not clearly visible Medium
Asked in: End Term Jul 2016 · Q.2(c) (marks not printed on the question line) · First Term Feb 2017 · Q.1(d) “What is Belady’s Anomaly.” (2.5 marks). Not asked in any 2023–2025 paper as a theory question, though the re-solved FIFO numbers in those papers show it in action.
Show answer

Definition. Belady’s anomaly is the counter-intuitive property of some page-replacement algorithms — FIFO is the classic case — whereby increasing the number of page frames can increase the number of page faults. It is named after László Bélády, who demonstrated it in 1969. It should be impossible: more memory ought to mean fewer misses. Its existence proves that FIFO is not a stack algorithm.

The worked demonstration (the example printed in the Jul-2016 answer)

Reference string: 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4

Frames allocatedBehaviour of FIFOPage faults
3 framesLoads 3, 2, 1; then 0 pushes out 3; 3 pushes out 2; 2 pushes out 1; 4 evicts 3; … by the end the resident set keeps missing the pages that were evicted in rotation. 9 faults
4 framesThe extra frame changes the eviction order. Every page now circulates one step later, so the queue positions shift and references that used to hit now miss. 10 faults — MORE, with MORE memory

Why it happens: FIFO evicts by age of loading, and a page’s load order is not related to its future use. Adding a frame therefore does not simply “keep one more page” — it re-orders the whole eviction sequence, and the new sequence can evict a page an instant before it is referenced. With LRU this cannot happen: if a page would be kept in n − 1 frames by recency, it is certainly kept in n frames, so the resident set for n − 1 frames is a subset of that for n frames (the stack property) and faults can only fall or stay equal. Optimal has the same guarantee.

AlgorithmSuffers Belady’s anomaly?Reason
FIFOYesEviction ignores usage history — not a stack algorithm
LRUNoStack algorithm — smaller frame set’s pages are a subset of the larger one’s
OptimalNoAlso a stack algorithm (decisions depend only on future-use distances)
MFU / NRU / ClockClock & NRU: not guaranteed; MFU generally behaves like LRU’s opposite Approximations inherit some of FIFO’s unpredictability
Verification noteThe Jul-2016 printing shows the two frame tables but its conclusion sentence is garbled as it stands: “In the first example (with fewer pages), there are 9 page faults, there are 10 page faults.” The intended meaning — and the re-checked result for the string above — is 9 faults with 3 frames and 10 faults with 4 frames, which is exactly the anomaly. Quote the two numbers as a pair and never as a single total. (A second, longer demonstration string appears in the recent papers: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1 with 4 frames gives FIFO 10 vs LRU 8 and Optimal 8 — the same lesson, solved frame by frame on Numericals.)

R. Performance of Demand Paging

Virtual memory
Unit II · Performance

If the average page fault service time of 25 ms and a memory access time of 100ns. Calculate the effective access time.

Older PYQ — syllabus gap End Term June 2019 · Q.1(h) 2.5 Marks High
Asked in: End Term June 2019 · Q.1(h) (2.5 marks) · End Term Jul 2016 · Q.2(b) (associative registers 100 ns, page table 180 ns, EAT target 125 ns → find the hit ratio; marks not printed) · First Term Feb 2019 · Q.3(a) TLB EAT, answered in section J. The recent papers reach the same topic through Dec-2024 Q.5(c) (TLB).
Show answer

Factor 1 — page-table size

A page table is another table in memory, and one entry is needed for every page of every process, so the table is large and must itself be stored in main memory. Its size is fixed by the number of address bits:

  • With a 16-bit address and a 1 KB (210) page: 26 = 64 entries — a few hundred bits per process, easily affordable.
  • With a 32-bit address and a 4 KB (212) page: 220 = 1,048,576 entries, which at 4 bytes an entry is about 4 MB of page table for one process — which is why real systems use multi-level, hashed or inverted page tables.
  • An inverted page table has one entry per frame, not per page, so its size is fixed by physical memory and is shared by all processes (Feb-2019 Q.4 asked exactly this: 32 frames ⇒ 32 entries, versus 256 entries in the ordinary table).

Factor 2 — address-space size

The size of a process’s logical address space is decided by the address width, not by how much RAM exists: 2m × n bytes for an m-bit logical address with n-byte words. The physical address space is decided by the number of frames × frame size. Those two are independent — and in a virtual-memory system the logical space is normally much larger, which is the whole point (Dec-2024 Q.5(b): 13-bit logical against 15-bit physical; Feb-2019 Q.4: 12-bit logical against 9-bit physical, where RAM is smaller than the program).

Factor 3 — the effective access time formula

Let p be the page-fault rate (0 ≤ p ≤ 1; p = 0 means no faults, p = 1 means every reference faults), ma the memory-access time and pf the total fault overhead. Then:

EAT = (1 − p) · ma  +  p · (page-fault overhead + swap page out
                              + read (swap) page in + swap page in)

      = (1 − p) · ma  +  p · pf
  • Page-fault overhead = service the interrupt + find a free frame + start the disk read + update the table + restart the instruction.
  • “Swap page out” appears only when the victim page is modified; a clean victim is discarded without a write.
  • “Read page” is bounded by seek + rotational latency + transfer, and dominates everything else.
  • The value of p cannot be computed — it is a property of the program’s behaviour, so it is measured empirically (count faults over an interval and divide by the number of references), or estimated from the reference string, as in thrashing.
  • Magnitude check with the numbers from the paper: ma = 100 ns and a fault service time of 25 ms = 25,000,000 ns. Even at p = 0.001, EAT = 0.999(100) + 0.001(25,000,000) ≈ 25,100 ns — a 250-fold slowdown. That is the real lesson of the question: virtual memory is only worth having while p stays very small.
Verification noteJun-2019 Q.1(h) is printed as “Effective access time = Page fault service time + memory access time = 25 + 100 = 125 ns”. That is dimensionally wrong — it adds 25 milliseconds to 100 nanoseconds and then labels the result ns. 25 ms = 25,000,000 ns. The correct answer to write is: convert both to the same unit, then apply EAT = (1 − p)·ma + p·pf; with the data given there is no page-fault probability, so EAT cannot be reduced to a single number and the fault rate must either be stated as a variable or assumed. If a fault is taken on every reference (p = 1) the EAT is 25,000,000 ns; with p = 0 it is 100 ns. Never reproduce “125 ns”.

The same caution applies to Jul-2016 Q.2(b), whose printed “hit ratio” comes out as 1.86 — an impossible probability; the re-solved value from the same model is x ≈ 0.861 (see section J).

S. Thrashing

Virtual memory
Unit II · Thrashing

Explain the concept of Thrashing in virtual memory.

Recent PYQ — must do Mid Term Oct 2025 · Q.1(d) 2 Marks Very high
Asked in (merged): Mid Term Oct 2025 · Q.1(d) (2 marks) · Mid Term Nov 2023 · Q.2(b) “What is cause of thrashing? What steps are taken to eliminate the problem?” (marks not printed on the question line — it shares a 10-mark Q.2 with the page-replacement numerical) · End Term May 2016 · Q.3(b) “Mention the cause that effect thrashing. How does degree of multiprogramming and CPU utilization effect tracing.” (2+2 marks; the sentence is garbled as printed) · End Term May-June 2017 · Q.2(c) (2 marks) · First Term Feb 2018 · Q.1(e) (2 marks) · First Term Feb 2019 · Q.1(d) (2 marks).
Show answer

Meaning. A process is thrashing when it is spending more time paging than executing. It does not have enough frames to hold the pages it is actively using, so it page-faults, replaces a page that it needs again almost immediately, faults again, and keeps cycling. The system as a whole looks busy — the paging device queue is full — while doing almost no useful work. The May-2016 printed definition is the one to quote: “A process is thrashing if it is spending more time paging than executing.”

Cause — the chain the papers ask for

  1. The OS monitors CPU utilisation. If utilisation is too low, it raises the degree of multiprogramming by admitting another process — without regard to which processes already own frames.
  2. A process enters a new phase of execution and needs more frames. It starts faulting and takes frames away from other processes.
  3. Those processes need the pages that were taken from them, so they fault too, and steal frames in turn.
  4. All these faulting processes queue for the paging device. While they wait, the ready queue empties and CPU utilisation falls.
  5. The CPU scheduler sees falling utilisation and reacts the only way it knows — it admits even more processes, which steals more frames and lengthens the paging queue.
  6. The feedback loop closes: page-fault rate rises tremendously, effective memory-access time rises, and no work gets done because the processes spend all their time paging. The frame allocation may even fall below the minimum a low-priority process needs, forcing it to be suspended and paged out entirely — the “swap-in, swap-out level of intermediate CPU scheduling” named in the May-2016 answer.

Effect

  • CPU utilisation and system throughput collapse, while paging-device utilisation saturates.
  • Effective access time explodes — the EAT of section R with p → 1.
  • Response time and turnaround time become terrible even though the ready queue is short.
  • The system may appear hung; the swap/paging device is the bottleneck, not the CPU.
Fig S-1 · CPU utilisation vs degree of multiprogramming
maximum CPU utilisation optimum degree of multiprogramming THRASHING REGION page-fault rate so high that adding a process REDUCES CPU utilisation utilisation drops sharply rising: each new process has enough frames to work degree of multiprogramming → CPU utilisation → 0 low optimum too many processes 100% 50%
How to draw this in exam
  1. Axes: y = CPU utilisation, x = degree of multiprogramming.
  2. Draw a curve that rises gently to a rounded peak about 60% along the x-axis.
  3. After the peak make it fall sharply, then flatten near the bottom.
  4. Shade everything right of the peak and write THRASHING REGION inside it.
  5. Mark the peak “optimum degree of multiprogramming / maximum CPU utilisation” — that single label is what the 2-mark question is really testing.

Relationship in words

As the degree of multiprogramming increases, CPU utilisation also increases — but more and more slowly — until a maximum is reached. If the degree of multiprogramming is increased even further, thrashing sets in and CPU utilisation drops sharply. At that point, to raise CPU utilisation and stop thrashing, the only remedy is to decrease the degree of multiprogramming. The counter-intuitive part — that “more processes” must mean “less work done” — is the answer’s centre of gravity.

How to eliminate / prevent it

  • Reduce the degree of multiprogramming — suspend (swap out) some processes and free their frames for the ones that remain. This is the direct, printed remedy.
  • Give each process at least the number of frames it needs for its active pages, instead of spreading frames evenly; the two standard formulations of “how many that is” are the working-set model and the page-fault-frequency (PFF) control.
  • Monitor the page-fault rate per process (counters + a timer, or reference bits) and act on it: raise a process’s allocation while its fault rate is above target, lower it when below — but never let the sum of allocations exceed capacity.
  • Prevent the feedback loop: do not use CPU utilisation alone as the admission signal, because during thrashing low utilisation is a symptom, not a reason to admit more work.
Exam tipFor 2 marks: the one-line definition + one cause + the graph with the shaded region. For a 6–8 mark version add the 6-step cause chain and the elimination list; the graph earns the difference every time.

T. Demand Segmentation

Virtual memory
Unit II · Demand Segmentation

Demand segmentation — segments brought in on demand, segment faults, and why the scheme is rarely used

Syllabus only — no direct PYQ Not asked in either book Safety
Show answer
Why this section is hereDemand segmentation is the last named line of the “Virtual Memory” part of your Unit II syllabus, and — like swapping — it is not asked as a question in either book. The extraction notes list it as “NOT FOUND” for every paper from 2016 to 2025, and the coverage matrix marks it “cover for safety”. One tight paragraph plus the reason it lost is enough insurance; do not spend a whole evening on it.

Demand segmentation is the application of lazy loading to segments instead of pages. Not all of a process’s segments are brought into memory when it starts, and — as the Jan-2024 answer to Q.5(a) puts it for virtual-memory segmentation — segments may be “created but not all at once, not at run time of the program”; a segment is loaded only when the program first references it. Until then its segment-table entry is marked invalid.

How it works

  • Each process is divided into logical segments (main routine, procedure, array, stack …) exactly as in section K.
  • The segment table entry carries base + limit plus a valid bit. Invalid = not resident.
  • A reference to an invalid segment causes a segment fault: the OS traps, finds a free block of memory large enough for the whole segment, reads it in from the backing store, updates the entry to valid and restarts the instruction.
  • Advantages are the same ones as for demand paging: startup I/O and memory per process are both proportional to what is actually used, and the logical address space can be much bigger than RAM.

Why it is rarely used

ProblemConsequence
Segments are variable sized A segment fault needs one contiguous free block as large as the whole segment — enough free memory in total is not enough. The fault may fail even though RAM is half empty.
Swapping a segment is expensive Transfer cost is proportional to the segment, which can be megabytes, and it must be paid as a single blocking operation rather than page by page.
External fragmentation returns Loading and removing variable-sized segments chops memory into holes; compaction is needed, and compaction while other segments are being faulted in is very costly.
Segments grow at run time Stacks and heaps expand, so a resident segment may outgrow its block and have to be moved — which demands a relocation mechanism and a bigger hole at exactly the wrong moment.
Replacement is awkward Evicting one big segment frees a lot at once, but the granularity is coarse, so the OS either throws out too much or cannot find a victim that fits the hole pattern.

The practical resolution: real systems keep the user-visible segmentation and put demand paging underneath it — segmentation with paging (section M), or the pure-virtual-memory-over-segments variant used by the Intel Core architecture. Then the on-demand unit is a fixed-size page, any free frame will accept it, and the “find a hole as big as the segment” problem disappears. That single sentence is the answer to “why is demand segmentation not used?”.

U. Overlay Concepts

Virtual memory
Unit II · Overlays

What is Virtual memory and how Overlay concept works, explain in short with example.

Older PYQ — syllabus gap First Term Feb 2019 · Q.2(b) 4 Marks Medium
Asked in: First Term Feb 2019 · Q.2(b) (4 marks) — note that this single question asks virtual memory and overlays together, so the virtual-memory half is answered in section N. No 2023–2025 paper asks overlays at all; the coverage matrix marks the topic “cover for safety”.
Show answer

Overlay. An overlay is a program module that is kept on disk and loaded into main memory only while it is needed, then overwritten by another module when control moves on. The program is split into pieces that are never required simultaneously, and one fixed region of memory — the overlay area — is shared by all of them: whatever is needed now occupies it. This lets a program larger than available memory run on a system with no virtual memory at all, which is exactly what early compilers, assemblers and linkers did.

Who decides — the key distinction. In overlays the programmer (or the program’s own structure) decides which routines are mutually exclusive, how big the overlay area must be, and when to call the overlay driver to load the next module. In swapping and paging the operating system makes all those decisions, with the program completely unaware. That one difference — programmer-managed versus OS-managed — is the mark.

BasisOverlaysSwappingPaging
Managed byThe programmer — the code must be split and the load calls written into itThe operating system (medium-term scheduler) The operating system + MMU hardware
Unit movedOne overlay module (whatever size the programmer chose) An entire processOne fixed-size page
Program aware of it?Yes — the program is written around the structure and calls the overlay loader explicitlyNo — the process just disappears and reappears No — completely invisible to the program
Hardware supportNone — works on a plain machine with a loader routine Relocation register / relocatable codeMMU, page tables, valid bits, trap on invalid page (TLB for speed)
Address spaceStill real addresses; the overlay region is addressed at run time by fixed offsetsLogical addresses must be relocatable Logical ≠ physical; virtual address space may exceed RAM
Deciding what is neededStatic, decided at design time from the program’s control flowLoad and priority driven, dynamicDemand driven — whichever page is referenced (dynamic, with a replacement policy)
OverheadLoading is by explicit call; no page faults, no table look-ups Whole-process transfer costFault handling + translation on every reference
Where still usedTiny embedded systems, ROM-limited devices, historical DOS programsControlled real-time / batch systemsEvery general-purpose OS today

Overlay structure — a small worked example

Suppose a program whose memory budget is 32 KB consists of a main routine that is always active plus three branches of which only one runs at a time:

ModuleSizeWhen needed
Main routine (resident)12 KBAlways
Overlay A — syntax analysis8 KBOnly during pass 1
Overlay B — code generation6 KBOnly during pass 2
Overlay C — optimiser10 KBOnly on request
Overlay driver (resident loader routine)2 KBAlways
Memory layout (32 KB budget)
  0  – 11 KB   main routine            (resident)
 12  – 13 KB   overlay driver          (resident)
 14  – 23 KB   OVERLAY AREA  = 10 KB   ← the biggest single module, A or B or C at a time
 24  – 31 KB   data area

Without overlays : 12 + 8 + 6 + 10 + 2 = 38 KB  → does NOT fit in 32 KB.
With overlays    : 12 + 2 + 10 = 24 KB resident, 8 KB spare  → fits.

Run sequence
  main → driver.load(A) → run A → return → main → driver.load(B) → run B → …
  Loading B overwrites the bytes that held A; A is re-read from disk only if needed again.

Three rules the example shows, and the ones worth stating in an answer:

  1. Only mutually exclusive modules may share one overlay area — the split must follow the program’s control flow, otherwise a needed module gets overwritten.
  2. The overlay area must be at least as large as the largest module that can occupy it (10 KB above), so a single oversized module ruins the design.
  3. Time is traded for space: every re-load is a disk read, so the frequently needed module should be made resident and the rarely needed ones overlaid.
Link back to virtual memoryOverlays solve the same problem virtual memory solves — a program bigger than RAM — but they push the work onto the programmer. Demand paging is the automated, fine-grained version of the same idea: the “overlay area” becomes all of free memory, the “module” becomes a page, and the “driver” becomes the page-fault handler (section P). Write that sentence whenever a question pairs the two, as Feb-2019 Q.2(b) does.

Memory Management Checklist

Track

Ticks are saved in this browser and survive a refresh. Progress also feeds the dashboard. Two of these are pure insurance items — swapping, demand segmentation and overlays are named in the syllabus but are not asked as questions in either book — so they are deliberately short on this page.