Unit 3: Memory and device management
Operating Systems notes · PTU syllabus (BSIT303/BSBC403)
On this page
- Unit summary
- Address binding, relocation, loading and linking
- Logical and physical addresses and swapping
- Memory sharing and protection
- Paging and segmentation
- Virtual memory: demand paging, page replacement and thrashing
- I/O devices, controllers, device drivers and disk scheduling
- Key terms
- Quick revision
- Important questions
Unit summary
Memory and device management keep programs in memory and data flowing to and from devices. This unit covers address binding, relocation, loading and linking, memory sharing and protection, paging and segmentation, virtual memory — demand paging, performance, page replacement and thrashing — I/O devices and controllers, device drivers, and disk scheduling and management.
After this unit you can
- Explain address binding, relocation, loading and linking
- Explain paging and segmentation and memory protection
- Explain virtual memory, page replacement and thrashing
- Explain I/O devices, drivers and disk scheduling
PTU syllabus topics
- Address binding
- relocation
- loading
- linking
- memory sharing and protection
- paging and segmentation
- virtual memory (demand paging, performance, page replacement, thrashing)
- I/O devices and controllers
- device drivers
- disk scheduling and management
Topic 1
Address binding, relocation, loading and linking
- Address binding: mapping program addresses to memory addresses at compile time (absolute code), load time (relocatable code) or execution time (dynamic, using an MMU).
- Relocation: adjusting addresses when a program is loaded at a different location — relocation register adds a base value.
- Loading: static loading (whole program before execution) vs dynamic loading (routines loaded when called).
- Linking: static linking (libraries copied into the executable) vs dynamic linking (shared libraries — .dll, .so — linked at run time).
Example
Run-time binding: a program uses logical address 340. If it is loaded with a relocation (base) register value of 14,000, the CPU accesses physical address 14,340. If the program is moved, only the base register changes.
Exam tip
Binding can occur at compile time, load time or execution time; dynamic linking loads library routines only when needed.
Topic 2
Logical and physical addresses and swapping
Swapping moves a whole process temporarily from main memory to a backing store (disk) and later back, so more processes can share memory. A logical address is generated by the CPU; a physical address is the actual location in memory. The Memory Management Unit (MMU) maps logical to physical addresses at run time, for example by adding a relocation (base) register value. Swapping temporarily moves a process from memory to disk (backing store) and back, so that more processes can run than fit in memory at once.
Example
Swapping in practice: with memory full, the OS swaps out an idle process to disk to load a new one. When the idle process is needed again, it is swapped back in, possibly at a different memory address.
Exam tip
The memory management unit (MMU) converts logical addresses to physical addresses at run time.
Topic 3
Memory sharing and protection
Memory can be shared — for example, several processes running the same program can share one copy of its read-only code — while each has its own data.
- Protection: base and limit registers, page-table protection bits (read, write, execute), valid–invalid bits.
- Sharing: shared pages for common code (reentrant code), shared memory segments for IPC.
Example
Shared code: if 30 students run the same text editor on a server, the editor's code is loaded once and shared, while each student's document is kept in separate, protected memory.
Exam tip
Protection uses base and limit registers or page-table bits; sharing uses common pages or segments.
Topic 4
Paging and segmentation
Paging divides logical memory into fixed-size pages and physical memory into frames of the same size. A page table maps each page to a frame, so a process need not be contiguous. Paging removes external fragmentation.
- Logical address = (page number p, offset d); physical address = frame number × page size + d.
Segmentation divides a program into variable-size logical segments (code, data, stack). A segment table stores each segment's base and limit.
Unit
Fixed-size pages
Variable-size segments
View
Physical, invisible to the programmer
Logical, matches program structure
Fragmentation
Internal (last page)
External
Table
Page table
Segment table with base and limit
Example
Paging calculation: with a page size of 4 KB (4,096 bytes), logical address 10,000 is page 2 (10,000 ÷ 4,096) with offset 1,808. If page 2 is in frame 5, the physical address = 5 × 4,096 + 1,808 = 22,288.
Exam tip
Paging avoids external fragmentation but may cause internal fragmentation; segmentation matches the program's logical structure.
Topic 5
Virtual memory: demand paging, page replacement and thrashing
Virtual memory lets a process run even if only part of it is in memory. Demand paging loads a page only when it is needed; accessing a page not in memory causes a page fault.
FIFO
The oldest page in memory
Simple; Belady's anomaly possible
Optimal
The page not needed for the longest time
Lowest faults; needs future knowledge
LRU
The least recently used page
Good approximation of optimal
Example
Reference string 7, 0, 1, 2, 0, 3, 0, 4 with 3 frames under FIFO gives 7 page faults: 7, 0, 1, 2, 3, 0, 4 (only the 5th reference, 0, is a hit).
Frame allocation can be equal or proportional to process size. Thrashing happens when processes have too few frames and spend more time paging than executing; it is controlled with the working-set model or by reducing multiprogramming.
Effective access time
(1 − p) × memory access time + p × page fault service time
Note
p = page fault rate; even a small p greatly increases access time
Topic 6
I/O devices, controllers, device drivers and disk scheduling
I/O devices connect through controllers; data moves by programmed I/O, interrupts or DMA. A disk has platters, tracks, sectors and cylinders; access time = seek time + rotational latency + transfer time. Disk scheduling reduces seek time.
| Algorithm | How it moves the head |
|---|---|
| FCFS | Serves requests in arrival order |
| SSTF | Serves the nearest request next (may starve far ones) |
| SCAN (elevator) | Moves end to end, serving requests on the way |
| C-SCAN | Serves in one direction only, then jumps back |
| LOOK / C-LOOK | Like SCAN / C-SCAN but turns at the last request |
Exam tip
For disk problems, draw the head movement on a number line and add up every cylinder moved.
- Device driver: OS module that hides device details and translates generic I/O requests into device-specific commands.
- Disk management: formatting (low-level and logical), partitioning, boot block, bad-block handling, RAID for reliability and performance.
Example
SSTF disk scheduling: the head is at cylinder 50 with requests 82, 17, 43, 140 and 24. SSTF serves 43, 24, 17, 82, 140, moving 7 + 19 + 7 + 65 + 58 = 156 cylinders — fewer than FCFS (32 + 65 + 26 + 97 + 116 = 336).
Exam tip
Practise head-movement calculations for FCFS, SSTF, SCAN and C-SCAN.
Key terms
- Address binding
- Mapping program addresses to physical addresses
- Dynamic linking
- Linking libraries at run time
- Page fault
- Reference to a page not in memory
- Thrashing
- Excessive paging reducing useful work
- Device driver
- Software controlling a specific device
Quick revision
- Compile, load, execution-time binding; relocation; static and dynamic loading and linking.
- Logical vs physical; swapping; MFT, MVT.
- Protection bits; shared pages; paging, segmentation, TLB.
- Demand paging; EAT; FIFO, LRU, optimal; Belady's anomaly; thrashing and working set.
- I/O controllers, drivers; FCFS, SSTF, SCAN, C-SCAN, LOOK; disk management.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.What is address binding?
- Q2.Distinguish static and dynamic linking.
- Q3.What is a page fault?
- Q4.State Belady's anomaly.
- Q5.What is thrashing?
- Q6.Name four disk scheduling algorithms.
Long-answer questions
- Q1.Explain address binding, relocation, loading and linking.
- Q2.Explain paging and segmentation with diagrams.
- Q3.Explain virtual memory and page replacement algorithms (numerical).
- Q4.Explain I/O devices, device drivers and disk scheduling (numerical).
Stuck on this unit?
Message SBS on WhatsApp for help with Operating Systems, or to ask about studying B.Sc IT at Synetic.
