chapter 16 - segmentation Flashcards
basic idea behind segmentation
Divide address space into logical segments (Code, Heap, Stack), each with its own base and bounds
What problem does segmentation solve?
It avoids filling physical memory with unused virtual address space
How does memory access work with segmentation?
Hardware checks segment
Uses base + offset to find physical address
Checks if access is within bounds
How does the hardware determine which segment a virtual address refers to?
By using the top few bits of the virtual address (top 2)
What do the remaining lower bits of a virtual address specify?
The offset within the segment
which direction does the stack grow
downward - negative
How does the hardware support negative growth segments like the stack?
Segment registers store the growth direction and adjust address translation accordingly
Why share code segments between processes?
To save memory while maintaining process isolation
How is memory protection enforced in segmentation?
Using protection bits that define read, write, and execute permissions per segment
What happens if an access violates protection bits?
The CPU traps to the OS, and the offending process is handled
What is coarse-grained segmentation?
Few large segments like Code, Heap, Stack
What is fine-grained segmentation?
Many small segments - often thousands, each representing small pieces of code or data
What must the OS do during a context switch?
Save and restore segment registers (base, size, growth direction, protection)
How does the OS handle heap growth during execution?
- A system call to the OS for more memory
- OS increases the heap segment size if possible
- OS updates the segment size register
What is external fragmentation?
When enough free memory exists overall, but not in a large enough contiguous block to satisfy an allocation request
How can external fragmentation be reduced?
- Compaction: Rearranging memory to create large contiguous free blocks
- Free-list algorithms: Best-fit, Worst-fit, First-fit, Buddy system