Memory Management Overview
- 26Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Why must a program be brought into main memory before it can be executed?
26 questions
- 1
Why must a program be brought into main memory before it can be executed?
Model answer
The CPU can only access main memory and its own registers; it cannot execute a program from secondary storage.
Explanation
The CPU fetches instructions and data from main memory. A program stored on disk must first be loaded into memory so the CPU can access it.
- 2
What is a 'stall' in the context of CPU memory access?
Model answer
When the CPU waits for data from main memory (which takes many clock cycles), it cannot do anything else during that wait; this is called a stall.
Explanation
Main memory access is slower than register access. While waiting for memory, the CPU is idle, causing a stall.
- 3
How do base and limit registers provide hardware address protection?
Model answer
Every memory address generated by a process is checked to ensure it is ≥ base and < base + limit. If not, an error is generated and the process is typically terminated.
Explanation
These registers define the legal memory range for a process. The hardware performs the comparison, preventing access outside that range.
- 4
What are the three times at which address binding can occur?
Model answer
Compile time, load time, and execution time.
Explanation
Binding can be done when the program is compiled (absolute code), when it is loaded into memory (relocatable code), or during execution (e.g., dynamically loaded libraries).
- 5
Why might an embedded system use absolute addresses at compile time?
Model answer
Because the program will never change location in memory, so there's no need for relocation overhead.
Explanation
Embedded systems have fixed memory layouts, so absolute addressing is simpler and more efficient.
- 6
What is the difference between a logical address and a physical address?
Model answer
A logical address is generated by the CPU from the process's perspective; a physical address is the actual location in main memory.
Explanation
The process sees its own logical address space (starting at 0), while the physical address may be different. The MMU translates between them.
- 7
What is the role of the Memory Management Unit (MMU)?
Model answer
The MMU maps logical addresses to physical addresses, often using a relocation register (base register).
Explanation
The MMU is hardware that performs address translation at runtime, allowing processes to be placed anywhere in physical memory without modifying the process code.
- 8
What is dynamic linking and why is it used?
Model answer
Dynamic linking delays the loading of library modules until they are needed at runtime, saving memory and allowing sharing of common code (e.g., DLLs).
Explanation
Instead of statically linking all libraries into the program, dynamic linking loads only when required, and multiple programs can share the same library in memory.
- 9
What is a DLL (Dynamically Loaded Library) and what common problem can occur with them?
Model answer
A DLL is a library that is loaded on demand. A common problem is version conflicts where different programs require different versions of the same DLL.
Explanation
DLLs allow code reuse, but if a program expects one version and another version is present, errors like 'wrong version of DLL' occur.
- 10
Explain the concept of swapping in memory management.
Model answer
Swapping moves a process out of main memory to backing store (disk) and later brings it back when needed, freeing memory for other processes.
Explanation
Swapping allows more processes to run than fit in memory by temporarily storing idle processes on disk. It requires fast backing store to minimize delay.
- 11
Why can't a swapped-out process be guaranteed to be loaded back into the same memory location?
Model answer
Because the memory it occupied may have been reused; the point of swapping is to free that memory for other processes.
Explanation
If the process returned to the same address, that memory would remain reserved, negating the benefit of swapping.
- 12
How does Android handle memory pressure compared to traditional swapping?
Model answer
Android terminates apps but saves their state, so they can restart from where they left off, avoiding swapping overhead.
Explanation
Instead of swapping to disk, Android kills background apps and preserves their state, reloading them when needed. This avoids slow disk I/O and wear on flash storage.
- 13
What does it mean for a process to be loaded contiguously in memory?
Model answer
All parts of the process must occupy a single continuous block of memory without gaps.
Explanation
Contiguous allocation simplifies address translation using base and limit registers, but leads to fragmentation over time.
- 14
Describe first-fit, best-fit, and worst-fit memory allocation strategies.
Model answer
First-fit selects the first hole large enough; best-fit selects the smallest hole that fits (leaves the smallest leftover); worst-fit selects the largest hole (leaves the largest leftover).
Explanation
Each strategy has trade-offs: first-fit is fast, best-fit minimizes waste but creates many small holes, worst-fit leaves larger holes but may waste more space initially.
- 15
Distinguish between external and internal fragmentation.
Model answer
External fragmentation occurs when total free memory is enough but scattered in small holes; internal fragmentation is wasted memory within an allocated block because the block is larger than needed.
Explanation
External fragmentation prevents loading a process even when enough total memory exists. Internal fragmentation is leftover space inside a partition (e.g., from paging).
- 16
What is compaction and why is it used?
Model answer
Compaction shuffles processes in memory to combine all free space into one contiguous block, resolving external fragmentation.
Explanation
By moving processes together, the scattered free holes merge into a single large hole, allowing larger processes to be loaded. It requires dynamic relocation at runtime.
- 17
What is segmentation in memory management?
Model answer
Segmentation divides a process into logical segments (e.g., code, data, stack), each with its own base and limit, allowing non-contiguous allocation of segments.
Explanation
Segmentation reflects the program's structure. Each segment has a name and length, and a segment table maps logical segment numbers to physical base addresses.
- 18
In paging, what are frames and pages?
Model answer
Frames are fixed-sized blocks of physical memory; pages are the same-sized blocks of logical memory. Each page maps to a frame via a page table.
Explanation
The OS divides physical memory into frames and logical memory into pages. A process's pages can be placed in any free frames, eliminating external fragmentation.
- 19
Why does paging eliminate external fragmentation?
Model answer
Because memory is divided into fixed-size frames, any free frame can be used for any page, so there are no holes between allocated blocks.
Explanation
All frames are the same size, so a process's pages can be scattered across frames. There is no need for contiguous space, so external fragmentation cannot occur.
- 20
What is the average internal fragmentation in a paging system with page size S?
Model answer
On average, half a page is wasted per process, i.e., rac{S}{2} bytes.
Explanation
Because a process rarely ends exactly on a page boundary, the last page is partially used. Over many processes, the average waste is half a page.
- 21
How does a page table translate a logical address to a physical address?
Model answer
The logical address is split into a page number and an offset. The page number indexes the page table to get a frame number; the frame number concatenated with the offset gives the physical address.
Explanation
The MMU uses the page table to map the page to a frame, then adds the offset within the page to produce the final physical address.
- 22
Why does paging require two memory accesses per logical address?
Model answer
One access to retrieve the page table entry (frame number) and another to access the actual memory location.
Explanation
The page table is stored in main memory, so fetching the frame number requires a memory read. Then the physical address is accessed, doubling the time.
- 23
What is a Translation Lookaside Buffer (TLB) and how does it improve performance?
Model answer
A TLB is a fast associative cache that stores recent page-to-frame mappings, allowing parallel search and reducing the number of memory accesses to one on a hit.
Explanation
The TLB sits between the CPU and the page table. If the page number is found in the TLB (hit), the frame number is obtained quickly; on a miss, the slower page table lookup is used.
- 24
Given a TLB hit ratio of 80%, a TLB search time of 20 ns, and memory access time of 100 ns, what is the effective access time?
Model answer
EAT=0.8imes(20+100)+0.2imes(20+100+100)=0.8imes120+0.2imes220=96+44=140 ns.
Explanation
On a hit, we access TLB then memory (120 ns total). On a miss, we also do a page table access (another 100 ns) making 220 ns. The weighted average is 140 ns.
- 25
What information is stored in a page table entry beyond the frame number?
Model answer
Protection bits (e.g., read-only, read-write) and a valid–invalid bit indicating whether the page is in memory.
Explanation
The valid bit tells if the page is loaded; protection bits enforce access permissions. Additional bits for caching, dirty, etc., may also exist.
- 26
What is reentrant code and why does it allow page sharing?
Model answer
Reentrant code does not modify itself and makes no assumptions about its memory location, allowing multiple processes to share the same physical pages.
Explanation
Because reentrant code is stateless and not self-modifying, it can be safely executed by multiple processes concurrently without interference, enabling sharing of pages (e.g., DLLs).

Ask anything
We've read this whole study set, so questions about it get the best answers.