Learning outcomes
- Describe cache memory organisation and the principle of locality of reference.
This section adds focused theory and solved examples for common university-style questions on page replacement, partitioning, paging hardware, fragmentation, virtual memory, thrashing, locality of reference, and a few linked topics from scheduling and disk management.
A page replacement algorithm is needed when a page fault occurs and all available memory frames are already occupied. In that situation, the operating system must choose one page currently in memory to remove so that the required page can be loaded.
Good page replacement improves demand-paging performance. Poor page replacement can increase the page-fault rate and may even contribute to thrashing. The lecture plan also places FIFO, Optimal, and LRU exactly in the page-replacement section of the course. :contentReference[oaicite:3]{index=3}
In this modified optimal algorithm, the operating system predicts correctly only up to the next 4 page references (including the current reference). Page sequence:
Number of frames = 3, initially empty.
| Step | Page | Status | Frames after reference | Decision |
|---|---|---|---|---|
| 1 | 1 | Fault | [1] | Load 1 |
| 2 | 3 | Fault | [1, 3] | Load 3 |
| 3 | 2 | Fault | [1, 3, 2] | Load 2 |
| 4 | 4 | Fault | [4, 3, 2] | Replace 1 |
| 5 | 2 | Hit | [4, 3, 2] | — |
| 6 | 3 | Hit | [4, 3, 2] | — |
| 7 | 1 | Fault | [4, 1, 2] | Replace 3 |
| 8 | 2 | Hit | [4, 1, 2] | — |
| 9 | 4 | Hit | [4, 1, 2] | — |
| 10 | 3 | Fault | [4, 1, 3] | Replace 2 |
| 11 | 1 | Hit | [4, 1, 3] | — |
| 12 | 4 | Hit | [4, 1, 3] | — |
In multiprogramming with variable partitions, memory is not divided into fixed blocks beforehand. Instead, the operating system allocates a partition according to the actual size of each process. When a process terminates, its memory becomes a free hole that can be reused for another process.
This improves memory utilization because space is not wasted inside large fixed partitions assigned to small processes. However, the system may suffer from external fragmentation because free memory gets split into scattered holes.
| Basis | Fixed Partitioning | Variable Partitioning |
|---|---|---|
| Partition size | Predefined and fixed | Created dynamically according to process size |
| Memory waste | Can waste space inside partitions | Usually less internal waste |
| Fragmentation type | Mainly internal fragmentation | Mainly external fragmentation |
| Flexibility | Low | High |
| Compaction need | Usually not required | May be required |
| Complexity | Simpler | More complex allocation management |
| Type | Meaning | Where it commonly appears |
|---|---|---|
| Internal Fragmentation | Unused space exists inside an allocated block. | Fixed partitioning, paging last page |
| External Fragmentation | Total free memory exists, but it is scattered into small noncontiguous holes. | Variable partitioning, pure segmentation |
Consider a demand paging system with:
Number of bits used for page offset:
Therefore, page number bits in the logical address:
Maximum number of logical pages, and hence maximum number of page-table entries:
| Aspect | Paging | Segmentation |
|---|---|---|
| Basic unit | Fixed-size page | Variable-size logical segment |
| Programmer view | Not natural | Natural and logical |
| Fragmentation | Internal fragmentation | External fragmentation |
| Protection | Page-level bits | Segment-level base, limit, permissions |
| Best suited for | Modern virtual-memory systems with efficient frame management | Systems needing logical modular protection and sharing |
Virtual memory allows a process to execute even when the whole process is not in main memory. The process sees a large logical address space, while only the needed pages are kept in RAM and the rest stay on backing store.
The syllabus explicitly includes virtual memory, demand paging, page replacement algorithms, thrashing, and locality of reference in Unit IV. :contentReference[oaicite:4]{index=4}
| Type | Meaning |
|---|---|
| Logical Address Space | The set of addresses generated by the CPU for a process. |
| Physical Address Space | The set of actual addresses in main memory. |
The OS text explains that programs move from locality to locality, and that if a process is given enough frames for its current locality, page faults stay low; if not, the process can thrash. Locality is also the unstated principle behind caching. :contentReference[oaicite:5]{index=5} :contentReference[oaicite:6]{index=6}
Thrashing is a condition in which the system spends more time bringing pages into memory than executing useful instructions.
Locality of reference means a process tends to access a small group of pages repeatedly for some time. This is why caches work and why virtual memory is practical. If accesses were completely random, caching would be useless. :contentReference[oaicite:7]{index=7}
| Type of locality | Meaning | Example |
|---|---|---|
| Temporal | A recently used item is likely to be used again soon. | Loop counter reused in each iteration |
| Spatial | Nearby items are likely to be accessed soon. | Sequential array traversal |
The lecture plan explicitly lists paging hardware support (TLB) in the memory-management module. :contentReference[oaicite:8]{index=8}
A TLB (Translation Lookaside Buffer) is a small, fast associative memory that stores recently used page-table entries. If the page number is found in the TLB, address translation is very fast. Otherwise, the system must consult the page table in main memory.
Given:
Using the simplified model:
Page-reference string:
Number of page frames = 3
| Replacement algorithm | Number of page faults |
|---|---|
| FIFO | 8 |
| LRU | 9 |
| Optimal | 7 |
Optimal replacement always removes the page whose next use lies farthest in the future, so it gives the minimum possible page-fault count for a given reference string and frame count.
The lecture plan lists Multilevel Feedback Queue in the scheduling module. :contentReference[oaicite:9]{index=9}
MLFQ is a CPU-scheduling algorithm in which processes move between multiple queues based on their behavior. Short and interactive jobs are kept in higher-priority queues, while CPU-bound jobs gradually move to lower-priority queues.
Disk scheduling is part of the later storage module in your lecture plan. :contentReference[oaicite:10]{index=10}
Track requests:
Initial head position = 49
| Algorithm | Service order | Total head movement |
|---|---|---|
| SSTF | 50, 45, 60, 70, 80, 90, 25, 20, 10 | 131 |
| SCAN | 50, 60, 70, 80, 90, 99, 45, 25, 20, 10 | 139 |
| C-SCAN | 50, 60, 70, 80, 90, 99, 0, 10, 20, 25, 45 | 194 |
| LOOK | 50, 60, 70, 80, 90, 45, 25, 20, 10 | 121 |
Purpose of page replacement algorithm: choose a victim page when memory is full so that future page faults are minimized.
Variable partitioning: improves memory utilization by allocating memory according to process size, but suffers from external fragmentation.
Maximum page-table entries: for 32-bit logical address and 2 KB page size, entries = 221 = 2,097,152.
Demand paging fault counts with 3 frames: FIFO = 8, LRU = 9, Optimal = 7.
Required TLB hit ratio for 125 ns EAT: about 96.43%.